concept ClassLoader in category java

appears as: ClassLoader
The Java Module System

This is an excerpt from Manning's book The Java Module System.

To load a resource, you call getResource or getResourceAsStream on either Class or ClassLoader. Conceptually, these methods are almost identical: you hand them the name of a resource file as a String, and they return a URL or InputStream if they find it; otherwise you get null back. To not make things more complicated than they have to be, we’ll stick to using Class::getResource.

You can access the application class loader by calling ClassLoader.getSystemClassLoader() or by calling getClass().getClassLoader() on an instance of one of your classes. Both methods promise to give you an instance of type ClassLoader. On Java 8 and before, the application class loader is a URLClassLoader, a subtype of ClassLoader; and because URLClassLoader offers some methods that can come in handy, it’s common to cast the instance to it. You can see an example of that in listing 6.1.