What is a reference in Java?

A reference is like a pointer to memory. When an object is created from a class, Java allocates enough memory required to store the object.

When the newly created object is assigned to a variable, the variable gets the value of the reference to the object, but not to the object itself.

Here, the reference assigned to the variable is the memory address where the object is stored.


Student studentVariable = new Student();

In the example above, the address of the Student object gets assigned to the studentVariable.

Free Resources