• As mentioned in the previous article, when each loader gets to load a class for the second time, it will look for whether the class exists within its own visual range. If it exists, it will load it, and if it doesn’t, it will pass it on to its own children.
  • BootstrapClassLoader does not have a father, so it is the first time to get it.

So what is the scope of the instance, or the scope of the first search, of the three classloaders?

The following examples show how specific classes work so you don’t have to be confused

4.1 Test Code

package com.yuhl.classload; /** * @author yuhl * @date 2020/12/22 13:17 * @className getClassLoaderDetail * @description public class getClassLoaderDetail { public static void main(String[] args) { String pathBoot = System.getProperty("sun.boot.class.path"); System. The out. Println (" BootStrapClassLoader instance range start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); System.out.println(pathBoot.replaceAll(";" , System.lineSeparator())); System. Out. Println (" BootStrapClassLoader instance scope end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); System. The out. Println (" ExtClassLoader instance range start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); String pathExt = System.getProperty("java.ext.dirs"); System.out.println(pathExt.replaceAll(";" , System.lineSeparator())); System. Out. Println (" ExtClassLoader instance scope end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); System. The out. Println (" AppClassLoader instance range start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); String pathApp = System.getProperty("java.class.path"); System.out.println(pathApp.replaceAll(";" , System.lineSeparator())); System. Out. Println (" AppClassLoader instance scope end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "); }}Copy the code

4.2 Test Results

BootStrapClassLoader instance scope start -------------------- C:\Program Files\Java\jdk1.8.0_201\jre\lib\resources.jar C:\Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ rt jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ sunrsasign jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ jsse jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ jce jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ charsets jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ JFR jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ classes BootStrapClassLoader instance scope end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ExtClassLoader instance range start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext C: \ WINDOWS \ Sun \ Java \ lib \ ext ExtClassLoader instance scope end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- AppClassLoader instance range start -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ charsets jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ deploy the jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ access - bridge - 64. The jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ cldrdata jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ DNSNS jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ jaccess jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ JFXRT jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ localedata jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ nashorn jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ sunec jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ sunjce_provider jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ sunmscapi jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ sunpkcs11 jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ ext \ zipfs jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ javaws jar Jar C:\Program Files\Java\jdk1.8.0_201\jre\lib\jce.jar C:\Program Files\Java\jdk1.8.0_201\jre\lib\jfr.jar C:\Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ JFXSWT jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ jsse jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ management - agent jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ plugin jar C: \ \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ resources jar C: \ Program Files \ Java \ jdk1.8.0 _201 \ jre \ lib \ rt jar D:\AA\JVM\out\production\Jvm2020 C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar AppClassLoader instance range End -------------------- Process Finished with exit code 0Copy the code
  1. When it needs to load a class, it will scan its own sphere of influence, if it is loaded, if it is not given to the child.
  2. It is important to note that the class must not be in memory before it is loaded, and it will not be reloaded if it is already in memory.

The hard work of self-discipline is better than the bitter fruit of regret. Focus on Java backend technology and solutions, good at summing up, sharing! The hard work of self-discipline is better than the bitter fruit of regret. Focus on Java backend technology and solutions, good at summing up, sharing! The hard work of self-discipline is better than the bitter fruit of regret. Focus on Java backend technology and solutions, good at summing up, sharing!