Showing posts with label Class Loader. Show all posts
Showing posts with label Class Loader. Show all posts

Friday, 14 September 2012

Java Training: -What do you mean by Bootstrap, Extension and System Class loader?

There three types of class loaders:-
  • Bootstrap Class loader also called as primordial class loader.
  • Extension Class loader.
  • System Class loader.
Let’s now try to get the fundamentals of these class loaders.

Bootstrap Class loader

Bootstrap class loader loads those classes those which are essential for JVM to function properly. Bootstrap class loader is responsible for loading all core java classes for instance java.lang.*, java.io.* etc. Bootstrap class loader finds these necessary classes from “jdk/jre/lib/rt.jar”. Bootstrap class loader cannot be instantiated from JAVA code and is implemented natively inside JVM.

Extension Class loader

The extension class loader also termed as the standard extensions class loader is a child of the bootstrap class loader. Its primary responsibility is to load classes from the extension directories, normally located the “jre/lib/ext” directory. This provides the ability to simply drop in new extensions, such as various security extensions, without requiring modification to the user's class path.

System Class loader

The system class loader also termed application class loader is the class loader responsible for loading code from the path specified by the CLASSPATH environment variable. It is also used to load an application’s entry point class that is the "static void main ()" method in a class.

See the following video on overview and working of Servlets in Java: -



Click to get Java Training

Regards,

Get more Java Training from author’s blog

Saturday, 24 March 2012

Java interview questions: - Elaborate the flow between bootstrap, extension and system class loader?

To understand this answer we will use below simple class lets get in to details of how the class will be loaded.

Import Koirala.Interview.Java;
public class mySimpleClass
{
public static void main(String[] args)
{
String myStr = "I am going to get a job";
System.out.println(myStr);
}}
Figure: - Flow between class loaders

The above class uses “String” class that means it has reference to “java.lang.String”.JVM will request the system class loader to load “java.lang.String”. But before he tries to load it will delegate to extension class loader. Extension class loader will pass it to Boot strap class loader. Now Boot Strap class loader does not have any parent so it will try to load “java.lang.String” using “rt.jar”. Now the Boot strap will return the class back using the same chain to the application.

Now lets see how “Import Koirala.Interview.Java;” is loaded using the class loaders. For the import statement JVM will make a call to the system class loader who will delegate the same to the extension class loader which will delegate the same to the boot strap class loader. Boot strap loader will not find “Koirala.Interview.Java” and return nothing to the extension class loader. Extension class loader will also check the same in its path and will not find anything thus returning nothing to the system class loader. System class loader will use its class path and load the class and return the same to the JVM who will then return it to the application.

See the following video on Java/J2EE Interview question which describes String Literal Pool: -



Click for more Java interview questions

Regards,

Visit for more author’s blog on Java interview questions