Professional Documents
Culture Documents
Oracle 02
Oracle 02
2-3 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java Class Structure
package <package_name>;
import <other_packages>;
<constructor(s)>;
<other methods>;
}
2-4 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
A Simple Class
}
}
2-5 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Java Naming Conventions
2-6 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
How to Compile and Run
2-7 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
How to Compile and Run: Example
$ java HelloWorld
Hello World
2-8 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Code Blocks
2-9 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Primitive Data Types
Integer Floating Character True
Point False
byte float char boolean
short double
int
long
1, 2, 3, 42 3.0 'a' true
7L 22.0F '\u0061' false
0xff .3337F '\n'
0b or 0B 4.022E23
package com.example.review;
package com.example;
int x = 30;
do {
System.out.print("value of x : " + x);
x++;
System.out.print("\n");
expression returning
} while (x < 20); boolean value
}
}
// Get length
System.out.println("Length: " + sb.length());
// Get SubString
System.out.println("Sub: " + sb.substring(0, 5));
}
}
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.
a. Same
b. Equals
c. Same Equals
d. Compiler Error