I have read that there are different class loaders in java, the one is primordial class loader and there are custom class loaders as well, so I want to understand why primordial class loader is not able to serve all classes in java? Why is there need for other class loaders?
The main need is isolation.
Let's say there are 3 applets on a page, each using a different version of the library foo.jar. You want each of those applets to run with its own version of the library, and to make sure it doesn't walk on another applet's toes. This is accomplished thanks to different class loaders.
The same goes for web applications deployed on a single container. The Java container is started without any app deployed, and then an app is deployed. You want the container to be able to load classes from a location it didn't even know about when it was started. And if another webapp is deployed, you want this other app to have its own classes and libraries, that are different and isolated from the classes and libraries of the first app.
Another need is to be able to load classes from various locations: the file system, but also URLs, databases, or whatever.
There are many practical situations in which you want features beyond what the system class loader provides:
The final point is particularly powerful (and has been the main reason for why I have used them). Since Java bytecode is universal across platforms, you can use it to instrument classes on any system: measure which methods are called, suppress security-critical calls, divert System.out accesses to your own custom logging routines, or perform advanced dynamic bug-testing routines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With