What is JVM?

  • Java Virtual Machine (JVM) is an engine that provides a runtime environment to drive Java Code or applications. 
  • It converts Java bytecode into machine language. JVM is a part of the Java Run Environment (JRE). 

Here is the working

  • Java Virtual Machine(JVM) is a virtual machine that provides a runtime environment to execute Java bytecode.

  • The JVM doesn’t understand Java typos, that’s why you compile your *.java files to obtain *.class files that contain bytecodes that understandable by JVM.

  • This bytecode gets interpreted on different machines, bytecode is an intermediary language
  • JVM controls the execution of every Java program. It enables features such as automated exception handling, Garbage-collected heap.

What JVM does?

  1. JVM performs operations

      1. Loads code
      2. Verify code
      3. Executes code
      4. Provides runtime environment
  2. JVM provides definitions for the:

      1. Memory area

      2. Class file format
      3. Register set
      4. Garbage-collected heap
      5. Fatal error reporting etc.

Here is a simple brief about JVM architecture


Classloader– Classloader is a subsystem of JVM which is used to load class filesIt performs three major functions viz. Loading, Linking, and Initialization.

  1. Bootstrap ClassLoader:
    • This is the first classloader which is the superclass of Extension 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, java.io package classes, java.sql package classes, etc.
  2.  Extension ClassLoader:
    • This is the child classloader for Bootstrap and the parent classloader for the System classloader.
    • It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
  3. System/Application ClassLoader:

    • This is the child classloader of the Extension classloader. It loads the class files from the classpath. By default, the classpath is set to the current directory. 
    • You can change the classpath using the “-cp” or “-classpath” switch. It is also known as the Application classloader.
  4. Method Area:

    • Method Area stores per-class structures such as the runtime constant pool, field and method data, and the code for methods.

  5. Heap:

    •  This is the runtime data area in which objects are allocated.
    • This memory is common and shared across multiple threads.
  6. JVM language Stacks

    • Java Stack stores frames. 
    • Java language Stacks holds local variables and it’s partial results, and plays a part in method invocation and return.
    • Each thread has a private JVM stack, created at the same time as the thread.
    • A new frame is created each time a method is invoked. The frame is destroyed when its method invocation completes.
  7. Program Counter Registers:

    • The PC register stores the address of the Java virtual machine instruction which is currently executing. In Java, each thread has its own separate PC register.

  8. Native Method Stacks:

    • Native method stacks hold the instruction of native code depending on the native library. 
    •  It is written in another language instead of Java.
  9. Native Method interface:

    • The Native Method Interface is a programming framework.
    • It allows Java code that is running in a JVM to be called by libraries and native applications.
  10. Native Method Libraries:

    • Native Libraries is a collection of the Native Libraries(C, C++) that are needed by the Execution Engine.

  11. Execution Engine:

    • It is a type of software used to test hardware, software, or complete systems. 

    • The test execution engine never carries any information about the tested product.

Software code compilation and execution

  • Editor – To type the program into, a notepad could be used for this.
  • Compiler – To convert your high language program into native machine code
  • Linker –It is a program in a system that helps to link object modules of a program into a single object file. It performs the process of linking.
  • Loader – To load the files from your secondary storage device like Hard Disk, Flash Drive, CD into RAM for execution. The loading is automatically done when you execute your code.
  • Execution – Actual execution of the code, which is handled by your OS & processor.