• Post Reply Bookmark Topic Watch Topic
  • New Topic

version Java classes ?  RSS feed

 
Edward Chen
Ranch Hand
Posts: 798
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why we need to version Java classes, only for serialization ? if yes, when the java code is in production, it will not be changed at all, why need version ?

Thanks.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about the 'serialVersionUID?' Then yes, that is really only necessary for Serializable classes.

Why do we need it when the code is 'stable' and goes to production? The problem with a good program is that it is never finished being written. The code can be updated and changed over time. Now, if you have Serializable classes and you have Serialized objects that may live for some time then you could have versions of the class that come from different versions of the application. Some of those versions may be incompatible with other version, and having a real version ID is important for tracking that.

This becomes an issue because you can store the Serialized Object to disk, to a database, or across a network. Then when you de-serialize the Object you could be de-serializing it in a newer or older iteration of the program. You might need to apply different conditions when re-building an older-version Object into a newer-version application, or you might not be able to properly de-serialze an Object created in a newer-version application in an older-version application.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!