The first class loader of the Java virtual machine is Bootstrap. This loader is nested in the Java virtual machine kernel. It is a binary code (not bytecode) written in C++.
Using the delegation mechanism, the parent class will be searched recursively, that is, it is preferred to use Bootstrap to try to load, and if it cannot be found, go down. Prevent two copies of bytecode from appearing in memory.
You misunderstood classes and classloader.
When a class is recorded, first use the class loader of the current thread to load the first class in the thread. For example, this class is ClassA and the class loader is ClassLoaderA.
If ClassA references ClassB, the system will use ClassLoaderA to load ClassB.
Now there are 2 classes (Simplified version, actually more than 2 classes).
We consider a situation where ClassX and ClassY have been loaded in memory, and they both refer to ClassZ. So who loads ClassZ?
Obviously according to the loading steps described above, 2 copies of ClassZ will appear: ClassX is loaded once, and ClassY is loaded again. Because ClassY doesn't know that ClassX has been loaded.
How to solve this problem is to search recursively to the parent class.
The specific steps are to first search from BootstrapClassLoader. If BootstrapClassLoader has loaded this class, return it. If BootstrapClassLoader has not loaded this class, continue to search until it finds this class. If the class loader of this thread is not found, it means that the class has not been loaded, and the loader of the current thread is used to load it. You can use getContextClassLoader() to get the class loader of the current thread.
There are two types of class loaders in Java: system class loaders and user-defined class loaders.
The system class loader will have loading path restrictions. For example, Bootstrap Class Loader在JDK1.6下,通过 System.getProperty("sun.boot.class.path")can get the class loading path
The classes in these paths are loaded by the next-level class loader in the corresponding path if the class file cannot be found. Bootstrap负责,其它路径下的class的递归到Bootstrap
The first class loader of the Java virtual machine is Bootstrap. This loader is nested in the Java virtual machine kernel. It is a binary code (not bytecode) written in C++.
Using the delegation mechanism, the parent class will be searched recursively, that is, it is preferred to use Bootstrap to try to load, and if it cannot be found, go down. Prevent two copies of bytecode from appearing in memory.
You misunderstood classes and classloader.
When a class is recorded, first use the class loader of the current thread to load the first class in the thread. For example, this class is ClassA and the class loader is ClassLoaderA.
If ClassA references ClassB, the system will use ClassLoaderA to load ClassB.
Now there are 2 classes (Simplified version, actually more than 2 classes).
We consider a situation where ClassX and ClassY have been loaded in memory, and they both refer to ClassZ. So who loads ClassZ?
Obviously according to the loading steps described above, 2 copies of ClassZ will appear: ClassX is loaded once, and ClassY is loaded again. Because ClassY doesn't know that ClassX has been loaded.
How to solve this problem is to search recursively to the parent class.
The specific steps are to first search from BootstrapClassLoader. If BootstrapClassLoader has loaded this class, return it. If BootstrapClassLoader has not loaded this class, continue to search until it finds this class. If the class loader of this thread is not found, it means that the class has not been loaded, and the loader of the current thread is used to load it. You can use
getContextClassLoader()
to get the class loader of the current thread.There are two types of class loaders in Java: system class loaders and user-defined class loaders.
The system class loader will have loading path restrictions. For example,
Bootstrap Class Loader
在JDK1.6下,通过System.getProperty("sun.boot.class.path")
can get the class loading pathThe classes in these paths are loaded by the next-level class loader in the corresponding path if the class file cannot be found.
Bootstrap
负责,其它路径下的class的递归到Bootstrap
What the person above said is right, I suggest you read JVM related books to learn more about it.