• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Please help me understand some concepts about classloader

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am really confused by the classloader hierarchy. for example, a very simple AAA.java file:


When I run the AAA, it is absolutely loaded by system classloader, but the String.class, System.class and Integer.class referenced by it should be loaded by bootstrap classloader. So, class AAA and those it referenced are loaded by different classloaders. why AAA can access them ?
 
Ranch Hand
Posts: 56
Eclipse IDE Chrome Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

this works because classloaders inside a JVM build a hierarchy.

See http://www.objectsource.com/j2eechapters/Ch21-ClassLoaders_and_J2EE.htm or http://www.digilife.be/quickreferences/PT/Understanding%20the%20Java%20ClassLoader.pdf (especially the "further reading" section at page 17)

Regards,
Ramon
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classloader hierarchies aren't "Beginning Java". Moving to Java in General.
 
gg cowra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ramon Anger wrote:Hi,

this works because classloaders inside a JVM build a hierarchy.

See http://www.objectsource.com/j2eechapters/Ch21-ClassLoaders_and_J2EE.htm or http://www.digilife.be/quickreferences/PT/Understanding%20the%20Java%20ClassLoader.pdf (especially the "further reading" section at page 17)

Regards,
Ramon



From the hyperlinks you provided, I got some valuable knowledge that I had never known.

Sing highly praise for your great help!
 
Ranch Hand
Posts: 107
MyEclipse IDE Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Boot Strap class loader or default class loader which is defined in side JVM By default Boot Strap class loader will load your class. But boot strap class loader will load class from local file system.Also you can define you own class loader.
please correct me if I am wrong.
 
gg cowra
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Somprakash Rai wrote:Boot Strap class loader or default class loader which is defined in side JVM By default Boot Strap class loader will load your class. But boot strap class loader will load class from local file system.Also you can define you own class loader.
please correct me if I am wrong.



According to the delegation principle of Java classloaders' hierarchy, the bootstrap classloader will be delegated to try to load my classes, but it could not find them, because it only loads the classes in the JRE/lib or as specified by the command line switch -Xbootclasspath . By default my classes will be eventually loaded by System-Classpath classloader or some children of it.

The key of my problem is the visibility principle of classloader operation. The fact that classes written by myself can access standard JDK classes just because the bootstrap classloader is a parent classloader above the system-classpath classloader.
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's something you can't prevent. When a ClassLoader tries to load a class it first asks its parent if the class has already been loaded. If so it will return the class as loaded by the parent. Only if the parent (or the parent's parent, etc) hasn't loaded the class yet will the ClassLoader try to load the class itself. Since the system class loader will always be somewhere at the top of the ClassLoader hierarchy, all classes from the core API are always available. The same goes for classes on the class path.
 
It will give me the powers of the gods. Not bad for a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic