This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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.
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 ]
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
Joined: Jun 28, 2002
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.
Joined: Jan 29, 2003
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?