Sunday, December 6, 2009

Standard Java class loading hierarchy



I think before we write complex Java programs we should have a basic understanding about how JVM works and class loading is one of the important thing which JVM does during running of Java programs. In typical Java programs we are using hierarchical class loading concept. In berief class loading is basically contains two operations which are locating the class in the file system and convert physical bytes in to Class object. We can overwrite the first operation by extending java.lang.ClassLoader but we cannot change the way conversion of physical bytes in to Class object.

When we run a normal Java application we have to give the classpath value for our Java command and it's the place where we have our Jar files. So that is the place where we start our class loading. JVM reads paths according to the given order and it's directly goes to the first place which is called Application Class Loader. Since the Java class loading is heirarchical, before loading the class by itself it delegate the work to the upper layer called Extension class Loader and before doing any work Extension class loader delegate the work to Bootstrap class Loader. This concept is called parent first class loading.
So when we try to load our own Jar, Bootstrap and Extension is failing to load the class because Bootstrap is aware of classes in JRE library or extension of JRE class and Extension class loader is aware of libraries in extension directory and finally class loading happens in Application class loader.









No comments :