What is the purpose of Serial Version UID in Java?

It is used to uniquely identify a serialized object's class during the process of deserialization.

For example, if an object is serialized and if the newer version of a class is available during the deserialization process, the Java runtime checks if the serial version UID of the loaded class matches with that of the object to be deserialized.

If the serial Version UID does not match then it will throw an InvalidClassException.

It is always a best practice to declare serialVUID for a serializable class.

Interview Questions: 

Search