Java class loader 博客分类: JDK JavaJVMUPCC++
程序员文章站
2024-02-27 22:16:57
...
- 1. Explain Java class loader?
Class loader are hierarchical and use a delegation model when loading a class. Here is the “Typical Default Class Loader Hierarchy”.
Class Loader | Explanation | ||
Bootstrap | Load the core java classes(e.g. java.*, javax.*, etc) into JVM | ||
Extension | Load classes from the JRE’s extension directories. | ||
System | Load classes from the system class path. |
Class loaders request their parent to load the class first before attempting to load it themselves. When a class loader loads a class, the child class loaders in the hierarchy will never reload the class again. Hence uniqueness is maintained. Classes loaded by a child class loader have visibility into classes loaded by its parents up the hierarchy but the reverse is not true as explained in the above diagram.
Note: Two objects loaded by different classes loaders are never equal even if they carry the same values, which mean a class is uniquely identified in the context of the associated class loader.
- 2.Explain static & dynamic class loading?
Static class loading knows the class at compile time.
Dynamic class loading knows the class at run time. That lets us maybe change classes through configuration or lets users introduce new classes that we never know about by passing a new string.
// static class loading at compile time Car c = new Car(); // dynamic class loading at run time. Class vehicleClass = Class.forName(myClassName) ;
Dynamic class loading methods:
The forName(..) method in class - Class. The findSystemClass(..) method in class - ClassLoader. The loadClass(..) method in class - ClassLoader.
下一篇: Java设计模式之模版方法模式简介
推荐阅读
-
Java class loader 博客分类: JDK JavaJVMUPCC++
-
Java十年 十大人物 写在2005 博客分类: Java Java大众硬件SUN大众软件JDK
-
Java十年 十大人物 写在2005 博客分类: Java Java大众硬件SUN大众软件JDK
-
java Class getDeclaredFields() 与getFields()的区别 博客分类: Java WebJava getDeclaredFieldsgetFields私有字段Class反射
-
JAX-WS 2.2 API与Java SE 6冲突的问题 博客分类: JAX-WS JAX-WS与JDK6冲突JAX-WSjavax.xml.ws.WebFault.messageName
-
JAX-WS 2.2 API与Java SE 6冲突的问题 博客分类: JAX-WS JAX-WS与JDK6冲突JAX-WSjavax.xml.ws.WebFault.messageName
-
Class.forName 返回 String[].class 博客分类: java java
-
Class.forName 返回 String[].class 博客分类: java java
-
JDK J2SE Java SE的发展历程 博客分类: java语言相关 JavaJ2SEJDK
-
JDK J2SE Java SE的发展历程 博客分类: java语言相关 JavaJ2SEJDK