Monday, March 19, 2018

What is Classloader in java ?


Classloader is very interesting topic in java , Every thing in  java is made up of classes only , So how to load these classes is one of the important aspect to learn.
When a program executed , JVM need to load all the classes either created by the programmer or the system classes to executed the program these loading of classes is done by classloader.



Also see Difference between JDK , JRE & JVM 

Type of ClassLoaders :

There are three different type of classloader in java , as there are basically 3 type of classes exist in java.

  • System classloader - Load all the classes from classpath.
  • Extension classloader - Load all the classes from extension directory
  • Bootstrap classloader - Load all the java core classes

Order of Execution of Classloader ?

Below is the Order of Classloader in which classloader are executed.
  1. First JRE ask the Classloader to load this particular class , First Executed Classloader is System classloader , which find the class in CLASSPATH if found will load the class , if not go to point 2.
  2. If the class is not found in classpath , then extension classloader will be called , it checks the class in Extension directory if found will load the class if not go to point 3
  3. If class is not found in extension directory , the Bootstrap classloader will be called , it checks the class in java core classes , if not found , then ClassNotFoundException will throw otherwise it return the class instance.
Above is the hierarchy of the Classloader to be executed.

If you like this article please share it with your friends and colleagues.

Thanks for reading
Noeik




0 comments:

Post a Comment