Initiating and defining loaders - JVM

A class loader, when invoked to load a class, might delegate the loading process to another class loader, i.e., there may be a chain of delegation. In such a case the _rst class loader is called an initiating loader. The loader which eventually loads the class and incorporates the class into the environment is called a de_ning loader. Two classes are equal i_ they have the same name, where the loader part of the name refers to the de_ning loader. It is possible that two classes, loaded by di_erent initiating loaders, are de_ned by the same loader. This is the reason why we have to attach the de_ning loader to the class name instead of the initiating loader.

If a class C references other classes, the de_ning loader of class C is used to load the references if they are not already loaded by that loader. For example, if C is de_ned by loader L and the super class of C is Object, then the loader L is used to load class Object. The loader L can load the class directly (becoming the de_ning loader) or it may delegate the loading to another loader. The JVM environment provides a system class loader which loads classes from the local _le system.

Since the system loader does not delegate loading, all references of a class loaded by the system loader are also loaded by the system loader. Therefore, local classes, which are typically built-in classes, cannot reference non-local classes. This avoids the problem of type spoo_ng" local classes.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

JVM Topics