Hi
we want to know about class loaders?
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.
Jignesh TrivediPosted May 15, 2012, 11:52 PM
Class loaders offer a very powerful mechanism by which classes can be loaded at runtime. Its power lies in its extensibility, i.e. custom classes needed for the application can be loaded in addition to the basic classes loaded by bootstrap loader. But with such powerful tool comes some security problems as well. Its important for application developers to understand the functioning of classloaders to make their application efficient and and it will also make debugging easy.hope this help.
please refer...
http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html
javapapers.com/core-java/java-class-loader/
hope this help.
Satyapriya NayakPosted May 15, 2012, 10:19 PM
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 link
http://geekexplains.blogspot.in/2008/06/classloaders-in-java-how-do-they-work.html
http://www.ibm.com/developerworks/java/tutorials/j-classloader/
http://www.techrepublic.com/article/get-the-most-out-of-javas-class-loaders/6080883
http://www.javaworld.com/javaworld/jw-10-1996/jw-10-indepth.html
Thanks