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

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