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

ClassforName(String name)
for Name
checkPackageAccess(name);
return Class.forName(name);
ClassforName(String name)
Like Class.forName, but works for primitive types too
if (name.equals("int"))
    return int.class;
if (name.equals("double"))
    return double.class;
if (name.equals("boolean"))
    return boolean.class;
if (name.equals("long"))
    return long.class;
...
ClassforName(String name)
for Name
Class<?> clazz = Class.forName(name, true, Thread.currentThread().getContextClassLoader());
return clazz;
ClassforName(String name)
A utility for using the current class loader (rather than the system class loader) when instantiating a new class.
ClassLoader ctxLoader = null;
try {
    ctxLoader = Thread.currentThread().getContextClassLoader();
    return Class.forName(name, true, ctxLoader);
} catch (ClassNotFoundException ex) {
} catch (SecurityException ex) {
return Class.forName(name);
...
ClassforName(String name)
for Name
switch (name) {
case "byte":
    return byte.class;
case "short":
    return short.class;
case "int":
    return int.class;
case "long":
...
ClassforName(String name, Class caller)
for Name
ClassLoader threadClassLoader = Thread.currentThread().getContextClassLoader();
if (threadClassLoader != null) {
    try {
        return Class.forName(name, true, threadClassLoader);
    } catch (ClassNotFoundException cnfe) {
        if (cnfe.getException() != null) {
            throw cnfe;
ClassLoader callerClassLoader = caller.getClassLoader();
if (callerClassLoader != null) {
    try {
        return Class.forName(name, true, callerClassLoader);
    } catch (final ClassNotFoundException cnfe) {
        if (cnfe.getException() != null) {
            throw cnfe;
return Class.forName(name, true, ClassLoader.getSystemClassLoader());
ClassforName(String origClassName)
Returns the class object.
try {
    return Class.forName(origClassName);
} catch (Throwable t) {
    throw new RuntimeException("Problem loading class: " + origClassName, t);
ClassforName(String type, Class cast)
for Name
return (Class<T>) Thread.currentThread().getContextClassLoader().loadClass(type);
Class[]forName(String[] classNames)
Returns an array of Class objects associated with the class or interface with the given names.
if (classNames == null)
    return null;
Class[] classes = new Class[classNames.length];
for (int i = 0; i < classNames.length; i++) {
    if (classNames[i] != null) {
        classes[i] = Class.forName(classNames[i]);
return classes;
ClassforNameElseNull(final String fullName)
for Name Else Null
if (fullName == null) {
    return null;
try {
    return Thread.currentThread().getContextClassLoader().loadClass(fullName);
} catch (final ClassNotFoundException e) {
    return null;