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.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources