I want to understand how Java class loaders work. I have read several articles, but there are some things that are still not clear.
As I understand it, the first class loader is the Bootstrap (BCL) class loader. Is the JVM loading?
BCL then downloads the rt.jar library and Extension Class Loader (ECL).
In turn, the ECL loads the extensions and application class loader (ACL). The ACL is responsible for loading the entire user class from the class path.
Is this description correct?
There are a few questions:
- Only one instance of each class loader exists in memory. (BCL, ECL, ACL)?
- I examined the principle of delegation, but for me it is a bit unclear. How this works, let's say we need to load MyClass. The first jvm gives this ACL class name, and it is not clear to me, the ACL looks at the class path, and if there is no such class delegate, this work is to the parent OR it delegates this work to the parents right after the call, I mean the JVM gives the ACL class name, he does not look for this class, which gives its ECL, this CL, in turn, also does not do any work and does not pass it to BCL, and only if BCL cannot find this class, it returns it to the lower level (ECL) .. .. and so on. What is the right chain?
- When we create a custom class loader, what is its parent class? ClassLoader app? Can we indicate, for example, ECL. Since the hierarchy of class loaders is not an inheritance, we specify parent in the constructor. Can we get an instance of the ECL class classloader to specify it in our user CL as the parent in the constructor.
- Why don't classes, such as String, Object, etc., return a ClassLoadder?
source share