Hi
we want to know about the class loader. And Explain the types of class loader, i.e. Bootstrap Class loader, Extension Class loader and System Class loader ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Apr 24, 2012, 12:29 AM
Classloaders are the Java program(s) i.e., Java classes that are responsible for loading classes into the underlying JVM. Any class before being used, should first be available and accessible to the classloader, which will load the class into the memory and then only the JVM can perform any task on it. Having said that we see that all the classes in Java are first loaded into the memory by a classloader (normally the default classloader) and then only the class can be used in any possible way. Right? We just said that classloaders are also Java classes only. Now, who loads this classloader classes then? Good pick, if you really picked it :-) The answer to this question is - the bootstrap classloader. Ohh... again a classloader. Yeah, it is, but different from what we discussed above. It's a native classloader and not written in Java. This bootstrap classloader is platform dependent (of course, that's why we called it native) and it's normally written in C.
How the Class-loading mechanism work in Java?
Whenever you try to execute a Java program by invoking the 'java' command then a native Java launcher program is first invoked. This launcher program is 'native' and hence platform dependent. Well... quite obvious, isn't it? Now, on a successful invokation of this launcher program, it calls the bootstrap classloader program. This bootstrap loader program then loads the Core Java classes (classes belonging to the packages starting with 'java.') and then loads two other classloaders - extension classloader and application classloader. That's it. The job of the bootstrap classloader is done once it completes these three tasks - One, loading Core Java classes; Two, loading extension classloader; Three, loading application classloader.
The bootstrap classloader transfer the control to the extension classloader, which then loads the extension classes into the memory. What are extension classes in Java? They are classes belonging to all the packages starting with 'javax.' OR the classes present in the 'ext' directory of the underlying JRE. You may like to go through the post Extension Mechanism in Java for more details.
Finally the control is transferred to the application classloader, which loads the classes of the current application.
One interesting point to note here is that all the three classloaders follow the delegation model i.e., if the application classloader requires to load a class, it'll first delegate a request for the same class to the extension classloader, which will in turn send a request to the bootstrap classloader for the same class. Now, the bootstrap classloader will check if that class is a Core Java class or not. If yes, then it'll make that available to the extension classloader in response to its request and finally the extension classloader will make that available to application classloader. If the bootstrap classloader discovers that the requested class if not a Core Java class, it notifies the same to the extension classloader. Now the extension classloader checks if this class is an extension class or not. If it discoveres that it's an extension class, it makes that available to the application classloader otherwise it notifies the application classloader that the requested class is not even an extension class. The application classloader itself loads a class in this case (when it has got notifications that the requested class is neither a Core Java class nor an extension class).
Please refer the below links
http://geekexplains.blogspot.in/2008/06/classloaders-in-java-how-do-they-work.html
http://www.devx.com/java/Article/31614/1954
http://www.techrepublic.com/article/get-the-most-out-of-javas-class-loaders/6080883
Thanks
MuthuMari MPosted Apr 23, 2012, 11:51 PM
Java ClassLoader loads a java class file into java virtual machine.
In a Java Virtual Machine (JVM), each and every class is loaded by some instance of a java.lang.ClassLoader. The ClassLoader class is located in the java.lang package and you can extend it to add your own functionality to class loading.
When a new JVM is started by java HelloWorld, the bootstrap class loader is responsible for loading key java classes like java.lang.Object and other runtime code into memory. The runtime classes are packaged inside jre/lib/rt.jar file. We cannot find the details of the bootstrap class loader in the java language specification, since this is a native implementation. For this reason the behavior of the bootstrap class loader will differ across JVMs.
There are three Class loaders in first group:
Second group includes:
Third group is context class loader. A thread's context class loader is, by default, set to the context class loader of the thread's parent. The hierarchy of threads is rooted at the primordial thread (the one that runs the program). The context class loader of the primordial thread is set to the class loaderthat loaded the application. So unless you explicitly change the thread's context class loader, its context class loader will be the application's class loader. That is, the context class loader can load the classes that the application can load.
To change a thread's context class loader, use Thread.setContextClassLoader().
pls refer this url for more info :
http://javapapers.com/core-java/java-class-loader/#&slider1=1
thanks.
If this post is useful then mark it as "Accepted Answer"
Jignesh TrivediPosted Apr 23, 2012, 11:41 PM
In .NET assemblies are the fundamental unit of deployment. The technology that actually loads the assemblies is called Fusion.
Actually Cllass loader concept is from java.
please Refer
http://msdn.microsoft.com/en-us/library/x94f0ab5%28v=vs.71%29.aspx
I think, class loader is not much popular and effective as java.
hope this help.
SenthilkumarPosted Apr 23, 2012, 9:41 PM
For more info:
http://www.javalobby.org/java/forums/t18345.html
http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html