Java class loading and custom class loader
Class loading
All class loaders are subclasses of classloader.
Class loaders always start with Class runs in the directory.
There are several ways to read files in the root directory of classpath:
1 in the Java project, you can obtain the files under classspath in the following ways:
In tomcat, Tomcat declares two class loaders:
Standardclassloaderc loading Tomcat / lib / * jar - serlvetapi. jar
Webappclassloader / load Tomcat / webapps / project / Web inf / lib / * jar && web-inf/classes/*. class
In any project, the loader that gets the class should use the following methods:
Someclass (you wrote it) class. getClassLoader(). getResource ; Get the class loader for this class
In the Java project: appclassloader
In a web project: webappclassloader
Test parent loader:
Results of operation:
Custom class loader
Class A is loaded by which class loader JDK reads the bytecode of class A.
Whether a class with the same name can be converted to each other depends on whether it is in the same class loader.
Test class custom class loader
The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!