Friday, 21 June 2013

Java Class Loader


  • Java class loader is part of Java Runtime Environment(JRE) that dynamically loads java class into Java Virtual Memory(JVM).
  • JRE doesn't need to know about files and file system, because classloader take care of this.
  • Java platform uses Delegation model for loading class.
  • The classloader is responsible for locating libraries, reading their content and loading the classes contained within the libraries.
  • Each Java Class must be loaded by class loader.
  • When JVM started three class loaders are used.
    • Bootstrap Class Loader.
    • Extension Class Loader.
    • System Class Loader.

Bootstrap Class Loader

  • The bootstrap classloader loads the runtime classes from rt.jar files and others.
  • Runtime classes can be located in the <JAVA_HOME>/jre/lib folder.
  • It is virtual machine built in class loader.
  • It doesn't have parent class loader, but it may server as parent of class loader.

Extension Class Loader.

  • The extension class loader loads the libraries in the extension folder.
  • Extension folder located in <JAVA_HOME>/lib/ext or any other directory specified in the java.ext.dirs System  Property.
  • It is implemented by the sun.misc.Launcher$ExtClassLoader

System Class Loader 

  • Loads the class include the JAR files specified by the system property java.class.path.
  • If a JAR file on the class path has a manifest with attribute Class-Path, JAR files specified by the Class-Path attribute will be also searched.
  • By default java.class.path property's values is .(dot) the current directory.

  • It can be changed using command line option -classpath or -cp or setting CLASSPATH environment variable .
  • The command line option overrides setting of the CLASSPATH environment variable.

No comments:

Post a Comment