Java development technology class loading and understanding of ClassLoader
Understanding: the loading process of the class
When a program passively applies a class, if the class has not been loaded into memory, the system will initialize the class through the following three steps.
Understanding: ClassLoader
The class loader is used to load classes into memory. The JVM standard defines two types of class loaders: bootstrap and user-defined class loader. The JVM will generate an initialization loader hierarchy composed of 3 class loaders at runtime, as shown in the following figure:
• //1.Get a fragmentary class loader
• ClassLoader classloader = ClassLoader.getSystemClassLoader();
• System.out.println(classloader);
• //2.Get the parent class loader of the fragmented class loader, that is, expand the class loader
• classloader = classloader.getParent();
• System.out.println(classloader);
• //3.Get the parent class loader of the expanded class loader, that is, the grooming class loader
• classloader = classloader.getParent();
• System.out.println(classloader);
• //4.Which class loader will load the class after the test
• classloader =
• Class.forName("exer2.ClassloaderDemo").getClassLoader();
• System.out.println(classloader);
• //5.Test which class loader loads the Object class provided by the JDK
• classloader =
• Class.forName("java.lang.Object").getClassLoader();
• System.out.println(classloader);
• //*6.A secondary method for the class loader: getResourceAsStream(String str): Get the output stream of the specified file under the class door
• InputStream in = null;
• in = this.getClass().getClassLoader().getResourceAsStream(“exer2\test.properties”);
• System.out.println(in);
To understand more java development technology, send off and pay attention to the editor's java training column!
0 Comments