Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Industrial programming >> Java

JVM Explained: What It Is and Its Architecture

What Is the JVM?

Java Virtual Machine (JVM) is the runtime engine that powers Java applications. It transforms compiled Java bytecode into native machine instructions and executes them on any platform that supports the JVM. The JVM is a core component of the Java Runtime Environment (JRE). Unlike languages that compile directly to machine code for a specific operating system, Java’s compiler produces platform‑agnostic bytecode that the JVM interprets or compiles at runtime.

How the JVM Works

Java source is first compiled into bytecode, which the JVM then interprets or compiles just‑in‑time (JIT) into native code. The JVM also manages memory allocation, thread scheduling, and interaction with native libraries.

JVM Explained: What It Is and Its Architecture

In this tutorial you’ll learn:

JVM Architecture

The JVM’s design is modular, comprising several subsystems that work together to load, verify, and execute Java code.

JVM Explained: What It Is and Its Architecture
  1. Class Loader – Loads class files and performs linking (verification, preparation, resolution) and initialization.
  2. Method Area – Stores class structures, metadata, constant pools, and method code.
  3. Heap – Holds all objects, instance variables, and arrays. It is shared among all threads.
  4. Java Stack – Each thread has its own stack that stores local variables and partial results. A new frame is created on method entry and popped on exit.
  5. Program Counter (PC) Register – Holds the address of the next instruction to execute for each thread.
  6. Native Method Stack – Stores calls to native code (written in C/C++).
  7. Execution Engine – Executes bytecode, either by interpretation or via the JIT compiler.
  8. Native Method Interface (JNI) – Enables Java code to invoke native libraries.
  9. Native Libraries – Collections of platform‑specific native code used by the execution engine.

Software Code Compilation & Execution Process

Running a program typically involves these steps:

  1. Editor – Where you write the source code.
  2. Compiler – Translates high‑level code into native machine code or bytecode.
  3. Linker – Combines object files and resolves external references.
  4. Loader – Loads the final executable into memory.
  5. Execution – The operating system and processor run the program.

C Code Compilation and Execution

To illustrate the Java process, let’s first examine a simple C program. Assume the main function is in a1.c and calls f1 (in a2.c) and f2 (in a3.c).

JVM Explained: What It Is and Its Architecture

The compiler turns each .c file into an object file containing machine code. The linker then merges these object files into a single .exe executable. When the program starts, the loader maps myapp.exe into RAM and the operating system begins execution.

JVM Explained: What It Is and Its Architecture

Java Code Compilation and Execution in the JVM

Java follows a similar yet distinct workflow. The source files a1.java, a2.java, and a3.java are compiled into bytecode files a1.class, a2.class, and a3.class. No separate linking stage occurs; the JVM loads the bytecode on demand.

JVM Explained: What It Is and Its Architecture

During execution, the JVM’s class loader brings the class files into memory, verifies them for security, and the execution engine either interprets or JIT‑compiles the bytecode into native machine code. This JIT step is what makes Java both compiled and interpreted.

JVM Explained: What It Is and Its Architecture

Note: The JIT compiler is a core component of the JVM that performs on‑the‑fly translation of bytecode into efficient native instructions.

Why Is Java Both Compiled and Interpreted?

Java’s design marries the benefits of compiled and interpreted languages:

Why Is Java Slower?

Java’s runtime overhead originates from two main sources:

  1. Dynamic Linking – Methods are resolved at runtime rather than at compile time, which adds a small lookup cost.
  2. Run‑time Bytecode Interpretation – Even with JIT, the initial execution of bytecode incurs a conversion cost before native code is produced.

Modern JVM implementations have dramatically reduced these overheads through aggressive optimization, tiered compilation, and hardware‑specific tuning.

Summary

Java

  1. Virtual Machines Explained: Types, Architecture, and Key Advantages
  2. Chatbots 101: Design Process, Architecture, and Practical Insights
  3. Understanding Java: JDK, JRE, and JVM Explained
  4. What Is CNC? – Understanding Computer Numerical Control for Modern Manufacturing
  5. Understanding Architecture Design: Principles, Practices, and Impact
  6. Understanding Binding Machines: Types, Uses, and How They Keep Documents Secure
  7. Machine Bolts Explained: Types, Uses, and Installation Guide
  8. How Claw Machines Work: The Thrill of the Arcade Prize Hunt
  9. Understanding Thread Machines: Precision Threading for Metal and Plastic
  10. Machine Tending Explained: Benefits, Automation, and Applications