Java Virtual Machine (JVM), JDK, JRE3 min read

In this article, we learn all about JVM and its architecture and also we will compare JDK, JRE, and JVM with important points required.

What is JVM?

JVM stands for Java Virtual Machine, which is an abstract machine that provides a run-time environment to run Java programs. It converts Java byte-code into machine language, so not only Java but it also enables the computer to run other programs that are compiled to byte-code.

JVM is a part of the JRE(Java Run Environment). However, the reason for the Java program is executed by the JVM helps to solve the major problems related to web-based programs and also to make it secure.

JVM working process can be explained in the following manner:

  • It first loads byte-code.
  • then verifies the byte-code.
  • Then executes byte-code providing runtime environment.

JVM Architecture:

1. ClassLoader subsystem:

This subsystem is used for loading class files. It performs three major functions :

Loading, Linking, and Initialization.

There are three built-in classloaders in Java.

  • Bootstrap ClassLoader: It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes.
  • Extension ClassLoader: It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
  • System ClassLoader: It loads the class files from the classpath. Also known as Application classloader.

2. JVM Memory:

  • Method Area:
    In the method area, structures like the run-time constant pool, field and method data, variables information, static variables, etc. are stored.
  • Heap:
    It is a shared resource among all the threads and created during run-time. All the Objects, metadata, and arrays are stored in the heap.
  • JVM language Stacks:
    Java language Stacks stores parameters, local variables, and return addresses during method calls. It is not a shared resource. One JVM stack is created simultaneously for each thread that is each thread contains its own JVM stack.
  • PC Registers:
    PC(Program Counter) Register contains/stores the address of JVM(Java Virtual Machine) instruction that is being currently executed. Each thread in Java has its own PC register.
  • Native Method Stacks:
    Every thread has its own separate native stack hold the native method information.

3. Execution Engine:

The execution engine executes the bytecode, reading it line by line.

It contains three parts:

  • Interpreter:
    The work of the interpreter is to read the byte-code line by line and then execute it.
  • Just-In-Time Compiler(JIT):
    It is used to increase the performance of the compiler by taking the block of similar byte-code that is the repeated method calls. Hence reducing the compilation time and making it more efficient.
  • Garbage Collector:
    It is used to destroy the useless objects or objects that are no longer required.

4. Java Native Interface (JNI):

It provides the native libraries required for the execution of a program. It allows the JVM to call other Libraries like C, C++, Assembly, etc., providing the interface to interact with other Native Application.

5. Native Method Libraries:

This is a collection of the Native Libraries(C, C++) which are required by the Execution Engine. These are the “native” codes, that is, the code that is compiled for a specific hardware architecture or operating systems such as X86 or windows.

Comparison between JDK, JRE, and JVM


MORE

C Program to search an element in an array using Pointers

A separate function( search_function()) will be created where the array pointer will be declared and the searched element along with the size of an array …

C Program to find the sum of the digits of a number using recursion function

This C program calculates the sum of digits of a given number using recursion. Here’s a concise explanation: Function Definition: sumDigits(int n) This function calculates …

C program to find factorial of a numberĀ using Ternary operator with Recursion

Recursion refers to the function calling itself directly or in a cycle. Before we begin, you should have the knowledge of following in C Programming: …

C Program to Add Two Numbers Using Call by Reference

The program takes the two numbers from the user and passes the reference to the function where the sum is calculated. You may go through …

Find the output ab, cd, ef, g for the input a,b,c,d,e,f,g in Javascript and Python

In this tutorial, we will write a program to find a pairs of elements from an array such that for the input [a,b,c,d,e,f,g] we will …

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …