Object references are just
named addresses. They are nothing but address of some memory location where the actual object is stored. The actual object usually resides in the program memory ie., heap and is
accessed as needed.
Imagine a two-column table with the different names in the first column ( EmployeeName, whateverId, someObject etc ) and addresses in the second column- just raw hexadecimal numbers ( 0x2322, 0x8977 etc ) for each name in the first column. This is roughly how JVM stores the references. Whenever the program tries to access an object, its name is looked up in the first column, its address fetched from the second column of the appropriate row and then the JVM
'seeks' the addressed referred to by the big-long hexadecimal number. If anything meaningful found there ie., if it finds what it is looking for, then the reference is said to have been
meaningfully resolved. Else you will get a runtime error - for example NullPointerException is thrown if nothing is found in that memory bin.
Remember, declaring object references is really not as
expensive as creating objects[/i]. This is true because object references are nothing but integer/long data types which store an address instead of a primitive value. You can declare any number of references without being worried about the cost or the overhead. However when you create an object, you are
consuming memory. There is only so much memory available to your( which is not infinite by the way
) program and JVM tries hard to make sure you don't run out of the quota. Every time you create an object using <code>new SomeObject()</code> the amount of memory available for your program decreases. The object may occupy only a fraction of the available memory, but irrespective of "how much" space an object eats up, the Garbage collector needs to keep track of its "active references" and strive to reclaim the memory when the object is no longer being used.
Moral of the story is - unlike objects primitives aren't considered entities that eatup valuable memory resources. It doesn't cost anything to declare object references, but when you instantiate objects, you gotta know you have started to eat the pie and it is going to get over soon
Hope that helps, and ofcourse, come back with questions if you don't understand something here. I would recommend you guys reading
JVM Section 2.4 Types and Values and Section 2.5 Variables Ajith