Types of Datatypes in Java

Different types of datatypes in Java are

  • byte
  • short
  • int
  • long
  • float
  • double
  • boolean
  • char

byte

  • byte is a datatype which can be used to store numbers between -128 and 128.
  • It makes compiler allocate memory of 1 byte(8 bits).

short

  • short is a datatype which can be used to store numbers between -32,768 and 32,768.
  • It makes compiler allocate memory of 2 byte(16 bits).

int

  • int is a datatype which can be used to store numbers between -231 and 231.
  • It makes compiler allocate memory of 4 byte(32 bits).

long

  • long is a datatype which can be used to store numbers between -263 and 263.
  • It makes compiler allocate memory of 8 byte(64 bits).

float

  • float is a datatype which can be used to store small decimal numbers.
  • It makes compiler allocate memory of 4 byte(32 bits).

double

  • double is a datatype which can be used to store large decimal numbers.
  • It makes compiler allocate memory of 8 byte(64 bits).

boolean

  • double is a datatype which can be used to store only true and false logics.
  • It makes compiler allocate memory of 1 bit(smallest).

char

  • char is a datatype which can be used to store single character or alphabet which are in UNICODE characters list between 0 to 65535.
  • It makes compiler allocate memory of 2 byte(64 bits).
  • If you need list of unicode characters, learn from here.

1 byte = 8 bits.

boolean is the datatype which uses very less memory out of all.

Remember to use correct suitable datatypes in your program. It is one of the factor for speed and efficiency of a program.


What is a variable or datatype and why they are used detailly ?