41

Possible Duplicates:
Why should I bother about serialVersionUID?
what is a serial version id?

When i created a new class extending java.util.logging.Level in Eclipse, It asked me to add a default or generated serial version ID. I just added blindly without knowing what it is and why I have to add it.

Can anybody tell me what is it and why it its required.

Community
  • 1
  • 1
GuruKulki
  • 25,776
  • 50
  • 140
  • 201
  • 3
    duplicates: http://stackoverflow.com/questions/615181/what-is-a-serial-version-id, http://stackoverflow.com/questions/285793/why-should-i-bother-about-serialversionuid – Bozho Feb 13 '10 at 19:12

2 Answers2

38

The Serial Version ID is used when serializing and deserializing an object. Java recognizes 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.

There's a very good description about serializing in the javadoc of Serializable.

tangens
  • 39,095
  • 19
  • 120
  • 139
14

It is the unique identifier for the class, used for serialization.

It is wise to declare it if you're serializing asap because if you don't declare one then when changing the class it will get a different one generated automatically and the serialization will stop working.

A good reference is here: http://c2.com/ppr/wiki/JavaIdioms/AlwaysDeclareSerialVersionUid.html

metismo
  • 457
  • 2
  • 6