Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

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: 22080
113
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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.
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic