JVM Class Loading Explained: From Loading to Initialization

This article provides a comprehensive, step‑by‑step explanation of the JVM class‑loading mechanism, covering the five phases—Loading, Verification, Preparation, Resolution, and Initialization—along with diagrams and detailed descriptions of each operation performed by the JVM.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
JVM Class Loading Explained: From Loading to Initialization

JVM Class Loading Mechanism

JVM class loading refers to the process of loading bytecode files into memory, as illustrated below:

The mechanism consists of five phases: Loading, Verification, Preparation, Resolution, and Initialization.

Loading

Loading reads the class bytecode from the file system or network into memory and creates a java.lang.Class object.

During this phase the JVM:

Uses class loaders to locate and load the bytecode data from various sources.

Transforms the bytecode into internal JVM data structures and stores them in the method area.

Allocates memory for static variables and assigns default values.

Creates the Class object representing the class and stores it in the method area.

Verification

Verification ensures that the loaded class conforms to JVM specifications and does not threaten security.

The verification step includes three checks:

File format verification – checks the class file header, constant pool, and illegal instructions.

Semantic verification – analyzes bytecode for illegal type conversions, illegal method access, etc.

Bytecode verification – checks for out‑of‑bounds array access, unsafe pointers, and other hazards.

Preparation

In the preparation phase the JVM allocates memory for static variables in the heap and sets default values.

Default values are:

Numeric primitive types (int, float, etc.) → 0 or 0.0

boolean → false

char → '\u0000' (null character)

Reference types → null

Resolution

Resolution converts symbolic references in the constant pool into direct references.

The JVM performs:

Replacing symbolic references in the constant pool with direct references.

Resolving superclass and super‑interface symbolic references.

Resolving field and method symbolic references to direct references.

Initialization

Initialization is the final phase where static variables receive their initialized values and static blocks are executed.

During initialization the JVM:

Allocates memory for static variables and sets their initialized values.

Executes static initializer blocks.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaJVMBackend DevelopmentRuntimeclass loading
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.