What is a Java ClassLoader?

前端 未结 7 2004
眼角桃花
眼角桃花 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:02

    Class loaders are hierarchical. Classes are introduced to the JVM as they are referenced by name in a class that is already running in the JVM.

    How the very first class loaded?
    The very first class is loaded with the help of static main() method declared in your class. All the subsequently loaded classes are loaded by the classes, which are already loaded and running.

    A class loader creates a namespace. All JVM include at least one class loader that is embedded within the JVM called the primordial (or bootstrap) class loader. That is one thing, and we will look at non-primordial class loaders. The JVM has hooks in it to allow user defined class loaders to be used in place of primordial class loader. Here are the class loaders created by the JVM.

    Bootstrap (primordial) This class loader not re loadable. Loads JDK internal classes, java.* packages ( typically loads rt.jar and i18n.jar). Extesions This class loader not re loadable. Loads jar files from JDK extensions directory (usually lib/ext of JRE). System This class loader not re loadable. Loads classes from system class path.

    http://www.sbalasani.com/2015/01/java-class-loaders.html

提交回复
热议问题