- Reports Class Loader

This section provides a tutorial example,, which reports the class loader by the JVM to load a given class.

While testing class loading behavior of the HotSpot JVM, I have created a simple class loading tool called

 * Copyright (c) All Rights Reserved.
class ClassChecker {
   public static void main(String[] a) {
      if (a.length<1) {
         System.out.println("Missing class name. Usage example:");
         System.out.println("   java ClassChecker");

      String className = a[0];
      String resourceName = className.replaceAll("\\.", "/")+".class";
      try {
         Class clazz = Class.forName(className);
         ClassLoader loader = clazz.getClassLoader();
         System.out.println("Class: "+clazz.getName());
         System.out.println("Loader: "+loader);
            = ClassLoader.getSystemResource(resourceName);
         System.out.println("Loaded from: "+url);

         System.out.println("All locations: ");
         java.util.Enumeration e
            = ClassLoader.getSystemResources(resourceName);
         while (e.hasMoreElements()) {
            url = ( e.nextElement();
            System.out.println("   "+url);
      } catch (Exception e) {
} can help you to identify which class loader is used by the JVM to load your class. For example:

herong> java ClassChecker ClassChecker

Class: ClassChecker
Loader: jdk.internal.loader.ClassLoaders$AppClassLoader@629f0666
Loaded from: file:/C:/herong/ClassChecker.class

All locations:

The output tells me that class "ClassChecker" is loaded by the jdk.internal.loader.ClassLoaders$AppClassLoader class loader.

If check the class, it tells me that jdk.internal.loader.ClassLoaders$PlatformClassLoader is used:

herong> java ClassChecker

Loader: jdk.internal.loader.ClassLoaders$PlatformClassLoader@47fd17e3
Loaded from: jrt:/jdk.crypto.cryptoki/sun/security/pkcs11/P11Util.class
All locations:

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

 Java HotSpot VM - JVM by Oracle/Sun

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

ClassLoader Class - Class Loaders

 What Is Class Loader

 What Is java.lang.ClassLoader Class

 Accessing the ClassLoader of a Class

 JVM "-verbose:class" Option

 loadClass() Method - Loading Classes Explicitly

 getSystemResource() Method - Finding Files

 Class Loading Problem - JAR Hell - Reports Class Loader - Reports Class Locations

 "superclass access check failed" Class Load Error

 Class Loading Followed by Class Initialization

 Class Class - Class Reflections

 JVM Runtime Data Areas

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 OpenJ9 by Eclipse Foundation

 JRockit JVM 28.2.7 by Oracle Corporation

 Archived Tutorials


 Full Version in PDF/EPUB