Monday, July 29, 2013

Class Loaders

-Class loaders are java classes which is used to load class files in java from either a file system, network or any other source.
- There are three default class loaders used by java - bootstrap, extension and system class loaders of the Application Class loader.
- Every JVM has primordial or bootstrap class loaders which loads the java.* packages and rt.jar/i18n jar.
- There are non-primordial class loaders such as Extensions which loads the java extension packages.
- Then there is system class loaders, that loads all the class defined in the class path.
- Class loaders are hierarchical and follow a delegation model.
- The parent class has no visibility to child class, however, the child class has visibility to all the parent classes.
- Two sibling classes does not have visibility of each other, but they can see the parent class loaders.
- A class is never reloaded and during initialization the child request the parent to load the classes first and hence the uniqueness of class in maintained.

- class.getClassLoader.getParent() gets the parent class loader
- A class can be loaded by class.forName(class name) or class.forName(class name, initialized, class loader), based on which the classLoader calls the class.loadClass() method which in-turn calls the class.findClass() to locate the bytecodes of the actual class to load.

- It is recommended that any class which overrides Class Loader overrides this findClass instead of loadClass, since loadClass internally calls findClass for class loading.


No comments:

Post a Comment