| Author |
How Java handles class files?
|
Dimple Patra
Greenhorn
Joined: Jun 28, 2002
Posts: 17
|
|
Hi, Suppose I have one class file with a object. Now If I change source file and increase one more field for object. Compile it and put it in same place where class file was there. My question here is how JVM mentains versions of class files? Regards Dimple
|
 |
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
|
|
|
There is no such a thing as "versions" of class files. If you change the source code and re-compile it, then you have earsed the old class file and replaced it with a new one.
|
Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
The only way to have different versions of a class file is to have each one located in a separate directory. So in your example above, when you copy the new class file to the location of the old one, the old "version" is gone. Layne p.s. A class file does NOT contain objects. It only contains a class (or perhaps multiple classes). It might be helpful for you to review the difference between these to terms. [ January 21, 2005: Message edited by: Layne Lund ] [ January 21, 2005: Message edited by: Layne Lund ]
|
Java API Documentation
The Java Tutorial
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
There are some environments that pick up a new version of a class in a running system such as JSPs, JUnit and most IDE debuggers. They do it by using a new ClassLoader for each new version. If one part of your program uses the system class loader to get an object and another part uses a custom loader to get the an object of the same class, they might wind up with different versions. The doc says something about all instances of the old version have to be unreferenced and eligible for GC to do this, but I'm not entirely sure about that. It sounds scary but you can read the JUnit code and they make it look dead simple. What is your objective, Dimple? I'm not sure if I'm on the right track at all.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Dimple Patra
Greenhorn
Joined: Jun 28, 2002
Posts: 17
|
|
Hi, Thanks all for giving your valuable comments. Someone ask me this query and I didnt know answer so I posted here for getting some idea. Question was when we replaced new class filed compiled and at other place then java takes new class file but how java knows or maintain those versions... Neways... from your all reply I think when we replaced class file java loader takes new class file. but there is not such versions mentaining in java for class files. Thanks again. Regards Dimple
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
|
BTW: You can really confuse the JVM if you replace a jar file. I guess at startup it reads the jar file and remembers the location of class files but doesn't really load the class files. If you change the jar and then it tries to load, bad things can happen. Or was that just me?
|
 |
 |
|
|
subject: How Java handles class files?
|
|
|