Java ClassLoader Explained: Bootstrap, Extension, and Application

Hello Java Developers, 🚀 Day 11 – Java Revision Series Today’s topic is one of the core pillars of JVM internals and frequently discussed in senior-level Java interviews. ❓ Question What is a ClassLoader in Java and how does it work internally? ✅ Answer A ClassLoader is a part of the JVM responsible for: 👉 Loading Java .class files into memory at runtime Java follows a dynamic class loading mechanism, meaning classes are loaded only when they are needed, not all at once. 🔹 Types of ClassLoaders in Java Java uses a hierarchical ClassLoader architecture: 1️⃣ Bootstrap ClassLoader Loads core Java classes Examples: java.lang.* java.util.* Written in native code (C/C++) Parent of all class loaders 2️⃣ Extension (Platform) ClassLoader Loads classes from: $JAVA_HOME/lib/ext Used for Java extension libraries 3️⃣ Application (System) ClassLoader Loads classes from: Application classpath This is the default class loader for user-defined classes 🔹 ClassLoader Delegation Model (Parent-First) Java follows the Parent Delegation Model: Application ClassLoader checks with Extension ClassLoader Extension checks with Bootstrap ClassLoader If parent cannot load the class, control returns downward ➡️ This prevents: Core Java classes from being overridden Security issues Duplicate class definitions 🔹 How a Class Is Loaded (Internally) A class goes through three main phases: 1️⃣ Loading .class file is read into memory 2️⃣ Linking Includes: Verification (bytecode safety) Preparation (static memory allocation) Resolution (symbolic references → direct references) #Java #CoreJava #NestedClasses #StaticKeyword #OOP #JavaDeveloper #LearningInPublic #InterviewPreparation

  • text, letter

To view or add a comment, sign in

Explore content categories