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

ClassloadClassFromClassLoader(String fillyQualifiedClassName)
load Class From Class Loader
Class clazz = null;
try {
    clazz = wsasClassLoader.loadClass(fillyQualifiedClassName);
} catch (ClassNotFoundException e) {
    e.printStackTrace();
return clazz;
ClassloadClassFromContextClassLoader(String theClassName)
Try loading class using the Context class loader.
return Class.forName(theClassName, true, Thread.currentThread().getContextClassLoader());
ClassloadClassOrNull(String className)
load Class Or Null
ClassLoader loader = getClassLoaderForResolving();
try {
    return loader.loadClass(className);
} catch (ClassNotFoundException e) {
    return null;
ClassloadClassOrReturnNull(ClassLoader loader, String className)
load Class Or Return Null
if (loader == null) {
    loader = ClassLoader.getSystemClassLoader();
try {
    return loader.loadClass(className);
} catch (ClassNotFoundException e) {
    return null;
ClassloadClassReflectively(ClassLoader classLoader, String fullyQualifiedClassName)
load Class Reflectively
try {
    return classLoader.loadClass(fullyQualifiedClassName);
} catch (ClassNotFoundException e) {
    throw new RuntimeException(e);
ClassloadClassSafe(final String klassName)
Loads a class with given klassName.
try {
    return Class.forName(klassName);
} catch (ClassNotFoundException e) {
    return null;
ClassloadClassSilently(ClassLoader cl, String name)
load Class Silently
Class<?> clz;
try {
    clz = cl.loadClass(name);
    return clz;
} catch (ClassNotFoundException e) {
    return null;
ClassloadClassUsingClass(Class clazz, String name)

This is a simple utility class that attempts to load the named class using the class loader of the supplied class or the class loader of one of its super classes or their implemented interfaces.

Class loadedClass = null;
while (clazz != null) {
    ClassLoader loader = clazz.getClassLoader();
    loader = (loader == null) ? ClassLoader.getSystemClassLoader() : loader;
    try {
        return loader.loadClass(name);
    } catch (ClassNotFoundException ex) {
    Class[] ifcs = clazz.getInterfaces();
    for (int i = 0; i < ifcs.length; i++) {
        loadedClass = loadClassUsingClass(ifcs[i], name);
        if (loadedClass != null) {
            return loadedClass;
    clazz = clazz.getSuperclass();
return null;
ClassloadClassViaContext(String fqcn)
load Class Via Context
ClassLoader loader = Thread.currentThread().getContextClassLoader();
try {
    return loader == null ? null : loader.loadClass(fqcn);
} catch (ClassNotFoundException e) {
return null;
ClassloadClassWithTCCL(String name)
load Class With TCCL
if ("byte[]".equals(name)) {
    return byte[].class;
return Thread.currentThread().getContextClassLoader().loadClass(name);