Skip to content
Learnearn.uk » IB Computer Science » Java Virtual Machine

Java Virtual Machine

Intro

Introduction to the JVM

The Java Virtual Machine (JVM) is a virtual platform that allows Java programs to run on any device or operating system.

It acts as an intermediary between compiled Java code (bytecode) and the hardware, making Java programs platform-independent — a principle known as “write once, run anywhere.”

Bytecode

Bytecode Execution

When Java code is compiled, it is converted into bytecode — a low-level, platform-independent code.

The JVM reads and executes this bytecode using either:

  • Interpretation – executing bytecode line-by-line
  • Just-In-Time (JIT) Compilation – translating bytecode into native machine code at runtime for improved performance

This approach allows Java to combine flexibility with performance.

Components

Main Components of the JVM

The JVM is made up of several key components that work together to manage program execution:

  • Class Loader – loads class files into memory
  • Bytecode Verifier – checks code for security and correctness
  • Runtime Data Areas – memory used during execution (heap, stack, method area, etc.)
  • Execution Engine – executes the bytecode, either through interpretation or JIT
  • Garbage Collector – automatically reclaims unused memory

Memory

JVM Memory Management

The JVM uses several memory areas to manage data during program execution:

  • Heap – stores objects and class instances
  • Stack – stores method calls and local variables
  • Method Area – stores class-level information
  • Program Counter (PC) – tracks the current instruction
  • Native Method Stack – handles native (non-Java) code execution

Effective memory management is crucial for performance and stability, and the JVM handles this automatically using garbage collection.

Portability

Portability & Platform Independence

One of the JVM’s most powerful features is its ability to run the same compiled code on any system that has a JVM installed.

This platform independence:

  • Reduces development time across multiple systems
  • Makes Java ideal for enterprise and mobile applications
  • Ensures consistent behavior across devices

As long as a JVM is available for the target platform, Java applications can run without modification.

Security

Security Features

The JVM includes built-in mechanisms to protect systems from malicious or faulty code.

Security features include:

  • Bytecode verification to detect invalid or dangerous code
  • Runtime checks for array bounds and null references
  • Sandboxes that restrict what applets or applications can access
  • Custom security policies to define permissions

These features make the JVM a trusted environment for running untrusted or remote code safely.

Performance

Performance Enhancements

While interpreted code is flexible, it can be slower. The JVM uses several techniques to improve performance:

  • Just-In-Time (JIT) Compilation – compiles frequently used bytecode into native code
  • Adaptive Optimization – adjusts performance based on execution patterns
  • Garbage Collection tuning – reduces memory-related delays

Modern JVMs are highly optimized and suitable for performance-critical applications.

 

Resources