Hello I've one question about SerialVersionUID
in Java.
If I generate a SerialVersionUID
for class A
,
2 instances of A
have the same SerialVersion
about class and another unique Serial for the object, different about object1
and object2
? Or how?
I don't understand, please reply me. Thanks.

- 736
- 2
- 7
- 22
-
2SerialVersionUID is a static field, therefore it "belongs" to the class, not to any of the instances. – Robert Jan 17 '17 at 09:15
2 Answers
SerialVersionUID is way to identify a class's version. So all objects of the same class will have the same SerialVersionUID. However if you make change to the class, it is recommended to change the SerialVersionUID. And then in case of incompatibility, the serialization of the object would fail.
serialVersionUID is used for version control of object.
If we don’t define serialVersionUID in the class, and any modification is made in class, then we will be unable to deSerialize our class because serialVersionUID generated by java compiler for modified class will be different from old serialized object and deserialization process will end up throwing java.io.InvalidClassException
- The serialization at runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization.
serialVersionUID object1 and object2?
It will be same, as serial version uid is static (i.e. class level)

- 5,569
- 1
- 24
- 45