https://www.bilibili.com/video/BV1Qv411V7qw

JVM类加载原理

https://cdn.nlark.com/yuque/0/2021/png/576791/1632616092895-29e74a9c-4308-4ca5-967e-e212dcd80dca.png#averageHue=%23222b56&clientId=u518c94c0-2a7f-4&from=paste&height=448&id=ue2a5b693&originHeight=896&originWidth=1800&originalType=binary&ratio=1&rotation=0&showTitle=false&size=821144&status=done&style=none&taskId=u4cdb4976-b787-445c-8415-a6e5d1cb883&title=&width=900

https://cdn.nlark.com/yuque/0/2021/png/576791/1632615766879-c1bb3488-d6bf-4bb1-86e1-9700bf2a4219.png#averageHue=%23202954&clientId=u88716a60-502f-4&from=paste&height=436&id=u2e64764c&originHeight=872&originWidth=1820&originalType=binary&ratio=1&rotation=0&showTitle=false&size=694199&status=done&style=none&taskId=u4e6fd3ab-ce8e-43c9-bb14-c039185f15c&title=&width=910

https://cdn.nlark.com/yuque/0/2021/png/576791/1632283368862-f2d4e945-37d0-42d1-a597-aa85d75a31f9.png#averageHue=%23262d61&clientId=u2d38512c-079a-4&from=paste&height=455&id=u8c086314&originHeight=910&originWidth=1654&originalType=binary&ratio=1&rotation=0&showTitle=false&size=854243&status=done&style=none&taskId=ubfee2c1a-b477-432b-9945-a698949f943&title=&width=827

  1. 使用 new 关键字实例化对象
  2. 读取或者设置一个类的静态变量的时候
  3. 调用类对应的静态方法的时候
  4. 对类进行反射调用的时候
  5. 初始化子类时,父类会先被初始化
  6. 虚拟机启动时,定义了 main() 方法的那个类先初始化

https://cdn.nlark.com/yuque/0/2021/png/576791/1632285131924-85ee4d98-1ff2-42b3-a60c-f9504df16074.png#averageHue=%233a4a7f&clientId=ub97c954b-e84d-4&from=paste&height=467&id=u8269ac03&originHeight=934&originWidth=1682&originalType=binary&ratio=1&rotation=0&showTitle=false&size=799360&status=done&style=none&taskId=u44596a3c-4236-451b-a906-101980084f8&title=&width=841

注意:类加载器的体系并不是“继承”体系,而是委派体系

https://cdn.nlark.com/yuque/0/2021/png/576791/1632285394053-ba73ce29-4f08-4a31-9a5b-a59bcbaa157e.png#averageHue=%23303768&clientId=ub97c954b-e84d-4&from=paste&height=473&id=u99993ddd&originHeight=946&originWidth=1734&originalType=binary&ratio=1&rotation=0&showTitle=false&size=1381616&status=done&style=none&taskId=u633a964b-ab93-46b3-b443-faf8d6f6d10&title=&width=867

它用来加载 Java 的核心类库(Java_HOME/jre/lib/rt.jar、reource.jar 或 sun.boot.class.path 路径下的内容)、用于提供JVM自身需要的类。

从 java.ext.dirs 系统属性所指定的目录中加载类库,或从JDK的安装目录的jre/lib/ext 子目录(扩展目录)下加载类库。如果用户创建的 JAR 放在此目录下,也会自动由扩展类加载器加载