Okay, assume that you have a class ObjectA
- You want to store the object into a file storage. You make use of writeObject and readObject to do that. You have successfully serialized the objects to disk storage.
- Now you change the class ObjectA, say you add new member variable or delete existing variable. You compile the class. Since your class implements Serializable interface a new SUID is generated.
- After this, you want to read the contents back from disk which you serialized before. But you can't since the class ObjectA has been modified java will throw an exception.
- So how do you make deserialize the data from disk with changed class definition? With help of SUID. You declare
private static final long serialVersionUID=<Original SUID of ObjectA>
in the class ObjectA.
In short SUID are used when the version of class reading the data from file is different from the version of class that wrote the data to file.
The below URL's will help in understanding serialization and SUID's.
http://java.sun.com/j2se/1.5.0/docs/api/java/io/Serializable.html http://java.sun.com/j2se/1.5.0/docs/api/java/io/ObjectOutputStream.html http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serialTOC.html