1000 Java Tips ebook
Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!.
I see that in Java a lot of Class loaders: bootstrap, extension, system, context
JavaFAQ Home » General Java
Question: I see that in Java a lot of
Class loaders: bootstrap, extension, system, context
and even user defined! It is difficult to understand
Class loader hierarchy in Java.
Answer: It was much better in Java 1.1
There were no relations between system class loader (responsible
for loading in the Java runtime, the application, and classes and
resources in the application's CLASSPATH) and applet class loader
(loaded classes over networks).
Since Java 1.2 we have three types of class loaders:
- Class loaders created automatically by the JVM
- Program defined class loaders
- Context class loaders.
There are three Class loaders in first group:
- bootstrap class loader - loads classes from ../jre/lib/rt.jar
It is the "root" in the class loader hierarchy.
- extensions class loader - loads classes from ../jre/lib/ext/*.jar
- system class loader - it is responsible for loading in the application, as
well as for loading classes and resources in the
Second group includes:
- system class loader - parent class loader by default
- additional parent class loader can be specified explicitly
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 loader
that 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().
Printer Friendly Page
Send to a Friend
Search here again if you need more info!