Instantiating and using a classloader

suggest change

This basic example shows how an application can instantiate a classloader and use it to dynamically load a class.

URL[] urls = new URL[] {new URL("file:/home/me/extras.jar")};
Classloader loader = new URLClassLoader(urls);
Class<?> myObjectClass = loader.findClass("com.example.MyObject");

The classloader created in this example will have the default classloader as its parent, and will first try to find any class in the parent classloader before looking in “extra.jar”. If the requested class has already been loaded, the findClass call will return the reference to the previously loaded class.

The findClass call can fail in a variety of ways. The most common are:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


ClasssLoader:
* Instantiating and using a classloader

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
110 ClasssLoader
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap