Tuesday 31 May 2016

How does ClassLoader Work?

When JVM requests for a class, it invokes ClassLoader.loadClass() method by passing the fully classified name of the Class.


public Class<?> loadClass(String name) throws ClassNotFoundException;


loadClass() method calls for findLoadedClass() method to check that the class has been already loaded or not. It’s required to avoid loading the class multiple times.


protected final Class<?> findLoadedClass(String name);


If the Class is not already loaded then it will delegate the request to parent ClassLoader to load the class.

If the parent ClassLoader is not finding the Class then it will invoke findClass() method to look for the classes in the file system.


protected Class<?> findClass(String name) throws ClassNotFoundException;

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...