[list]
[*]1. Explain Java class loader?
[/list]
Class loader are hierarchical and use a delegation model when loading a class. Here is the “Typical Default Class Loader Hierarchy”.
[img]http://dl.iteye.com/upload/attachment/162331/4f97917a-8cb7-3217-a72c-abb7c4bed9f1.jpg[/img]
[table]
||[b]Class Loader[/b]||[b]Explanation[/b]
||Bootstrap||Load the core java classes(e.g. java.*, javax.*, etc) into JVM
||Extension||Load classes from the JRE’s extension directories.
||System||Load classes from the system class path.
[/table]
Class loaders request their parent to load the class first before attempting to load it themselves. When a class loader loads a class, the child class loaders in the hierarchy will never reload the class again. Hence uniqueness is maintained. Classes loaded by a child class loader have visibility into classes loaded by its parents up the hierarchy but the reverse is not true as explained in the above diagram.
Note: Two objects loaded by different classes 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.
[list]
[*]2.Explain static & dynamic class loading?
[/list]
Static class loading knows the class at compile time.
Dynamic class loading knows the class at run time. That lets us maybe change classes through configuration or lets users introduce new classes that we never know about by passing a new string.
[b]Dynamic class loading methods:[/b]
[*]1. Explain Java class loader?
[/list]
Class loader are hierarchical and use a delegation model when loading a class. Here is the “Typical Default Class Loader Hierarchy”.
[img]http://dl.iteye.com/upload/attachment/162331/4f97917a-8cb7-3217-a72c-abb7c4bed9f1.jpg[/img]
[table]
||[b]Class Loader[/b]||[b]Explanation[/b]
||Bootstrap||Load the core java classes(e.g. java.*, javax.*, etc) into JVM
||Extension||Load classes from the JRE’s extension directories.
||System||Load classes from the system class path.
[/table]
Class loaders request their parent to load the class first before attempting to load it themselves. When a class loader loads a class, the child class loaders in the hierarchy will never reload the class again. Hence uniqueness is maintained. Classes loaded by a child class loader have visibility into classes loaded by its parents up the hierarchy but the reverse is not true as explained in the above diagram.
Note: Two objects loaded by different classes 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.
[list]
[*]2.Explain static & dynamic class loading?
[/list]
Static class loading knows the class at compile time.
Dynamic class loading knows the class at run time. That lets us maybe change classes through configuration or lets users introduce new classes that we never know about by passing a new string.
// static class loading at compile time
Car c = new Car();
// dynamic class loading at run time.
Class vehicleClass = Class.forName(myClassName) ;
[b]Dynamic class loading methods:[/b]
The forName(..) method in class - Class.
The findSystemClass(..) method in class - ClassLoader.
The loadClass(..) method in class - ClassLoader.