MyApplet.java

Werbung
Munz – IT/TG - Lörrach
Goals of this “intensive”
lecture
• To learn:
– What does it means programming in Java ?
– What is JAVA good/bad for ?
– Which programming resources offers JAVA to
support “modern” programming ?
– What is “Object Oriented Programming” ?
• You should be able to design, write, debug
•
and run Java programs of “certain”
complexity
Learning by example
What means “by Example”
• A lot of example programs
• Little explanation about the details of the
•
•
•
•
syntax
There will be some slides about the Java
syntax after we see the examples (shortly)
You will be confronted with the “practical”
problems about programming
The reason of many programming “recipes”
will became clear as we learn more
Deductive learning/teaching style
Why is JAVA so Popular ?
• Multi-platform
• Object oriented: the modern
•
•
•
programming paradigm
Robust: avoids programming features
which can frequently cause errors,
permits recovering from errors.
Aware of the Network: easy for
developing distributed systems in a
TCP/IP network
It is free and has very good
documentation
Some historical facts
• Java was conceived in 1990 as a microchip
•
programming language for domestic appliances
Java means “coffee” in the USA (programmers
drink lot of coffee)
• As such it has had not much acceptance (yet)
• It was seen that the same characteristics are
•
good for a multi-platform language
The Applets made Java famous
What do I need to develop
Java programs
• There are many commercial and free developing
environments
• We will use the most simple and sure, but may
•
be not the most efficient way to develop big
applications
We need:
– A text editor
– The compiler
– The JVM
The JDK or SDK
How do I write and run a Java
Stand-alone Program ?
MyProg.class
MyProg.java
class {
int i,j;
public main
Java source code
Java
Java compiler
(javac)
Java VM
(java)
How do I write and run
a Java-Applet ?
MyApplet.class
MyApplet.java
class {
int i,j;
public main
Java VM
(inside the browser)
Java source code
Java compiler
(javac)
What makes Java Multiplatform
P1.java
P1.class
Program’s
output
Java compiler (specific for each platform)
javac P1.java
Java interpreter (specific for each platform) also
called Java Virtual Machine
java P1
How do I get the JDK ?
(outside the school)
• You can download the JDK from
There are different versions of JAVA
http://java.sun.com/
1.Java 1.0.x Original version, largely been replaced.
2.Java 1.1.x Major upgrade from 1.0. (double) Many things in the earlier were
deprecated in this version. They still exist and can be used, but there are new
(and often better) ways of doing the same things.
3.Java 1.2.x. Known as Java 2. Doubled the size and capabilities of the previous
version. This version can be downloaded as an SDK (Software Development
Kit). An SDK is the same thing as a JDK, only the name was changed.
4.Java 1.3.x This version is also known as Java 2, Version 1.3. It is also known
as J2SE which stands for Java 2 Standard Edition.
5.Java 1.4.x This has been released as a beta version
Java compared to C
JAVA
C
speed
- interpreted
+ directly executed
versatility
- code must fit for every + access to low level
computer
programming res.
standardiza + Java is the same
tion
everywhere
- each C compiler has
some differences
Multiplatform
- similar source code but
different object code
+ the same source and
java code
Robustness + no “tricky” prog.
- Allows hackering
Network
+ part of the language
- different libraries
Other libs
+ a lot and standard
+- a lot but not standard
Lecture Content
• Einfaches programieren in Java (mit Hilfe der Class
•
•
•
•
•
•
•
•
Console für I/O)
Variabeln, aritmehmetische Ausdrücke, Datentypen,
casts, Bedingungen, Schleifen, Verzweigungen
String-Operationen, Text-orientiertes I/O auf Dateien
Weitere Klassen, package Konzept
Statische Methoden
Class-orientiertes programieren
Klassendefinitionen und Zugriffsrechte
Vererbung, Interfaces und Polymorphie
Graphics und Graphische Schnittstellen
Mein Erstes Programm in
Java
public class Programm1 {
public static void main(String args[]) {
Console c = new Console();
c.print("Hallo, tipp ein Nummer ein ?");
int deinnummer = c.readInt();
int meinnummer = deinnummer+1;
c.println(" Mein Nummer lautet " + meinnumer);
c.println("Also ich gewinne Diesmal")
}
}
Blau: standart
Variabeln
Rot: Datentypen Grün:
Mein Zweites Programm
public class Programm2 {
public static void main(String args[]) {
Console c = new Console();
c.print("Hallo, wie heist du ?");
String name = c.readString();
c.print("Wann bist Du geboren ? (Jahr) ");
int jahr = c.readInt();
c.println(name+", also du bist ungefähr "+
(2001-jahr)+" alt ");
}
}
Blau: standart
Variabeln
Rot: Datentypen Grün:
Herunterladen