File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How Java handles class files?

 
Dimple Patra
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 195
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dimple Patra
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic