Data Types

When we write programs, We need a way to store different kinds of data. Data types are a way for us to specify what kind of data and the size we need to store.

Java is a strongly typed language. This means that all operations are type-checked by the compiler for type compatibility. As with all modern programming languages, Java supports several types of data. Broadly, the data types available in Java can be classified into the following types:

  1. Primitive data types
  2. Reference data types

Primitive data types

Primitive types are the fundamental types, that is, they cannot be modified. There are eight primitive data types in Java: byte, short, int, long, char, float, double, and boolean. These can be further grouped in four groups:

  1. Integers: They are whole-valued signed numbers. It includes byte, short, int, and long.
  2. Floating-point numbers: They represent numbers with fractional precision. It includes float and double.
  3. Characters: They represent character sets. It includes char.
  4. Boolean: A special type for representing true/false values. It includes boolean.

Reference data types

Reference types are types that refer to data that’s stored in a certain memory location. They don’t hold the data themselves, but hold the address of the data. Objects are example of reference types.