aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "instantiation" Watch "instantiation" New topic
Author

instantiation

Nazma Panjwani
Greenhorn

Joined: Jan 17, 2010
Posts: 17
Hi,

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???
Thanks
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
Sheriff

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
sscce.org
 
jQuery in Action, 2nd edition
 
subject: instantiation