Java virtual machine is an abstract machine which provides you with the runtime environment to execute Java bytecode. JVM depends on the underlying platform. JVM is nor compatible with many hardware and software.
What is JVM (Java Virtual Machine)?
JVM is a specification which specifies the working of JVM. but the algorithm will be chosen by their implementation provider. JVM’s implementation is provided by Oracle and other companies. JVM is also an implementation which is specified by JRE. JVM is a runtime instance which will be created whenever you run the java class.
JVM allows you to perform some operations like- loading the code, verifying the code, executing the code and providing a runtime environment.
JVM architecture defines- classloader, memory area, execution engine etc.
Classloader will load the Java class file and is a subsystem of JVM. When we run a Java program it will be loaded by classloader. You can create a customized class loader which has to extend the classloader class. Java has three built-in classloader-
- Bootstrap ClassLoader-: This is the superclass of the Extension ClassLoader. It enables the loading of rt.jar files which holds Java standard edition class files.
- Extension ClassLoader: This classloader is the subclass of Bootstrap classloader and the parent for the system classloader. It will help in loading the jar files from the extension directory.
- System ClassLoader: Also known as the application classloader and is a child of Extension classloader. It helps in loading the class file from the classpath. You can change the classpath using -cp or the -classpath command. 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.
Heap is used to allocate objects and is a runtime data area.
Java stacks are used to store stacks which 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 address of the instruction which will be executed by the Java Virtual Machine.
6. Execution Engine
It consists of- a virtual processor, interpreter and the JIT compiler.
7. Java Native Interfaces
This is a framework used by Java as an interface to communicate with the programs written in a different language. It allows sending the output to the console or to connect with OS libraries.
People are also reading: