Tuesday, April 12, 2011

What are classloaders ? - All About Classloaders

Some related question to this are

  • What are classloaders ?

  • What is the significance of having multiple class loaders in Java ?

  • When multiple web/enterprise J2EE applications are deployed in a single instance of Application Server what role do these multiple classloaders play ?
Classloaders as the name specifies are used for loading classes in Java. Whenever you call the main() method of the Java class the first classs is loaded by the ClassLoader. Bootstrap(primordial) classloader is the minimal classloader which every Java application would be using. The hierachy between the various classloaders in JAVA/J2EE can be displayed as shown below in the diagram.



Class loaders follow a delegation model i.e. they request their parent to load the class (till the top level is reached) and if that does not happen it itself tries to load the class. Classes which are loaded by a classloader are not visible to it's parents or siblings but only to the child. This is how java manages namespace conflicts if multiple applications (using different version of common libraries like log4j, parsers etc.) are loaded in the same instance of the application server.

No comments:

Post a Comment