Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

instantiation

 
Nazma Panjwani
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All you need to know is that human keeps something like a 'pointer' (reference) to the object instance which is somewhere on the heap.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic