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

ClassclassForName(final String className)
class For Name
return classForName(className, false);
ClassclassForName(final String clsName)
class For Name
if ("int".equals(clsName))
    return int.class;
if ("boolean".equals(clsName))
    return boolean.class;
return Class.forName(clsName);
ClassclassForName(final String theClassName)
Returns the class for a name.
return Class.forName(theClassName);
ClassclassForName(String className)
Class.forName() cannot instantiate Class objects for primitive data types like `int'.
if (className.equals("byte")) {
    return byte.class;
} else if (className.equals("short")) {
    return short.class;
} else if (className.equals("int")) {
    return int.class;
} else if (className.equals("long")) {
    return long.class;
...
ClassclassForName(String className)
class For Name
try {
    return Class.forName(className, false, Thread.currentThread().getContextClassLoader());
} catch (Exception ignore) {
    try {
        return Class.forName(className);
    } catch (Exception e) {
        throw new IllegalArgumentException("classForName(" + className + ")  with ex:", e);
ClassclassForName(String className)
Invokes Class#forName(String) for the given type name but does not throw any Exception .
Class<T> retval = null;
try {
    Class<?> forName = Class.forName(className);
    retval = (Class<T>) forName;
} catch (Exception e) {
return retval;
ClassclassForName(String className)
class For Name
Thread t = Thread.currentThread();
ClassLoader cl = t.getContextClassLoader();
Class<?> cls = cl.loadClass(className);
return cls;
ClassclassForName(String className)
Tries to load the class with the current context class loader, and only then with the current defining class loader.
try {
    return Class.forName(className, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
    ; 
} catch (SecurityException e) {
    ; 
return Class.forName(className);
...
ClassclassForName(String className)
Method classForName
try {
    return Class.forName(className);
} catch (ClassNotFoundException e) {
    return null;
ClassclassForName(String className)
class For Name
Class c = __primitiveTypes.get(className);
if (null != c)
    return c;
try {
    return (Class<T>) Class.forName(className);
} catch (ClassNotFoundException e) {
    throw new Exception(e);