Professional Documents
Culture Documents
02 Java Syntax and Class Review
02 Java Syntax and Class Review
2-2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java Language Review
2-3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Class Structure
package <package_name>;
import <other_packages>;
<constructor method(s)>;
<other methods>;
}
2-4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
A Simple Class
}
}
2-5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Code Blocks
2-6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Primitive Data Types
2-7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java SE 7 Numeric Literals
2-9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Java SE 7 Binary Literals
9 return empId;
10 }
11 // getter/setter methods for other fields...
12 }
pa c k age!
s decl a re a
Alwa y
3 3
x y
copy the value of x
• If x is later modified (for example, x = 5;), the value of y
remains unchanged.
42 memory address = 42
x Employee
y = x; object
42
y
• After the assignment, the value of y is the same as the
value of x: a reference to the same Employee object.
2 - 29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Objects Passed as Parameters
e 99 Employee
object
• To run the application, you use the interpreter and the fully
qualified class name:
java –cp D:\test com.example.HelloWorld
Hello World!
Test.class.getClassLoader().loadClass("Employee");
a. Fred
b. Bob
c. null
d. an empty String