InterviewSolution
Saved Bookmarks
| 1. |
Role of ClassLoader in Java |
|
Answer» The Java Class is stored in the form of byte code in a .class file after it is compiled. The ClassLoader loads the Class of the Java program into memory when it is required. The ClassLoader is hierarchical and so if there is a request to load a class, it is DELEGATED to the parent class loader. The uniqueness in the Java Runtime ENVIRONMENT is maintained using this method. The types of build-in ClassLoader in Java are given as follows:
A program that demonstrates ClassLoader in Java is given as follows: public class Demo { public static void MAIN(STRING[] ARGS) { System.out.println("class loader for this class: " + Demo.class.getClassLoader()); System.out.println("class loader for DNSNameService: " + sun.net.spi.nameservice.dns.DNSNameService.class.getClassLoader()); System.out.println("class loader for HashMap: " + java.util.HashMap.class.getClassLoader()); } }The output of the above program is as follows: class loader for this class: sun.misc.Launcher$AppClassLoader@4e0e2f2a class loader for DNSNameService: sun.misc.Launcher$ExtClassLoader@5c647e05 class loader for HashMap: null |
|