Java Class.getClassLoader()

Syntax

Class.getClassLoader() has the following syntax.

public ClassLoader getClassLoader()

Example

In the following code shows how to use Class.getClassLoader() method.


/*  ww  w.j  a va  2 s.c  om*/

public class Main {

  public static void main(String[] args) throws Exception {
    Class cls = Class.forName("java.lang.String");
    // returns the ClassLoader object associated with this Class.
    ClassLoader cLoader = cls.getClassLoader();

    if (cLoader == null) {
      System.out.println("The default system class was used.");
    } else {
      // returns the class loader
      Class loaderClass = cLoader.getClass();
      System.out.println(loaderClass.getName());
    }
  }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable