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

Stack>getClassHierarchyFrom(Class clazz)
get Class Hierarchy From
Stack<Class<?>> result = new Stack<Class<?>>();
Class<?> target = clazz;
while (target.getSuperclass() != null) {
    result.add(target);
    target = target.getSuperclass();
for (Class<?> iface : clazz.getInterfaces()) {
    result.add(iface);
...
ClassgetClassHierarchyLeaf(Collection> classes)
get Class Hierarchy Leaf
Class<?> hierarchyLeaf = null;
for (Class<?> clazz : classes) {
    if (hierarchyLeaf == null) {
        hierarchyLeaf = clazz;
    } else if (clazz != null) {
        if (hierarchyLeaf.isAssignableFrom(clazz)) {
            hierarchyLeaf = clazz;
return hierarchyLeaf;
StringgetClassName(String logicalName, String trailingName)
Returns the class name for the given logical name and trailing name.
if (isBlank(logicalName)) {
    throw new IllegalArgumentException("Argument [logicalName] cannot be null or blank");
String className = logicalName.substring(0, 1).toUpperCase(Locale.ENGLISH) + logicalName.substring(1);
if (trailingName != null) {
    className = className + trailingName;
return className;
...
StringgetClassNameRepresentation(String name)
Returns the class name representation of the given name
String className;
StringBuffer buf = new StringBuffer();
if (name != null && name.length() > 0) {
    String[] tokens = name.split("[^\\w\\d]");
    for (int i = 0; i < tokens.length; i++) {
        String token = tokens[i].trim();
        buf.append(token.substring(0, 1).toUpperCase(Locale.ENGLISH)).append(token.substring(1));
className = buf.toString();
return className;
ListgetClassNames(StackTraceElement[] currentStack)
get Class Names
ArrayList<String> list = new ArrayList<String>();
for (StackTraceElement element : currentStack) {
    list.add(element.getClassName());
return list;
ClassloadClass(Class context, String... names)
Attempt to load a class for one ore more supplied class names, returning the first one found.
for (String name : names) {
    try {
        Class<?> clazz = Class.forName(name, true, context.getClassLoader());
        return clazz;
    } catch (ClassNotFoundException cnfe) {
return null;
...
ClassloadClass(Class sourceClass, final String className)
load Class
try {
    ClassLoader loader = sourceClass.getClassLoader();
    if (loader != null) {
        return loader.loadClass(className);
    } else {
        return (Class) Class.forName(className);
} catch (ClassNotFoundException e) {
...
ClassloadClass(Class base, String name)
load Class
return loadClass(base.getClassLoader(), name);
voidloadClass(Class clazz)
load Class
loadClass(clazz.getName());
ClassloadClass(Class contextClass, String className)
Loads a class using the class loader.
Class<?> clazz = null;
if (contextClass.getClassLoader() != null) {
    clazz = silentLoadClass(className, contextClass.getClassLoader());
if (clazz == null && Thread.currentThread().getContextClassLoader() != null) {
    clazz = silentLoadClass(className, Thread.currentThread().getContextClassLoader());
return clazz;
...