Solved

ClassLoaders in java

Posted on 2014-03-25
6
942 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
web application structure 18 100
type mismatch (Object[] to double[] 4 33
ejb stateless example 2 25
jsp login check 12 43
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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

828 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