• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassLoader

 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the difference between ClassLoader.getSystemResourceAsStream and ClassLoader.getResourceAsStream ??
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getSystemResource() will only consult the "system ClassLoader", while getResource() will consult the ClassLoader the method is called on. The system ClassLoader is the "built-in" one, the one that loads classes from the CLASSPATH when an application starts up.
No Java programmer should miss reading Ted Neward's two excellent articles on ClassLoaders here and here.
 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So then all of my classes that I created in a single application should have the same classloader?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Should" meaning "will, generally" or "should" meaning "it is good practice to?" The former, yes. The latter, not especially. If you need multiple ClassLoaders, then they're a good thing. If you don't, then you don't, and that's fine too.
Anyway, the answer to your question is that they will, in general, if you don't do anything special -- i.e., if you don't create your own class loader.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic