Kowshik Nandagudi wrote:1 ) What does The serializable class PositionCollector does not declare a static final serialVersionUID field of type long mean ?
It means you are using Eclipse; other IDEs tend to keep quiet about it
. . .
3) What is the role of this id?
It ensures that you are deserialising from a particular version of a class to the same version. Imagine you have a Car class
Now imagine you add a new field to the class, in newer versions of the application.
If you serialize an object of the first Car class, and deserialize it into the newer Car class, where will the CD_Player object be? What the SUID does here, is to tell the JVM that despite the similar name, they are different classes. I think in that case, an Exception willl be thrown, but I am not certain.
There are at least three things you can do with SUIDs
1: Leave it out. That tells the JVM that you are not worrying whether different versions of the class are the same.2: Use the same SUID throughout (unzip the String class and look at its code). That tells the JVM to treat all versions of the class as if they were the same version.3: Give different versions different SUIDs. That tells the JVM to treat them as different versions, not mutually serializable with one another.There is a serialver tool which adds a SUID to a class.