Java Data Types

Primitive Data Types

Primitive data types are the most basic data types available within the Java language. They serve as the building blocks of data manipulation in Java. There are 8 primitive data types.

Data TypeDescriptionDefault ValueSize
byteSigned integer01 byte
shortSigned integer02 bytes
intSigned integer04 bytes
longSigned integer0L8 bytes
floatSingle-precision floating point0.0f4 bytes
doubleDouble-precision floating point0.0d8 bytes
booleanRepresents true or false valuesfalse1 bit
charA single Unicode character'\u0000'2 bytes

Reference (Non-Primitive) Data Types

Reference data types are created by programmers and are not defined by Java (except for String). They refer to objects. The main difference between primitive and reference data types is that primitive types store the actual values, whereas reference types store the address where the value is being stored.

Strings

In Java, a string is an object that represents a sequence of characters.

Arrays

An array is a container object that holds a fixed number of values of a single type.

Classes

A class is a blueprint from which individual objects are created.

Interfaces

An interface is a reference type in Java. It is a collection of abstract methods.