How to Perform Dynamic Loading
Two ways:
- forName():
- static method in java.lang.Class,
- simple to use.
- loadClass():
- method in java.lang.ClassLoader,
- first create a class loader, then call loadClass(),
- you can create as many as you like,
- more powerful.
Use class loaders if :
- You need name spaces,
- You need to customise the load process,
- You need to dynamically replace existing class definitions in a running java application.