Java supports both primitive and non-primitive variables.Primitive variables are byte,short,int,long,float,double,boolean,char.
primitive variables are declared as:

Datatype variable;
example:     int a;

but how non-primitive variables declare? it means how objects are declared ?there is 3 steps of object creation and assigning
Mobile mob= new Mobile();
1st step:  Mobile mob;
its declaring a reference variable,it tells JVM (Java Virtual Machine) to allocate space for reference variable and names that variable mob.
2nd step:             new Mobile();
it is creating object,it tells the JVM to allocate a space for a new Mobile object on the heap.
3rd step:             Mobile mob = new Mobile();
it is linking the object and the reference.

Primitive variable represents the actual value of the variable, whereas object reference variable represents  a way to get to the object.

Objects and arrays in java actually will hold a reference only, in java all the raw data types passed to a method are call by value and all the object/array data types passed to a method are call by reference.

Advertisements