类生命周期:
类加载器:
查看类对应的加载器:
package com.study.classLoader;
public class ClassLoaderView {
public static void main(String[] args) throws Exception {
// 加载核心类库的 BootStrap ClassLoader
System.out.println("核心类库加载器:"
+ ClassLoaderView.class.getClassLoader().loadClass("java.lang.Object").getClassLoader());
// 加载拓展库的 Extension ClassLoader
System.out.println("拓展类库加载器:" + ClassLoaderView.class.getClassLoader()
.loadClass("com.sun.nio.zipfs.ZipCoder").getClassLoader());
// 加载应用程序的
System.out.println("应用程序库加载器:" + ClassLoaderView.class.getClassLoader());
// 双亲委派模型 Parents Delegation Model
System.out.println("应用程序库加载器的父类:" + ClassLoaderView.class.getClassLoader().getParent());
System.out.println(
"应用程序库加载器的父类的父类:" + ClassLoaderView.class.getClassLoader().getParent().getParent());
}
}
JVM如何直到我们的类在何方:
类不会重复加载:
类的卸载:
双亲委派模型: