< Java Tutorial

Java datatypes

← Previous Next →

Data type define size a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables.

There are two data types available in Java −

1. Primitive Data Types
2. Reference/Object Data Types

Primitive Data Types

There are eight primitive datatypes supported by Java. Primitive datatypes are predefined by the language and named by a keyword. Let us now look into the eight primitive data types in detail.

Data Type Default Value Default size
boolean false 1 bit
char '\u0000' 2 byte
byte 0 1 1 byte
short 0 2 byte
int 0 4 byte
long 0L 8 byte
float 0.0f 4 byte
double 0.0d 8 byte

Reference/Object Data Types

A reference variable is used to refer any object of a class.


Animal animal = new Animal("giraffe");
← Previous Next →