Data Types

In Java, data types specify the size and type of values that can be stored in variables. Java has two categories of data types: Primitive data types and Reference data types.

Primitive Data Type

Primitive data types are predefined by the language and are named by a reserved keyword. They represent single values and are not objects.

Different Types

Limits or Range

Size of data types is constant in java. The JVM (Java Virtual Machine) is designed to be platform independent. If data type sizes were different across platforms, then cross-platform consistency is sacrificed. The JVM isolates the program from the underlying OS and platform.

Reference Data Types:

Reference data types are objects that hold references to the memory location where the data is stored. They include classes, interfaces, arrays, and enumerations.

Primitive Wrapper Classes:

These are reference data types that wrap primitive data types into objects. For example:

  • Byte

  • Short

  • Integer

  • Long

  • Float

  • Double

  • Character

  • Boolean

These wrapper classes are useful when working with collections or when you need to treat primitive types as objects.

Last updated