Class Loader


  • public final class Loader
    extends Object
    Load resources (or images) from various sources.

    • Method Detail

      • getResource

        public static URL getResource​(String resource)
        This method will search for resource in different places. The search order is as follows:

        1. Search for resource using the thread context class loader under Java2.

        2. Try one last time with ClassLoader.getSystemResource(resource), that is is using the system class loader in JDK 1.2 and virtual machine's built-in class loader in JDK 1.1.

        Parameters:
        resource -
        Returns:
        the url to the resource or null if not found
      • getResource

        public static URL getResource​(ClassLoader loader,
                                      String resource)
        This method will search for resource in different places. The search order is as follows:

        1. Search for resource using the supplied class loader. If that fails, search for resource using the thread context class loader.

        2. Try one last time with ClassLoader.getSystemResource(resource), that is is using the system class loader in JDK 1.2 and virtual machine's built-in class loader in JDK 1.1.

        Parameters:
        resource -
        Returns:
        the url to the resource or null if not found
      • getResourceAsStream

        public static InputStream getResourceAsStream​(String resourceName)
        This is a convenience method to load a resource as a stream.

        The algorithm used to find the resource is given in getResource()

        Parameters:
        resourceName - The name of the resource to load
      • getClassLoader

        public static ClassLoader getClassLoader​(Class<?> clazz)
        Get the class loader of the class argument

        Returns:
        the class loader of the argument
      • loadClass

        public static Class<?> loadClass​(String clazz)
                                  throws ClassNotFoundException
        If running under JDK 1.2 load the specified class using the Thread contextClassLoader if that fails try Class.forname.

        Parameters:
        clazz -
        Returns:
        the class
        Throws:
        ClassNotFoundException
      • loadClass

        public static <T> Class<? extends T> loadClass​(String clazz,
                                                       Class<T> type)
                                                throws ClassNotFoundException
        If running under JDK 1.2 load the specified class using the Thread contextClassLoader if that fails try Class.forname.

        Parameters:
        clazz -
        type - Type to cast it to
        Returns:
        the class
        Throws:
        ClassNotFoundException