Java Virtual Machine (JVM) in Java

The Java Virtual Machine is a platform independent abstract machine. It is particularly responsible for creating a run-time environment that is conducive for byte code to execute efficiently. As it is platform-independent, JVM can be used for a series of hardware and software platforms.

What is JVM?

  • It is a specification that determines how bytecode will be processed in various hardware and software. The implementation provider is, however, free to choose from any algorithm. As JAVA is owned by Oracle currently, the company dictates the implementation conventions.
  • The JVM creates a runtime environment called the Java Runtime Environment (JRE).
  • Whenever a Java code is executed or a command is entered in the command prompt, Java creates an instance of the JVM.

What the JVM does?

The Java Virtual Machine performs the following operations:

  • Loads the code as an instance of the JVM is created whenever the code begins to compile.
  • The JVM then verifies the code.
  • Executes the code by using the bytecode provided by the compiler.
  • Creates a runtime environment (JRE).

JVM also provides definitions for the following:

  • Memory Area
  • Class file format
  • Register Set
  • Garbage-collected Heap
  • Fatal error reporting etc.

JVM Architecture

The JVM Architecture can be broken down in the following components:

  1. Classloader – As the name suggests, the classloader loads the class files whenever a new program is executed. There are three in-built classloaders in Java namely Bootstrap ClassLoader, Extension ClassLoader, and System/Application ClassLoader.
  2. Class (Method) Area – This is a designated area for the current class components under execution.
  3. Heap – Objects are allocated here.
  4. Stack – Java Stack stores local variables and frames.
  5. Program Counter Register – It contains the address of the JVM.
  6. Native Method Stack – Contains all the native methods.
  7. Execution Engine – Contains a virtual processor, interpreter, and a Just in Time (JIT) compiler.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.