Java – Datatypes

Prev     Next

Java is a strongly typed language. Hence every element to be declared, must strictly define its type.


int x =10;
char c;

Here, x is a variable of the type ‘int’ which is initialized by a value of 10 and c is a variable of type ‘char’.

There are two kinds of data type in Java. They are,

  1. Primitive data type
  2. Reference type

1. Primitive Data Type:

  • Java defines 8 primitive data types – byte, short, int, long, float, double, char, Boolean.
  • The primitive types byte, short, int, long – represents signed integer values.


  • Description: Smallest integer type. Useful to work with raw binary data. E.g data from a network or file.
  • Size (in Byte): 1
  • Range: -128 to 127
  • Example: byte b=5;


  • Description: 16 bit signed integer type. Least used.
  • Size (in Byte): 2
  • Range: -32,768 to 32,767
  • Example: short num=5;


  • Description: Signed 32 bit type. Commonly used in expressions which requires a larger range; also to control loops, index arrays.
  • Size (in Byte): 4
  • Range: -2,147,483,648 to 2,147,483,647
  • Example: int i=567;


  • Description: Signed 64 bit type and used when ‘int’ is not enough to hold the value.
  • Size (in Byte): 8
  • Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
  • Example: long num=2233720368;


  • Description: Real numbers. Decimal with a single precision.
  • Size (in Byte): 4
  • Range: 1.4e–045 to 3.4e+038
  • Example: float temp=52.5;


  • Description: Decimal with double precision. Math functions like sin(), cos() and sqrt() return double values.
  • Size (in Byte): 8
  • Range: 4.9e–324 to 1.8e+308
  • Example: double sal= 0.50;


  • Description: Data type to store characters. Unicode values are used to store characters.
  • Size (in Byte): 2
  • Range: 0 to 65,536
  • Example: char ch = ‘d’;


  • Description: Data type to store logical value i.e. true or false. This type is returned by all relational operators and required by conditional expressions like ‘if’ and ‘for’.
  • Stores either “true” or “false”
  • Example: boolean flag=true;

2. Reference Type:

  • A reference type is a data type that refers to an object in memory. They can be instantiated.
  • Reference type does not store the actual value, but stores the address. References are of type class, interface and array.


String st = new String(); // st is a reference variable of reference type ‘String’
Bird b1;

Prev     Next

Share this website !!!
Facebook Twitter Linkedin

1. Online Compilers - Compile & Run your C/C++ programs:

✅ Online Compilers

2. Ask your questions or clarify your/others doubts from,

✅ Online Discussion Forums by

We Support JALLIKATTU !!!
Show Your Support as well. Thanks!