Java Review ●
DASTRAP Term 2, SY 2009 2010
Variables • Primitive Data types ▫ ▫ ▫ ▫ ▫ ▫ ▫ ▫
byte -128 -> 127 short -32,768 -> -32,767 int -2,147,483,648 -> 2,147,483,647 long -9,223,372,036,854,775,808 -> 9,223,372,036,854,775,807 float single-precision 32-bit IEEE 754 floating point double double-precision 64-bit IEEE 754 floating point boolean true or false char ex. ‘a’
Variables • String – not a primitive data type! But java has special support • String literals are enclosed in “ ” • Can be concatenated
Comments • Single line // • Multiple line /* */ • Javadoc /** */
Unary ! ++ --
Mathematical Operations * / % + -
Relational > < >= <=
Equality == !=
Logical AND, OR && ||
Assignment = += -= *= /= %=
++ equal to +=1 x = 1; x+=3; //x=4 -- equal to -=1 x = 3; x-=1; //x=2 x = 2; x*=4; //x=8 x = 9; x/=3; //x=3 x = 9; x%=2; //1
Loops ● ● ●
for while do-while
Loops for( int i=0; i<5 ; i++) { print(“.”); } Result: .....
Loops int i=0; while(i<5) { print(“.”); i++; } Result: .....
Loops int i=0; do{ print(“.”); i++; } while(i<5); Result: .....