What is the JVM?

JVM(Java Virtual Machine) is a virtual machine for running Java.

Java application often referred to as WORA (Write Once Run Anywhere). This means that a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. This is all possible because of JVM.

In other words, JVM is a virtual machine that allows to CPUs to recognize and execute Java without being dependent on any specific OS.

A “.java” file is can not be recognized by a CPU, so it needs to be compiled into machine code(also known as bytecode). However, Java does not compile directly into machine code that the OS can recognize. Instead, it goes through the JVM. The Java source code is converted into Java bytecode (*.class), which the JVM can understand. And Java compiler transfer a “.java” file into a “.class”(bytecode) file.

The transformed bytecode is also not executable directly by the operating system since it's not machine code. The JVM interprets the bytecode to make it understandable to the OS. Therefore, bytecode can be executed on top of the JVM regardless of the underlying operating system.

JVM Architecture

Untitled

JVM contains Class Loader, JVM Memory, Execution Engine.

Class Loader

The Class Loader primarily handles the following three tasks:

  1. Loading
  2. Linking
  3. Initialization

In more detail, the Class Loader is responsible for loading ".class" files into the JVM and linking them to place them in the JVM's memory area.