Java Data Types

Last Updated: March 17, 2022

When you declare a variable in Java you have to mention the data types

Java programming language has eight primitive data types.

In Java, there are two types of data types

  • Primitive Data types – byte, short, int, long, float, double, boolean and char
  • Non-primitive data types – String, Array, Classes
Type Size(bits) Details
byte 8

Stores whole numbers from -128 to 127

byte b = 100;
short 16

Stores whole numbers from -32,768 to 32,767

short s = 20000;
int 32

Stores whole numbers from -2,147,483,648 to 2,147,483,647

int num = 1 000 000 000
long 64

Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

long x= 3466366466
float 32

Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits

float x= 67.67;
double 64

Stores fractional numbers. Sufficient for storing 15 decimal digits

double num = 2.34 double x= 1.233456
char 16

tores a single character/letter or ASCII values

char a = ‘a';
boolean 1

Stores true or false values

boolean isFound = true;
Test