Class ClassUtil

java.lang.Object
fc.util.ClassUtil

public final class ClassUtil extends Object
  • Constructor Details

  • Method Details

    • getClassLoaderInfo

      public static String getClassLoaderInfo(Object obj)
      Returns classloader information about the specified object
    • getClassLoaderInfo

      public static String getClassLoaderInfo(Class c)
      Returns classloader information about the specified class.
    • getClassName

      public static String getClassName()
      This method can be called from either a instance or a static method. Returns the class name in which the calling method was declared.

      Important note: The returned class name is wherever the method is invoked from. For instance methods, it is the runtime virtual class. For static it is the class name where the method was declared (static methods are not virtual and bound at compile time). For example:

      
      Class A 
        { 
        static void foo(...) {
          System.out.print(ClassUtil.getClassName());
          }
        }
      
      public class B extends A
        {
        }
      
      % java B  
      will print:
        A (NOT B)
      
    • getMainClassName

      public static String getMainClassName()
      Returns the fully qualified name of the class that contained the main() method used to invoke the application. Note: this method must be called from the same thread (the "main" thread) that started the application. Newly started threads that call this method will instead obtain the class name containing that thread's run() method.
    • isSystemClass

      public static boolean isSystemClass(Class c)
      Returns true is the specified class is a system/JDK class. This method should work, but given the vagaries of classes, classloaders, etc, there isn't any guarantee.
      Parameters:
      caller - the object or Class Class corresponding to that object
    • getLoadedFromPath

      public static String getLoadedFromPath(Class caller)
      Returns either the directory or jar file from which the specified class was loaded

      This does not work for system/bootstrap classes and will return null for system classes.

      Parameters:
      caller - the Class class to be looked up
    • getParentDir

      public static String getParentDir(Class caller)
      Returns the right most parent directory from which the actual class was loaded. This is the leaf directory where the actual class is located.

      For classes loaded from other sources (jar, etc), the return value will be null.

      This also does not work for system/bootstrap classes (they are typically loaded from jars) either (those will return null also)

      Parameters:
      caller - the Class class to be looked up
    • getParentDirAsURL

      public static URL getParentDirAsURL(Class caller)
      Returns the parent directory from which the actual class was loaded. This is the leaf directory where the actual class is located.

      For classes loaded from other sources (jar, etc), a URL will be returned. For jar URL's, the URL.getProtocol() method returns "jar", so that can be useful for further processing as needed.

      Parameters:
      caller - the Class class to be looked up
    • main

      public static void main(String[] args)