Each Java variable or expression has a definite type, given by a declaration such as"int i;". There are three "types" of types!
-
There are Primitive or Simple types such as integers or booleans which are built-in.
-
New composite types (objects) can be constructed in terms of classes and interfaces. The type of an object is its class or interface
-
Arrays we will see are a sort of "almost" object!
|
First we discuss the Primitive Types
-
There are 4 integer types: byte, short, int, long of size 8, 16, 32 and 64 bits, respectively.
-
float is 32 bits, double is 64 bits. Floating point arithmetic and data formats are defined by IEEE754 standard.
-
characters are given by 16bit Unicode charset and represented as short integers.
|
One can use casts for conversion such as longint = (long) i; // which can be explicit as here and sometimes implied (see later)
|
Note booleans are either TRUE or FALSE -- they are not 0, 1 ,-1 ...
|