Professional Documents
Culture Documents
AVA
1. Package declaration
(package)
1. import statements
2. Class definitions
Test.java
// Package declaration
package exam.prepguide
// Imports
import java.awt.Button // a class
import java.util.* // a package
// Class Definition
public class Test { ... }
Keywords and Identifiers
Identifier :
word used by a programmer to name a
variable, method, class, or label
Floating-point types:
float and double
IEEE 754 especification
Float.Nan
Float.NEGATIVE_INFINITY
Nan: Not a number Float.POSITIVE_INFINITY
Double.Nan
Double.NEGATIVE_INFINITY
t
Double.POSITIVE_INFINITY
1. double d=-10.0/0.0;
2. if (d==Double.NEGATIVE_INFINITY) {
3. t[0]
System.out.println(“d t[1]
just t[2] t[3] t[4]
exploded”+d);
4. }
Literals
A value that may be assigned to a
primitive or string variable or passed
as an argument to a method call
boolean:
char:
boolean isBig=true;
char c=´w´;
boolean isLittle=true; char c= ´\u4567´;
Unicode hexadecimal
t[0] t[1] t[2] t[3] t[4]
SPECIAL CHARACTERS
String:
String s =“Characters in strings are 16 bits”;
Arrays ...
An ordered collection of primitives,
object references, or other arrays
1. int size=1152*900;
2. int raster[];
3. rater=new int[size];
Declaration and construction in a single line
Element Initial
Type Value
boolean false
char ‘\u0000’
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
object reference null
Initialization
1. long squares[];
2. squares =new long[6000];
3. for (int i=0; i<6000; i++)
4. squares[i]=i*i;
Class Fundamentals
main() method
Entry point for JAVA applications
Application: class that includes main()
Execution: java at the command line,
followed by the name of the class
1. Class HasVariables {
2. int x=20;
3. static int y =30;
public int wrong() {
int i;
return i+5;
}
double radians=1.2345;
System.out.println(“Sine of”+radians
+”=“+Math.sin(radians));
int xx=12345;
bumper(xx);
System.out.println(“Now xx is”+xx);
Object Reference
Button btn;
Btn=new Button(“Ok”);
Button btn;
btn = new Button(“Good”);
replacer(btn);
System.out.println(btn.getLabel());