It's not a secret anymore!
The moose likes Beginning Java and the fly likes instantiation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "instantiation" Watch "instantiation" New topic


Nazma Panjwani

Joined: Jan 17, 2010
Posts: 17

When you instantiate an object, Mammal human = new Mammal(), the address or reference of the object is stored somewhere in memory which we refer to as human. I don't know how this whole thing works, please someone explain to me in a simple way. So human refers to a block of memory,which contains an address leading to another block of memory which is storing the object???
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
All you need to know is that human keeps something like a 'pointer' (reference) to the object instance which is somewhere on the heap.

JDBCSupport - An easy to use, light-weight JDBC framework -
marc weber

Joined: Aug 31, 2004
Posts: 11343

Basically, The Java Virtual Machine Specification says that a "variable is a storage location," and a "variable of reference type can hold ... a reference to any object whose class is assignment compatible (ยง2.6.7) with the type of the variable." Ultimately, these "reference values ... are pointers to these objects." (See 2.4.6 Reference Types, Objects, and Reference Values and 2.5 Variables.)

I think the level of detail you're asking about might be specific to the implementation of the JVM. I don't think we can know whether a Java reference points directly to the object itself, or whether it points to some sort of "table" that stores an address of the object.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
I agree. Here's the link:
subject: instantiation
jQuery in Action, 3rd edition