After compilation of java program by the compiler, the code turns into a respective .class file that contains Java bytecode. The file and the resources are then loaded onto JRE using Classloader.
Class Loader Subsystem
In the classloader Subsystem there consists of three stages:-
There are three kinds of loaders. Any program requires these three loaders to execute.
Bootstrap Classloader: It loads classes or packages that are essential for a program that resides in rt.jar file such as Java.lang.object, Java.lang.Thread etc.
Extension Classloader: It loads classes from installed optional packages and jar files that are required by JVM for the further processing program which resides within $JRE_HOME/lib/ext directory.
Application Classloader: It loads classes from the application path and this path can be set by using -cp. It is also known as system class loader.
It is responsible for verifying and preparing class or interface, however, the resolution is an optional process in linking. Class get loaded before linking and after that verified and prepared before initialization.
It has three steps:
1)Verification:- It checks whether a class or interface up to the JVM’S structural constraints or not. if not then it would throw VerifyError exception.
2) Preparation:- It initializes the instance variables of the class to its default value.
3) Resolution: It determines the actual value from symbolic references ( references of variables and methods are stored in class’s constant pool) in runtime constant pool, dynamically.
It invokes the class’s static initialization methods to initialize the static variable. It also initializes the class reference if it’s not initialized yet.
Runtime Data Area
It comprised of all the memories which are going to be used by JVM in order to execute a program. Out of these memories, some of them are created when JVM starts up and diminished when it ends up its execution.
- Method area: It stores runtime constant pool, constructors, field and method data, and other meta data corresponding to a class. It is created when JVM starts up. By default the size of Method area are fixed and can be varied as per need.
- Heap:- It is a memory area where all the objects with their properties and arrays get allocated. It is cleaned up and recycled by garbage collector because objects don’t get deallocated by itself. By default the size of Heap is almost one-fourth of the physical memory and can be varied as per need.
- Java Stack: It consists frames which are created, whenever a method is invoked. Basically what t does is, it loads methods when they are invoked in a last-in-first-out manner and destroyed itself as task of the method finishes up. It stores data, partial results and return value of method.
- Pc registers: It is a program counter which points to address of next instruction to be executed. It is responsible for thread management.
- Native method stack:- It manages and stores native methods (methods written in a different language other than the JAVA). It is basically native operating dependent classes that are loaded to work with Java stack.
It is responsible for executing the bytecode. It has three subparts, these are:
Interpreter: It interprets bytecodes line by line and converts the bytecode to the machine understandable language.
Jit-compiler: Just-in-compiler comes into play when a single code inn program appears and executes multiple times. What it does is, it precompiles that particular piece of code and improves the performance by reducing the execution time.
Garbage collector: It cleans up the objects created by using new keyword which are not being used in heap memory area.
Java Native Interface
There may be situation where a programmer cannot writes his application entirely on Java language. In this situation, Java native Interface can be used as it provides a way where native applications can communicate with JAVA application
You must be logged in to take the quiz.