Solved

ClassLoaders in java

Posted on 2014-03-25
6
923 Views
Last Modified: 2014-04-03
Two objects loaded by different class loaders are never equal even if they carry the same values.
This means a class is uniquely identified in the context of the associated classloader. This applies to singletons too, where each classloader will have its own singleton.

I was reading as above. I have not understood what it means.
please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:Sharon Seth
ID: 39955749
I do not think two classloaders(on the same JVM) can load the same object , it wld create conflicts when trying to access the class. But the same object on different JVMs is possible.
0
 
LVL 35

Expert Comment

by:girionis
ID: 39958275
It means that a class can be loaded by two different classloaders, and in the context of the JVM these classes are considered *not* the same, even if, in fact, they are byte-for-byte the same class. So if you have a class A which is loaded by both classloader X and classloader Y then, as far as the JVM is concerned, you have *two different* classes. This is what the phrase
a class is uniquely identified in the context of the associated classloader
means.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39973090
how is classloader is different or related to JVM. In which practical scenario this situation happens? I never come across this scenario earlier. please advise
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:girionis
ID: 39974295
All classloaders are loaded by the JVM. When the JVM starts it loads the bootstrap classloader, and this in turn loads all other classes, including the rest of the classloaders that will load their own classes and so on.
0
 
LVL 12

Assisted Solution

by:Sharon Seth
Sharon Seth earned 100 total points
ID: 39974725
I still do not believe there will be a practical scenario where a class will be loades by two classloaders . Class loading is hierarchial , in the sense that a classloader first checks if a class is already loaded by another lower level class loader , before actually loading it .
0
 
LVL 35

Accepted Solution

by:
girionis earned 400 total points
ID: 39974767
A class is identified (among other things) in the context of the classloader as well. So two different classloader could load the same class twice. Here is a nice article on different ways you can get two different objects from two different classloaders.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now