Class loaders are hierarchical.
Classes are introduced into the JVM as they are referenced by name in a class that is already running in the JVM.
The very first class is specially loaded with the help of static main() method declared in your class.
All the subsequently loaded classes are loaded by the classes, which are already loaded and running.
A class loader creates a namespace.
All JVMs include at least one class loader that is embedded within the JVM called the primordial (or bootstrap) class loader.
The JVM has hooks in it to allow user defined class loaders to be used in place of primordial class loader.
Class loaders created by the JVM
1. Bootstrap (primordial)
Loads JDK internal classes, java.* packages. (as defined in the sun.boot.class.path system property, typically loads rt.jar and i18n.jar)
2. Extensions
Loads jar files from JDK extensions directory (as defined in the java.ext.dirs system property – usually lib/ext directory of the JRE)
3. System
Loads classes from system classpath (as defined by the java.class.path property, which is set by the CLASSPATH environment variable or –classpath or –cp command line options)
Important : Two objects loaded by different class loaders are never equal even if they carry the same values, which mean a class is uniquely identified in the context of the associated class loader. This applies to singletons too, where each class loader will have its own singleton.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.