• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassPath class loader

 
arunseege paramashivappa
Ranch Hand
Posts: 33
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can anyone please give info. on classpath class loader.My understanding as of now is

whenever we say

Java xyz.

JVM will search for it in classpath and load it into JVM.


But my confusion is system class loader and classpath class loader are one and the same?.

And also when an instance of JVM is created which are the class loaders will executed.

Please give me supporting links to understand class loading clearly and better.

Thanks-Arun
 
Stephan van Hulst
Bartender
Pie
Posts: 5803
61
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arunseege, welcome to CodeRanch!

No, the classpath loader and the system loader aren't the same.

Now, it's been a while since I delved into this subject, but I believe that when you start the JVM, it will always initialize the system loader. It's responsible for loading those few classes that are necessary for the JVM itself to run, and for it to be able to delegate the rest of the classes to other class loaders. This is only speculation on my end, but I think it's responsible for loading classes such as Object, Class, ClassLoader, String, arrays, etc. I believe the system class loader is more or less "hardcoded" into the JVM's executable. I'm not actually sure of this last part, because I think you can even specify a custom loader that's responsible for these classes.

When the system class loader is done, the JVM creates an instance of whatever default loader is in the configuration files. This would be the Classpath loader by default. You can also create your own custom loader and have it initialize that instead.

When a class' name is referenced, the JVM will get the class loader that loaded the class that references it, and ask it to retrieve its Class instance. The loader will first ask its "superior" loader (usually the Classpath loader) for the Class, which in turn will ask its own superior (the system loader). If the system loader can't find the Class, the classpath loader will try to find it, and if it can't find it either, the loader below that goes to find it.

You can probably get more detailed and correct info if you go through the ClassLoader docs, the Virtual Machine documentation, and if you just google around.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic