What is serialVersionUID?

What is serialVersionUID?

What is serialVersionUID?

What is serialVersionUID?
  • In Serialization, both sender and receiver need not be the same person, need not use the same machine and need not be from the same location. That person may be different, machines may be different and location may be different.
  • In Serialization, both sender and receiver have a .class file at beginning only. Just state of the object is traveling from sender to receiver.
  • At the time of serialization with every object sender side, JVM will save a unique identifier.
  • JVM is responsible to generate this unique identifier based on the .class file.
  • At the time of de-serialization receiver side, JVM will compare the unique identifier associated with the object with a local class unique identifier. If both are matched then only de-serialization will be performed otherwise we will get RuntimeException saying invalid class exception.
  • This unique identifier is nothing but SerialVersionUID
  • SerialVersionUID is used to version serialized data. You can only de-serialize a class if it’s SerialVersionUID matches the serialized instance.
  • SerialVersionUID is used to ensure that during deserialization the same class (that was used during serialize process) is loaded.

Leave a Reply

Your email address will not be published. Required fields are marked *

*