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(final String className)
Loads the class with the given name, or null if it cannot be loaded.
return loadClass(className, null);
ClassloadClass(final String className)
load Class
try {
    return (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
    throw new IllegalArgumentException("Unable to load class " + className);
ClassloadClass(final String className)
load Class
if (className == null) {
    return null;
try {
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader != null) {
        try {
            final Class clazz = classLoader.loadClass(className);
...
ClassloadClass(final String className, final ClassLoader classLoader)
Tries to load the class with the given name.
try {
    final ClassLoader cl = classLoader == null ? Thread.currentThread().getContextClassLoader()
            : classLoader;
    return cl.loadClass(className);
} catch (final ClassNotFoundException e) {
    return null;
ClassloadClass(final String className, final ClassLoader classLoader)
Helper method to load a class.
Class<?> cls = null;
if (classLoader == null) {
    cls = Class.forName(className.trim());
} else {
    cls = Class.forName(className.trim(), true, classLoader);
return cls;
ClassloadClass(final String clazz)
Loads the given class using the context class loader
Class<?> clazzObject;
try {
    clazzObject = Thread.currentThread().getContextClassLoader().loadClass(clazz);
} catch (final ClassNotFoundException e) {
    throw new RuntimeException("Unable to load " + clazz, e);
return clazzObject;
ClassloadClass(final String fqcn)
Load a root entity class or return null if it can't be loaded.
try {
    return Thread.currentThread().getContextClassLoader().loadClass(fqcn);
} catch (final ClassNotFoundException e) {
    return null;
ObjectloadClass(final String lclass)
Utility method to dynamically load classes
Object loadedClass = null;
Class handlerClass = null;
try {
    handlerClass = Class.forName(lclass);
} catch (final NoClassDefFoundError e) {
    throw new RuntimeException("Cannot find class : " + lclass, e);
} catch (final ClassNotFoundException e) {
    throw new RuntimeException("Cannot find class : " + lclass, e);
...
ClassloadClass(final String packageName, final String className)
Rather than using the Class.forName mechanism first, this uses Thread.getContextClassLoader instead.
return loadClass(toQualifiedClassName(packageName, className));
ClassloadClass(String className)
load Class
Class<?> clazz = null;
try {
    clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
} catch (ClassNotFoundException e) {
    throw new ClassNotFoundException();
} catch (Exception e) {
    throw new Exception(e);
if (clazz == null) {
    clazz = Class.forName(className);
return clazz;