• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

ClassPath class loader

Ranch Hand
Posts: 33
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

Saloon Keeper
Posts: 13886
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic