Java Utililty Methods Class Load

List of utility methods to do Class Load

Description

The list of methods to do Class Load are organized into topic(s).

Method

ClassloadClass(String className)
load Class
ClassLoader loader = Thread.currentThread().getContextClassLoader();
return loadClass(className, loader);
ClassloadClass(String className)
load Class
try {
    return Class.forName(className);
} catch (ClassNotFoundException e) {
    throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
} catch (NoClassDefFoundError e) {
    return null;
ClassloadClass(String className)
load Class
try {
    return Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
    try {
        return Class.forName(className);
    } catch (ClassNotFoundException ex) {
        try {
            return ClassLoader.class.getClassLoader().loadClass(className);
...
ClassloadClass(String className)
load Class
Class<?> result = null;
if (className != null) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    result = (cl != null ? cl.loadClass(className) : null);
return result;
ClassloadClass(String className)
load Class
return getDefaultClassLoader().loadClass(className);
ClassloadClass(String className)
Load the class
try {
    return Class.forName(className);
} catch (ClassNotFoundException e) {
    throw new IllegalStateException(e);
ClassloadClass(String className)
load Class
return loadClass(className, getContextClassLoader());
ClassloadClass(String className)
Load class from the previously set class loader.
ClassLoader loader = currentClassLoader;
if (loader == null) {
    loader = Thread.currentThread().getContextClassLoader();
try {
    return Class.forName(className, false, loader);
} catch (ClassNotFoundException e) {
    ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
...
ClassloadClass(String className)
Loads a class with the given name.
Class<T> clazz = null;
try {
    clazz = (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException nf) {
    clazz = (Class<T>) Class.forName(className);
return clazz;
ClassloadClass(String className)
Load the specified class, which can be a (public static) inner class provided the physical name is used ("my.package.MyClass$MyInnerClass") rather than the canonical name ("my.package.MyClass.MyInnerClass")
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
return classLoader.loadClass(className);