What is a Java ClassLoader?

前端 未结 7 1968
眼角桃花
眼角桃花 2020-11-29 14:24

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 a

相关标签:
7条回答
  • 2020-11-29 15:10

    When you asking why does the ClassLoader class exist, the reason is pretty simple - it's the class responsible for finding and loading class files at run time.

    Let's elaborate it.

    In JVM, every Class is loaded by some instance of java.lang.ClassLoader. Whenever a new JVM is started by you usual Java program launching java <classname> command, the first step is to load all the key classes in memory required for proper working like java.lang.Object and other runtime classes (rt.jar).

    Now, there are actually 3 parts to ClassLoader:

    • The BootstrapClassLoader is responsible for making these classes available i.e. loading these classes in memory.

    • The next task is to load any external libraries / JARs into the memory for proper working of the application. The ExtClassLoader is responsible for this task. This class loader is responsible for loading all the .jar files mentioned in java.ext.dirs path.

    • The third and the main important class loader is the AppClassLoader. The application class loader is responsible for loading of the class files mentioned in the java.class.path system property.

    It's also important to note that the default ClassLoader implementations could be overridden enabling you to customize the JVM in useful and interesting ways, allowing you to completely redefine how class files are brought into the system.

    Check it out to learn more about Java Class Loader.

    0 讨论(0)
提交回复
热议问题