JVM(Java Virtual Machine) runs Java applications as a run-time engine. JVM is the one that calls the main method present in a Java code. JRE (Java Runtime Environment) includes the JVM. Java applications are called WORA (Write Once Run Anywhere). This means that a programmer can write Java code on one system and expect it to work on any system with Java support. This is all possible because of JVM.
When we compile a .java file, .class files(contains byte-code) with the same class names present in .java file are generated by the Java compiler. This .class file goes into various steps when we run it. Together, these steps describe the JVM as a whole.
Java course in Aurangabad
1. Subsystem for the Class Loader It is mainly responsible for three activities.
Loading
Linking
Initialization
Loading:
The Class loader reads the “.class” file, generate the corresponding binary data and save it in the method area. JVM stores the following data in the method area for each “.class” file. The fully qualified name of the loaded class and its immediate parent class.
Whether the “.class” file is associated with an Enum, Interface, or Class. Modifier, Variables and Method information etc.
After loading the “.class” file, JVM creates an object of type Class to represent this file in the heap memory. Please note that this object is of type Class predefined in java.lang package. These Class object can be used by the programmer for getting class level information like the name of the class, parent name, methods and variable information etc. We can use the Object class’s getClass() method to obtain this object reference.
Java classes in Aurangabad
Linking
carries out verification, preparation, and, if desired, resolution. Verification: It verifies whether or not the.class file was generated by a valid compiler and whether or not it is correctly formatted. We receive the run-time exception java.lang.VerifyError if verification fails. ByteCodeVerifier is the component that performs this action. Once this activity is completed then the class file is ready for compilation.
Preparation: JVM allocates memory for class static variables and initializing the memory to default values.
Resolution: It is the process of replacing symbolic references from the type with direct references. It is done by searching into the method area to locate the referenced entity.
Initialization
In this phase, all static variables are assigned with their values defined in the code and static block(if any). In a class, this is carried out from the top to the bottom and from the parent to the child in the class hierarchy. In general, there are three class loaders:
Bootstrap class loader: Every JVM implementation must have a bootstrap class loader, capable of loading trusted classes. It loads the “JAVA_HOME/lib” directory’s core Java API classes. The bootstrap path is a common name for this path. It is implemented in native C and C++ languages. The bootstrap class loader is a child of the extension class loader. It loads the classes present in the extensions directories “JAVA_HOME/jre/lib/ext”(Extension path) or any other directory specified by the java.ext.dirs system property.
Java Training in Aurangabad
The sun.misc.Launcher$ExtClassLoader class in Java implements it. System/Application class loader: It is a child of the extension class loader. Classes from the application’s classpath are loaded by it. It uses an Environment Variable that is mapped to java.class.path internally. It is also implemented in Java by the sun.misc.Launcher$AppClassLoader class.