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 ?
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.
Steve
My pie came with a little toothpic holding up this tiny ad:
a bit of art, as a gift, that will fit in a stocking