10X Sale
kh logo
All Courses
  1. Tutorials
  2. Java

Java Virtual Machine

Updated on Sep 2, 2025
 
32,974 Views
Table of Content

JVM in java

JVM is an engine that offers the Java Code or applications runtime environment. It transforms bytecode Java into the language of computers. JVM (Java Run Environment) is a component of JRE. It is a Java Virtual Machine.

  1. The compiler generates machine code for a specific scheme in other programming languages. However, for a virtual machine known as Java Virtual Machine, Java compiler generates code.
  2. First, the bytecode for Java code is generated. This bytecode is interpreted on various computers
  3. Bytecode is an intermediate code between the host system and the source code of Java.
  4. JVM is accountable for memory space allocation.

JVM

JVM is an abstract machine (Java Virtual Machine). It is a specification that offers runtime environment and allows the execution of java bytecode.

For many hardware and software platforms, JVMs are available (i.e. JVM depends on the platform).

JVM is the Java Virtual Machine – it actually executes Java ByteCode.

JRE is the Java Runtime Environment – it contains a JVM, among other things, and is what you need to run a Java program.

JDK is the Java Development Kit – it is the JRE, but with javac (which is what you need to compile Java source code) and has other programming tools added.

Let's comprehend JVM's inner architecture. It includes classloader, region of memory, engine of execution, etc.

JVM Inner Architecture

Classloader is a JVM subsystem for loading class files. Every time we run the java program, the classloader loads it first. In Java, there are three integrated class loaders.

  1. Bootstrap ClassLoader
    This is the first-class loader to the Extension class loader super class. It loads the rt.jar file containing all Java Standard Edition class files such as package classes java.lang, package classes java.net, package classes java.util, package classes java.io, package classes java.sql etc.
  2. Extension ClassLoader
    This is Bootstrap's child classloader and System classloader's parent classloader. It loads the jar documents within the folder of $JAVA HOME / jre / lib / ext.
  3. System/Application ClassLoader
    It is the child classloader of Extension classloader. It loads the classfiles from classpath. By default, classpath is set to current directory. You can change the classpath using "-cp" or "-classpath" switch. It is also known as Application classloader.
// Below is an example to print the classloadername in java 
publicclass MyClassLoaderProgram 
{   
publicstaticvoid main(String[] args)   
    {   
        Class c= MyClassLoaderProgram.class;   
        System.out.println(c.getClassLoader());   
        System.out.println(String.class.getClassLoader());   
    }   
}     

These are Java's inner class loaders. You need to extend the ClassLoader class if you want to create your own classloader.

Class (Method) Area

Class(Method) Area stores structures per class such as the runtime constant pool, field and method data, the method code.

Heap

It is the runtime data pool in which objects are placed.

Stack

Frames are stored in Java Stack. It maintains local variables and partial outcomes and plays a role in invoking and returning the method.

Each thread has a personal JVM stack, which is generated simultaneously with a thread.

Every time a method is invoked, a new frame is developed. When the invocation method finishes, a frame is demolished.

Program Counter Register

PC (program counter) register includes the address of the presently executed Java virtual machine instruction.

Native Method Stack

It includes all of the application's native methods.

Execution Engine

It contains the below things:

  1. A virtual processor
  2. Interpreter
    Execute the instruction by reading the bytecode stream.
  3. Just-In-Time (JIT) compiler
    Used for performance enhancement. JIT compiles parts of the byte code that simultaneously have similar functionality, thus reducing the amount of time required for compilation. The word "compiler" here relates to a translator from a Java virtual machine's instruction set (JVM) to a particular CPU's instruction set.

Java Native Interface

Java Native Interface (JNI) is a framework for communicating with another application written in a different language such as C, C++, Assembly, etc. Java utilizes JNI framework to send output or communicate with OS libraries to the Console.

+91

By Signing up, you agree to ourTerms & Conditionsand ourPrivacy and Policy

pattern
10% OFF
Coupon Code "TEN10"
Coupon Expires  17/11
Copy
Get your free handbook for CSM!!
Recommended Courses