File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me understand some concepts about classloader

 
gg cowra
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • 2
  • Mark post as helpful
  • send pies
  • 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
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Classloader hierarchies aren't "Beginning Java". Moving to Java in General.
 
gg cowra
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Prakash Rai
Ranch Hand
Posts: 106
Eclipse IDE MyEclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Pie
Posts: 20393
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic