Java Datatypes


While defining a variable in Java you must specify data type, the data type talks about what kind of data it accepts and how much size it takes to store the data in the memory

In Java, there are two types of data types

  • Primitive data types ( or) value types
  • Reference types

Primitive data types

In the primitive data types, the value will be directly stored into the memory, there are total 8 primitive data types


  • The size of the byte is 1 byte or 8 bits
  • The range is between -128 to 127
  • The default value is 0


  • The size of the short is 2 bytes or 16 bits
  • The range is between -32,768 to 32.767
  • The default value is 0


  • The size of the int is 4 bytes or 32 bits
  • The range is between -2.147.483.648 to 2.147.483.647
  • The default value is 0


  • The size of the long is 8 bytes or 64 bits
  • The range is between -9.223.372.036.854.775.808 to 9.223.372.036.854.775.808
  • The default value is 0


  • The size of the float is 32-bit IEEE 754 floating point
  • The default value is 0.0f


  • The size of the double is 64-bit IEEE 754 floating point
  • The default value is 0.0d


  • The size of the char is 2 bytes
  • The default value is ‘\u0000’


  • The size of the boolean is 1 bit
  • The default value is false

Reference Types

The example of reference types is a class, ArrayList, String etc…

Example: get the primitive data types values

Output :