what is the different between default and generated serial version uid in java?

Savan Javia picture Savan Javia · Feb 2, 2017 · Viewed 7.3k times · Source

I don't know exactly where to use default serialVersionUID or generated serialVersionUID in java ?

private static final long serialVersionUID = 4125965356358329466L; // generated
private static final long serialVersionUID = 1L; // default

Answer

rushang patel picture rushang patel · Feb 2, 2017

The Serial Version ID is used in serializing and deserializing an object. Java identifies if the bytes you want to deserialize match the local class version,if not it will throw an exception. This is important when doing RMI or persisting object structures. The serialization 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.