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

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 …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More

Inverted Half Pyramid Pattern of Alphabets in C

In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More