Java Essentials: Introduction to the JVM

Site Admin · 11 Sep 2026 · 9 views

Meet the Java Virtual Machine

The Java Virtual Machine, or JVM, is the engine that runs every Java program. When you compile a .java file, the javac compiler does not create machine code for your specific operating system. Instead, it creates bytecode inside a .class file. The JVM reads that bytecode and translates it into real instructions that your CPU can execute. This extra layer is what gives Java its famous slogan: Write Once, Run Anywhere.

Because the JVM sits between your code and the hardware, the same compiled program can run on Windows, macOS, and Linux as long as a Java installation exists on the machine. The Java Runtime Environment (JRE) bundles the JVM together with core class libraries such as java.util and java.lang. The Java Development Kit (JDK) goes further and adds the compiler, the debugger, and other build tools.

Running Your First Program

Save the following file as Hello.java:

public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello from the JVM");
    }
}

Open a terminal in the same folder, then compile and run:

javac Hello.java
java Hello

The first command produces Hello.class, which holds the bytecode. The second command hands that bytecode to the JVM. Modern JVMs like HotSpot interpret the bytecode first, then use just-in-time compilation to turn frequently used sections into highly optimized native code. That is why a long-running Java application keeps getting faster.

What Lives Inside the JVM

  • Classloader - locates and loads .class files on demand.
  • Bytecode verifier - checks every class for safety before it executes.
  • Garbage collector - frees memory automatically when objects are no longer used.
  • Execution engine - interprets bytecode and compiles hot paths to native code.

Key Points

  • The JVM executes platform-independent bytecode instead of OS-specific machine code.
  • javac writes .class files and the java command starts the virtual machine.
  • JRE is the JVM plus core libraries, while the JDK adds the compiler and tools.
  • Automatic garbage collection removes the burden of manual memory management.
Share this post:

Comments (0)

Please login or register to comment.