Java Classloaders

If you have any doubts in the below, contact us by dropping a mail to the Kung Fu Panda. We will get back to you very soon.


Class Loading

Normally a class Foo is loaded only when it is needed in a class Bar in the following two ways

	// when a new object is created.
	Foo foo = new Foo();  
	// some static reference is made to the Foo for the first time.

In the above cases, both classes Foo and Bar are loaded by the same classloader.

Types of ClassLoaders

Bootstrap classloader

Extension classloader

System classloader

Classloaders in J2EE application servers

Custom Classloaders

Principles of ClassLoading

NoClassDefFoundError Vs ClassNotFoundException Vs NoSuchMethodError

Steps of Class Loading for a classloader(Simplified)

A classloader should the following steps to load a class.

Methods in java.lang.classLoader

	// loads the class given the name of the class.
	public Class loadClass(String name);
	//creates a object of a Class, if you are given a byte array.
	protected Class defineClass(byte[] bytes);
	// returns the parent classloader
	public ClassLoader getParent();
	public URL getResource(String name);