• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classloaders  RSS feed

 
Vineeth Kumar N
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the need of class loaders in java?Please guide me for the same

 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, this should come as no surprise really, but the purpose of class loaders is to load classes. Classes are usually read from the file system where they are stored as files in directories or entries in jar archives, but they could be anywhere ... stored on a network, in a database, returned by a web service (maybe, I'd have to think about that one). A simple Java program uses a single class loader, but a more complex application like an app server might use a hierarchy of loaders. This allows different parts of the application to share a set of common classes, while still having a set of classes unique to them.
 
Vineeth Kumar N
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Greg,But i found in one of the application in which they are loading the class loader using the method getClassLoader() .Then the same class loader is used to load the class.So i didn't
got the purpose of class loaders in this context.
Also we can use reflection also to load the class right .So what is the difference between these two
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Previous discussions, found by searching for"classloaders" through all forums:

http://www.coderanch.com/t/582246/java/java/Java-Class-Loaders

http://www.coderanch.com/t/551500/java/java/Classloade
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vineeth Kumar N wrote:Also we can use reflection also to load the class right .So what is the difference between these two

At the risk of getting the same reply as in the first thread that Ulf mentioned, I would say: don't worry about it.

I'm an experienced programmer, and I've never had a need to use them unless I was told to in documentation; in which case (one hopes), you will be given instructions on how to use them for the specific situation.

I know you probably want to know 'everything about everything', but seriously, at this stage, there are better uses for your time. And custom ClassLoaders (like reflection) are best left for a point when you know when, why and how to use them - which, in my experience is "almost never". And if even if you think you do, there may well be a more elegant solution available.

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!