Data Types

 Before we talk about data type first we know about variable because data type is used with variable. Without variable the meaning of the data type is nothing, it's incomplete. Data types are used when you create variable in the program. Each variable is assigned a data type.



Variable is the name which is used to reserve space in memory For example if we use

int a;

Then, ‘a’ is the variable of integer type. So,this is clear in the above example that without variable data type is not complete and without data type variable can do nothing. Data types defines the type of data that the variable is integer type, float type ,character type or so on.

Data types are of two types:

         a) Primitive data type   b) Non –primitive data type

Primitive data type---Primitive data type is predefined data type and its name is reserved keyword.

Primitive Data Type:


  1. Integer
  • Byte
  • Short
  • Int
  • Long
  1. Floating Point
  • Float
  • Double


  1. Character
  2. Boolean

When we talk about the data type then first we should know about the size of the datatype(how much bits(0,1) it can store, means its capacity or range).

The primitive data type are:.

1)int->size of integer data type is 32 bit(4 byte)

2)char->size of character data type is 8 bit(1 byte).

3)float-> size of float(.value like 2.3)data type is 32 bit(4 byte).

4)byte-> size of data type is 8 bits(1 byte).

5)short- size of short data type is 16 bit(2 byte).

6)long-> size of long data type is 64 bits(4 byte).

7)double-> size of double data type is 64 bits(4 byte).

8)Boolean->it may return true or false its size is 1 bit

Non Primitive Data type---

Non primitive data type like Array ,Structure etc are not predefined in any computer language like C,C++,Java. It also known as “Reference type”( or object reference).Non primitive data type is created by programmer.

Non Primitive:

  1. Classes
  2. Array

Array declaration syntax:

int a[];   //declaration of an array

………..Program example in an array…………..

class arr


public static void main(String aa[])


int i,le;         //variable declaration ‘I’ for loop and le for count the length

int a[]={1,4,6,7,8,2];   //constant value