Java: Summary - Data
Basic Java: Know int, double, String, boolean, and char.
Primitive types | Reference types / Classes | ||||||||||||||||||||
There are 8 primitive types:
boolean (true and false); char (Unicode characters);
byte , short , int ,
and long (integers); float and double (floating point).
|
The most commonly used pre-defined object type is String.
Primitive types have corresponding "wrapper" class whose objects are immutable (values can not be changed).
Autoboxing. Conversion between the primitive and the wrapper classes is largely automatic as of Java 5. |
||||||||||||||||||||
Integers - primitive types | Integer classes | ||||||||||||||||||||
The integer types byte, short, int, and long are stored
as two's complement, signed binary integers. char, which is technically also
an integer type, is stored as an unsigned binary number.
Expressions are computed as ints, so a cast is needed to store in a smaller type.
|
|
||||||||||||||||||||
Floating-point primitive types | Floating-point classes | ||||||||||||||||||||
The floating-point types, float and double, are stored
in IEEE-754 format. Calculations may produce NaN (Not a Number) or +/- infinity.
Calculations are done as doubles, so a cast is needed to store in a float.
|
|
||||||||||||||||||||
char primitive type | Character, String, ... classes | ||||||||||||||||||||
char type is a Unicode character stored as an unsigned number in two bytes
(range 0..65,535 or '\u0000'..'\uFFFF').
char is an integer type.
char literals
|
|
||||||||||||||||||||
boolean primitive type | Boolean class | ||||||||||||||||||||
boolean has values true or false.
Operators: logical, ==, !=, assignment. |
Boolean: wrapper class with little utility. |
2007 Fred Swartz