What Is the Java Virtual Machine? An Introduction and Architecture Overview
This article explains the concept, purpose, and internal architecture of the Java Virtual Machine, compares Java and C program execution, and describes the JVM's class loader, execution engine, and garbage collection subsystems with illustrative code examples and diagrams.
The Java Virtual Machine (JVM) is an abstract computing engine that executes Java bytecode, providing a platform‑independent environment by abstracting away operating‑system details.
From an operating‑system perspective, a JVM runs as a regular process; when a Java program is launched, the java command starts the JVM process, which then loads the specified class, performs initialization and dynamic linking, and executes the main method.
To illustrate the difference between native and Java execution, the article first presents a simple C HelloWorld program, shows its compilation with gcc HelloWorld.c -o HelloWorld, and runs it directly as a binary process:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("hello world
");
return 0;
}The compiled binary can be executed with ./HelloWorld, creating a process that the OS runs directly.
In contrast, the Java version requires two steps: compilation with javac HelloWorld.java producing a .class file, and execution with java -classpath . HelloWorld. The .class file is not a native executable; it is loaded by the JVM process.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("HelloWorld");
}
}The JVM architecture consists of three main subsystems:
Class Loader – loads classes on demand, similar to a mouth taking in food.
Execution Engine – interprets or JIT‑compiles bytecode into native instructions, analogous to digestion.
Garbage Collector – automatically reclaims memory of unused objects, comparable to waste elimination.
These subsystems work together within the JVM’s runtime data areas (method area, heap, stack, etc.) to manage memory, execute bytecode, and provide a managed environment for Java applications.
The article concludes that the JVM is essentially a specialized process that hosts Java programs, handling class loading, execution, and memory management, and recommends further reading such as "深入Java虚拟机", "深入理解Java虚拟机JVM高级特性与最佳实践", and the official JVM specification.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
