Java Utililty Methods Class forName

List of utility methods to do Class forName

Description

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

Method

ObjectforName(Class classType, String className)
Creates a new instance of an object given it's class name.
Class c = null;
try {
    c = Class.forName(className);
} catch (Exception ex) {
    throw new Exception("Can't find class called: " + className);
if (!classType.isAssignableFrom(c)) {
    throw new Exception(classType.getName() + " is not assignable from " + className);
...
ClassforName(final Class caller, final String className)
Attempt to load the named class.
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
    try {
        return contextClassLoader.loadClass(className);
    } catch (final ClassNotFoundException cnfe) {
final ClassLoader callerClassLoader = caller.getClassLoader();
...
ClassforName(final String className)
Returns the Class object associated with the class or interface with the given string name.
try {
    return Class.forName(className);
} catch (final ClassNotFoundException e) {
    return null;
ClassforName(final String className, final Class caller)
Load the specified class.
final ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
if (threadClassLoader != null) {
    try {
        return Class.forName(className, true, threadClassLoader);
    } catch (final ClassNotFoundException cnfe) {
        if (cnfe.getException() != null) {
            throw cnfe;
final ClassLoader classLoader = caller.getClassLoader();
if (classLoader != null) {
    try {
        return Class.forName(className, true, classLoader);
    } catch (final ClassNotFoundException cnfe) {
        if (cnfe.getException() != null) {
            throw cnfe;
return Class.forName(className, true, ClassLoader.getSystemClassLoader());
ClassforName(String className)
for Name
return (Class<T>) (classLoader == null ? Class.forName(className)
        : Class.forName(className, true, classLoader));
ClassforName(String className)
Gets the Class for the className in a way that works well for extensions.
return Thread.currentThread().getContextClassLoader().loadClass(className);
ClassforName(String className)
for Name
try {
    return (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
    throw new RuntimeException(className, e);
ClassforName(String className)
for Name
return forName(className, Thread.currentThread().getContextClassLoader());
ClassforName(String className)
Safe Class.forName.
Class theClass = null;
try {
    theClass = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
    theClass = Class.forName(className);
return theClass;
ClassforName(String className)
for Name
try {
    return Class.forName(className);
} catch (ClassNotFoundException e) {
    e.printStackTrace();
    return null;