Category | Types | Size (bits) | Minimum Value | Maximum Value | Precision | Example |
---|---|---|---|---|---|---|
Integer | byte |
8 | -128 | 127 | From +127 to -128 | byte b = 65; |
char |
16 | 0 | 216-1 | All Unicode characters | char c = 'A'; |
|
short |
16 | -215 | 215-1 | From +32,767 to -32,768 | short s = 65; |
|
int |
32 | -231 | 231-1 | From +2,147,483,647 to -2,147,483,648 | int i = 65; |
|
long |
64 | -263 | 263-1 | From +9,223,372,036,854,775,807 to -9,223,372,036,854,775,808 | long l = 65L; |
|
Floating-point | float |
32 | 2-149 | (2-2-23)*2127 | From 3.402,823,5 E+38 to 1.4 E-45 | float f = 65f; |
double |
64 | 2-1074 | (2-2-52)*21023 | From 1.797,693,134,862,315,7 E+308 to 4.9 E-324 | double d = 65.55; |
|
Other | boolean |
1 | -- | -- | false, true | boolean b = true; |
void |
-- | -- | -- | -- | -- |
System.out.println(42); // A single literal value is an expression
System.out.println(2 + 2); // So is an operator acting on two literals
23 / 4; // 5
23.0 / 4; // 5.75
23. / 4; // 5.75
23 / 4.0; // 5.75
23 / 4.; // 5.75
23. / 4.; // 5.75
23.0 / 4.0; // 5.75
23 / 4; // 5
(int) 23.0 / 4; // 5
23.0 / 4; // 5.75
<type> <name>; // Declartion without initialization/assignment
<type> <name> = <expression>; // Declaration with assignment
int x, y, z;
x = y = z = 2 * 5 + 4; // What are the values of x, y and z?
w += 1; // same as: w = w + 1;
x -= 2; // same as: x = x - 2;
y *= 3; // same as: y = y * 3;
z /= 4; // same as: z = z / 4;
x++; // Increment x by 1
y--; // Decrement y by 1