Java virtual machine is an abstract machine that provides you with the runtime environment to execute Java bytecode. It depends on the underlying platform. It is not compatible with many hardware and software.
What is JVM (Java Virtual Machine)?
JVM is a specification that specifies the working of JVM. But the algorithm will be chosen by their implementation provider. Oracle and other companies provide JVM’s implementation.
Also, JVM is an implementation that JRE specifies. It is a runtime instance that will be created whenever you run the Java class. It allows you to perform some operations like
- Loading the code
- Verifying the code
- Executing the code
- Providing a runtime environment
The following are the components of the JVM architecture:
1. Class Loader
A class loader will load the Java class file and is a subsystem of JVM. When we run a Java program, it will be loaded by the class loader. You can create a customized class loader that has to extend the classloader class.
Java has three built-in class loaders -
- Bootstrap ClassLoader-: This is the superclass of the Extension ClassLoader. It enables loading rt.jar files, which hold Java standard edition class files.
- Extension ClassLoader: This ClassLoader is the subclass of the Bootstrap classloader and the parent for the system ClassLoader. It will help in loading the jar files from the extension directory.
Also known as the application ClassLoader, and is a child of the Extension ClassLoader. It helps in loading the class file from the classpath. You can change the classpath using
-classpathcommand. Classpath points to the current directory by default.
2. Class Area
The class area allows you to store the structure of per class, like runtime constant pool, method, and method codes.
A heap is used to allocate objects and is a runtime data area.
Java stacks are used to store stacks that contain the local variable and the partial results. JVM stack is created with each thread, and each thread has its stack. This frame will be created with the method invocation and destroyed when the method invocation finishes.
5. Program Counter Register
This counter will hold the instruction address that the Java Virtual Machine will execute.
6. Execution Engine
It consists of- a virtual processor, an interpreter , and the JIT compiler.
7. Java Native Interfaces
This is a Java framework used as an interface to communicate with programs written in a different language. It allows sending the output to the console or to connect with OS libraries.