Variables in Java

In java a variable is nothing but name, which can be used to store the values. A variable is like a container which can hold the different type contents. Internally a variable is represented as a memory location name.

Types of variables in Java

Based on the value holding a variable are divide into two types.

Primitive Variable

Primitive Variables only allow to store single value and hold single value.

Example of primitive variable

	
    //primitve variable..
    int a = 10;
    char ch = 'b';
    float a = 2.5f;
    

Reference Variable

Reference Variable allow to store multiple values in a single variable.

Example of reference variable

	
    //reference variable..
    String str = new String();
    String st = new String();    
    

Based on the position of declaration and based on the position all variables divide in three types.

Instance Variable

Static Variable

Local Variable

Post Your Comment