Introduction To Java: Object-Oriented Programming
Introduction To Java: Object-Oriented Programming
Object-Oriented Programming
Outline
Readings:
HFJ: Ch.1, Ch.5.
GT: Ch. 2.
Introduction to Java
Java
Why Java?
Object-oriented
Portability
Safe
Data always initialized, references always typesafe
Access to "private" or "package private" data and
methods is rigidly controlled.
Addresses the weaknesses of older programming
languages
Built-in multi-threading
Introduction to Java
Introduction to Java
Java
program
Compiler
Java
bytecode
program
Introduction to Java
Introduction to Java
Introduction to Java
HelloWorld application
same name with the class
HelloWorld.java:
this is a class
class name
a statement
it says print to
standard output
}
}
public, so that
everyone can access
Introduction to Java
10
Compile HelloWorld.java
javac HelloWorld.java
Run
java HelloWorld
compiler
HelloWorld.class
11
Greeting.java:
Introduction to Java
12
Introduction to Java
13
java
Introduction to Java
14
Code structure
Introduction to Java
15
Introduction to Java
16
Looping
Conditional branching
if (x == 2) {
System.out.println("x must be 2");
} else {
System.out.println("x is not 2");
}
Introduction to Java
17
do-while?
switch?
int, long, float, double, boolean?
other syntactical stuff?
Introduction to Java
18