Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

In a few simple sentences, what is a Java ClassLoader, when is it used and why?

OK, I read a wiki article. ClassLoader loads classes. OK. So if I include jar files and import, a ClassLoader does the job.

Why should I bother with this ClassLoader? I've never used it and didn't know it existed.

The question is, why does the ClassLoader class exist? And also, how do you use it in practice? (Cases exist, I know.)

1 Answer

0 votes
by (46k points)

Most Java developers will never need to explicitly use class loaders (except to load resources so that it still works when they're bundled in JARs), let alone write their own.

ClassLoaders are used in large systems and server applications to do things like:

  • Modularize a system and load, unload and update modules at runtime
  • Use different versions of an API library (e.g. an XML parser) in parallel
  • Isolate different applications running within the same JVM (ensuring they don't interfere with each other, e.g. through static variables)

Browse Categories

...