Java Data Types
Variables in Java must be objects, arrays, or one of the primitive data types
Java has 8 primitive data types
(boolean, byte, short, int, long, double, float, char)
Notes:
-
All integer types are signed (and there is no unsigned keyword)
-
Unlike C and C++ char variables are 16 rather than 8 bits
Because Java is Unicode compliant
-
Unlike C, Java types have a definitely fixed size
in C, it used to depend on the compiler
-
Primitive data types are passed to method by value
the actual value of a primitive type can only
be modified by the methods of the declaring or derived object
boolean likeeScience = true;
/* boolean likewise have values {true, false}
they can never be mixed up with integer or other type
*/
byte teeth = 32; // bytes go from -128 to 127
if (!likeeScience) teeth = teeth - 1;
float pi = 3.141592f; // you need the "f" here
short classes = 0xbad; // hexadecimal