File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes SerialVersionUID Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "SerialVersionUID" Watch "SerialVersionUID" New topic


Ranganath Junpal
Ranch Hand

Joined: Aug 31, 2006
Posts: 76

I wanted to know wht exactly the Serial Version UId is all about. I did google for the information but i got a very abstract answers like it improves the performance N stuff..
Please let me know where exactly we use it.

Thank you
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
When a object is deserialized , first it checks that class compatibility with the class available to the classloader at the instance of deserialization.This is done by comparing the serialversionID of the class that is there with the serialized data to that of the serialversionID class which would be used for deserialization.

It might happen that class used for creating the object before serialization has changed in the couse of time.
HF book on core java explains this fact very clearly.You can refer that.

Rahul Bhattacharjee
LinkedIn - Blog
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
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.
I agree. Here's the link:
subject: SerialVersionUID
jQuery in Action, 3rd edition