How objects are created in Java internally?


Ans:
When the Java Virtual Machine (JVM) initially starts the process of running a java program, it allocates a portion of memory to be used as Heap (you can actually specify the Heap size on the command line when you run the program). While the JVM is running the program, whenever a new object is created, the JVM reserves as portion of the Heap for that object (where the object will be stored). The amount of Heap that gets reserved is based on the size of the object. The JVM maps out this segment in the Heap to represent all of the attributes of the object being stored. A reference (address in Heap) to the object is kept by the JVM and stored in a table that allows the JVM to keep track of all the objects that have been allocated on the Heap. The JVM uses these references to access the objects later (when the program accesses the object). 

People who read this post also read :



1 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More