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.