CopyPastor

Detecting plagiarism made easy.

Score: 0.8729001331815914; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2020-04-24
by Saurabh Verma

Original Post

Original - Posted on 2009-05-20
by coobird



            
Present in both answers; Present only in the new answer; Present only in the old answer;

The purpose of the serialization version UID is to keep track of different versions of a class in order to perform valid serialization of objects.
The idea is to generate an ID that is unique to a certain version of an class, which is then changed when there are new details added to the class, such as a new field, which would affect the structure of the serialized object.
A Simple Explanation:
Are you serializing data?
Serialization is basically writing class data to a file/stream/etc. De-serialization is reading that data back to a class.
Do you intend to go into production?
If you are just testing something with unimportant/fake data, then don't worry about it (unless you are testing serialization directly).
Is this the first version?
If so, set serialVersionUID=1L.
Is this the second, third, etc. prod version?
Now you need to worry about serialVersionUID, and should look into it in depth.
Basically, if you don't update the version correctly when you update a class you need to write/read, you will get an error when you try to read old data.
The purpose of the serialization version UID is to keep track of different versions of a class in order to perform valid serialization of objects.
The idea is to generate an ID that is unique to a certain version of an class, which is then changed when there are new details added to the class, such as a new field, which would affect the structure of the serialized object.
Always using the same ID, such as `1L` means that in the future, if the class definition is changed which causes changes to the structure of the serialized object, there will be a good chance that problems arise when trying to deserialize an object.
If the ID is omitted, Java will actually calculate the ID for you based on fields of the object, but I believe it is an expensive process, so providing one manually will improve performance.
Here's are a couple of links to articles which discuss serialization and versioning of classes:
- [JDC Tech Tips: February 29, 2000][1] *(link broken as of February 2013)* - [Discover the secrets of the Java Serialization API][2]

[1]: http://java.sun.com/developer/TechTips/2000/tt0229.html [2]: http://www.oracle.com/technetwork/articles/java/javaserial-1536170.html

        
Present in both answers; Present only in the new answer; Present only in the old answer;