Software Engineering Glossary

Class Loader

Also known as: ClassLoader Class Loading Class Loader Subsystem

A class loader is the part of the JVM that finds .class files and brings their bytecode into memory. It works in three phases: loading (read the class file), linking (verify the bytecode, prepare static fields, resolve references), and initialization (run static blocks). Classes load lazily on first use, and loaders follow a parent-first delegation model from the bootstrap loader down to the application loader, which prevents untrusted code from shadowing core Java classes.

Key Takeaways

  • Class loading has three phases: loading, linking (verify, prepare, resolve), and initialization.
  • Classes are loaded lazily, the first time they are actually referenced, not all at once at startup.
  • The parent-first delegation model (bootstrap, platform, application) is a security feature that stops fake core classes.
  • Each loaded class gets one java.lang.Class object on the heap, which is the handle reflection uses.

How It Works

  1. A loader is asked for a class and first delegates the request to its parent loader.
  2. If no parent can supply it, the loader reads the .class bytes and stores the metadata in the method area.
  3. Linking verifies the bytecode, allocates static fields with default values, and resolves symbolic references.
  4. Initialization runs static initializers exactly once per class, guaranteed thread-safe by the JVM.

Where It Is Used

  • Application servers and plugin systems use custom class loaders to isolate modules from each other.
  • Hot-reload and live-restart tools swap class loaders to pick up recompiled classes without a full restart.
  • A ClassNotFoundException or NoClassDefFoundError almost always points to a class loading or classpath problem.

Related glossary terms