Jul 10, 2017

Understanding JVM: Class Loader Sub System - Part 1

Now we know from the previous article that JVM is responsible for loading od the Java class file. Internally Class Loader Sub System performs following steps:
  1. Loading
  2. Linking
  3. Initialization
Loading: Loading means reading .class file data and store corresponding data in method area. For each .class file, JVM will store following information:
  • fully qualified name of class
  • fully qualified name of immediate parent
  • whether .class file represents class/interface/enum
  • methods/constructors/variables information
  • modifiers information
  • constant pool information
After .class object is loaded into memory, JVM then creates the "Class" object for the the same. This object can be used to retrieve class level information like how many methods are there in class, using reflection. 

It is important to note that for every class, only one "Class" object will be created by JVM. Consider following example:

1:  public class Exmaple {  
2:       Student s1 = new Student ();  
3:       Class c1 = s1.getClass();  
4:       Student s2 = new Student ();  
5:       Class c2 = s2.getClass();  
6:  }  

In the above example, s1.getClass() and s2.getClass() will give same object as there is only one object of Class class of Student.

Classloader subsystem first loads class file and stores in method area. Then JVM creates object of Class class.

Next section will be on the second activity performed by Class Loader Sub System, i.e., Linking.
Join us at +Java Territory or facebook to stay updated.

0 comments:

Post a Comment