datatype varName; datatype varName = varValue;
int 4 bytes -2*109 to 2*109 short 2 bytes -32,000 to 32,000 long 8 bytes -9*1018 to 9*1018 byte 1 byte -128 to 127
float 4 bytes approx 7 decimal places double 8 bytes approx 15 decimal places
char 2 bytes unicode character set boolean true or false
int i; //this is a declaration int j = 37; //this is initialization i = 42 ; //this is assignment
Implicit casting from left to right,
byte -> short -> int -> long -> float -> double
and
char -> int
Explicit casting example,
double x = 9.997; int nx = (int)x;
x has the value 9.
Use Math.round method for rounding,
double x = 9.997; int nx = (int)Math.round(x);
final int CM_PER_INCH = 2.54;
//This is a single line comment
/*
this is a
multiple line
comment
*/