Understanding Class Loaders in Java
While developing any java application one of the most common phenomena encountered is of class loading. To understand this consider the case of C and C++ where class files are loaded into memory all at once but the case is different in java where classes are loaded into JVM on demand or we can say dynamically. This is the case when class loaders come into existence.
Class loaders are part of java virtual machine and their responsibility is to find and load class files into JVM. The feature of class loaders is so powerful that we can customize the JVM itself by defining our own class loaders which leads to the redefining of process of bringing class files into the system.
As we know that source code of java file is directly not converted into executable file, but into a platform independent format called bytecode. A java program is a collection of many individual class files. Each class file refers to a single class and also named same as that class.
As mentioned above for the execution of java program class files must be loaded in the memory. This is not done all at once but on demand as needed by the program and class loaders are that part of JVM that loads classes into memory dynamically.
A class file is a binary representation of a java class which contains byte code and links to other class files. It is the smallest unit loaded by the class loader. Class loader understands the bytecode and creates an instance of java.lang.Class. JVM is unaware of which classes to be loaded. Initially only the class file is loaded and other files are loaded as and when required by JVM. There are three steps included in this process of loading of a class by class loader:
The process of loading occurs whenever binary representation of a type is brought to the JVM. Linking is done when that type is incorporated in the runtime state of JVM in order to execute it. Finally the process of executing the initializers of type like static field initializers for classes and interfaces is initialization. It should be noted here that when there are no references for a type then it goes to garbage collection. This is called type unloading.
Basically class loaders can be classified into two categories. First is bootstrap class loader which is an integral part of JVM and responsible of loading key classes like basic java library classes. The second category is of user defined class loaders or custom class loaders which are not the integral part of JVM but are subclasses of java.util.ClassLoader class.
| Generating XML Document Using Java servlet | How to Design a XML Document Easily | Understanding Advanced XML Concepts | Understanding Class Loaders in Java | Understanding The Basic Reasons for Development of XML | Understanding Various Methods of Formatting XML Data | Understanding XML Based Web Protocols | Working With ebXML An Indepth Overview | XML Database Program Knowing the Basic Concepts |
Copyright - © 2004 - 2018 - All Rights Reserved.