Java Data Types

Based on the data type of a variable, the operating system allocates memory and decides what type of value will be stored in the reserved memory. You can store integers, decimals, or characters in these variables.

The appropriate data type is to be select by the programmer according to the needs of the application.

In Java, Data types are divided into 2 categories:

  1. Primitive data type: also known as intrinsic or built-in data type.
  2. Derived data type: also known as reference data type or object data type or user-defined data type.
Integer data type

Integer data type can hold whole numbers such as 10, 56, -97. Java supports 4 types of integers: byte, short, int, and long. Java does not support the concept of unsigned data types and therefor all Java values are signed means they can be positive or negative.

Type Size Suffix Range
byte 1 byte y or Y -128 to 127
short 2 bytes s or S -32768 to 32767
int 4 bytes None -231 to 231
long 8 bytes l or L -263 to 263
Floating Point Data type

Integer data type can hold only whole numbers, if you want to store decimal numbers than use floating point data type.

Type Size Suffix Range
float 4 byte f or F -231 to 231-1
double 8 bytes d or D -263 to 263-1
Character data type
Type Size Range
char 2 byte -215 to 215-1
boolean 1 bytes true/false

Reference Data type (User-Defined Data type)

  1. String
  2. Arrays
  3. Class
  4. Interface