ClassChecker.java - Reports Class Locations

This section provides a tutorial example, ClassChecker.java, which reports class locations from the classpath of a given class.

ClassChecker.java can also be used to find the location of a given class. For example:

C:\herong>java ClassChecker ClassChecker

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

All locations:
   file:/C:/herong/ClassChecker.class

The output tells me that class "ClassChecker" is loaded from a file at: C:/herong/ClassChecker.class

If I check the "Hello" class from "MyZIP.zip", it tells me that "Hello" is loaded from a JAR file: C:/herong/MyZIP.zip:

C:\herong>java -classpath MyZIP.zip;. ClassChecker
Hello
Class: Hello
Loader: jdk.internal.loader.ClassLoaders$AppClassLoader@129a8472
Loaded from: jar:file:/C:/herong/MyZIP.zip!/Hello.class
All locations:
   jar:file:/C:/herong/MyZIP.zip!/Hello.class

If a class is found at multiple locations from the classpath, it reports me all the locations:

C:\herong>java -classpath .;.\src\Hello.jar;.\src;.\MyZIP.zip 
   ClassChecker Hello

Class: Hello
Loader: jdk.internal.loader.ClassLoaders$AppClassLoader@129a8472
Loaded from: jar:file:/C:/herong/src/Hello.jar!/Hello.class
All locations:
   jar:file:/C:/herong/src/Hello.jar!/Hello.class
   file:/C:/herong/src/Hello.class
   jar:file:/C:/herong/MyZIP.zip!/Hello.class

Last update: 2018.

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

 ClassChecker.java - Reports Class Loader

ClassChecker.java - 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

 JRockit JVM 28.2.7 by Oracle Corporation

 Outdated Tutorials

 References

 Full Version in PDF/EPUB