Convert / cast between primitive data types

Certain things need to be considered when doing certain conversions. All of the primitive types can be converted to another type except for the boolean type.
There are two different types of conversions. A widening conversion occurs when converting from a smaller type to a larger, for example converting from and integer, which is stored as a 32-bit value, to a long which is stored as a 64-bit value.
The other type is the narrowing conversion, which is the opposite. Narrowing conversion isn’t allowed by default in Java, so you need to explicitly tell the compiler that it is ok to do this kind of conversion.

Continue reading

Floating point data types

The 32-bit data type float and the 64-bit data type double represent the real types in Java.
They can be expressed as a number with decimals or with exponential notation in which a number is followed by the letter E or e and another number.
The second number is the power of then with which the first number is multiplied.

Continue reading

Primitive data types

Java has two different data types: Primitive Types and Reference Types.
Primitive types are passed to and from methods ‘by value’ which means that each time a primitive type is passed as argument, a new value is created on the stack.
Reference types are instances of classes (objects) and are handled in another section.

Java has eight primitive types:

Continue reading