Class.getClassLoader() has the following syntax.
public ClassLoader getClassLoader()
In the following code shows how to use Class.getClassLoader() method.
/*from www .ja va 2s . co m*/ 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.