Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java The Thing About Strings

Shankar ChandraBose
Shankar ChandraBose
912 Points

Difference between Object equality and object reference equality ?

What is the meaning of object equality and object reference equality ?

1 Answer

Patrick Y.
Patrick Y.
3,052 Points

Object Equality (equals) means whether two objects are equal to each other. It does not matter where the object resides in memory, so even if two objects reside in different location in memory, they are consider equal as long as they are the same thing.

Object reference equality (==) has to do with the location of the objects in memory. It checks to see if two objects reference the same memory location, aka whether they are pointing to the same spot in memory.

Its important to understand how two objects can be the same, but they are stored in different memory location.