0

It is being said that

The bootstrap class loader loads the core Java libraries located in the <JAVA_HOME>/jre/lib directory.

And

The extensions class loader loads the code in the extensions directories <JAVA_HOME>/jre/lib/ext,or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.

Now if my main program is

public class TestSt {

    public static void main(String[] args) {

        System.out.println(String.class.getClassLoader());
        System.out.println(Student.class.getClassLoader());
        System.out.println(TestSt.class.getClassLoader());
    }

}

The output is

null
sun.misc.Launcher$AppClassLoader@73d16e93 sun.misc.Launcher$AppClassLoader@73d16e93

Which is fine.

Now if I put Student Jar file in /jre/lib/ext The output is

null
sun.misc.Launcher$ExtClassLoader@3d4eac69 sun.misc.Launcher$AppClassLoader@2a139a55

Which is also fine.

But I couldnot understand that if I place student jar file in
/jre/lib directory . Why the output is giving as

null
sun.misc.Launcher$AppClassLoader@73d16e93 sun.misc.Launcher$AppClassLoader@73d16e93

I was thinking that Student Class in this case should be loaded from bootstrap class loader, Why it is loaded by application class loader. I think I am missing something. Please let me know where I am wrong.

2
  • Are you asking why the ExtClassLoader is used to load classes in the ext directory? Apr 17, 2016 at 19:31
  • No, I am asking why bootstrap class loader does not load classes placed inside jre/lib/ directory
    – Roshan
    Apr 17, 2016 at 19:32

1 Answer 1

2

There is only a few directories where all the JARs are loaded automatically. In directories such as /jre/lib only the JARs it expects to load are loaded. Any other JAR needs to loaded via the classpath.

1
  • 1
    So , is it something like bootstarp class loader loads only the class which is provided by JVM internally such as the classes inside rt.jar
    – Roshan
    Apr 17, 2016 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.