The docs for java.io.Serializable are probably about as good an explanation as you'll get:
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. If the receiver has loaded a class for the object that has a differentserialVersionUIDthan that of the corresponding sender's class, then deserialization will result in anInvalidClassException. A serializable class can declare its ownserialVersionUIDexplicitly by declaring a field namedserialVersionUIDthat must be static, final, and of typelong:
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
Answer from Jon Skeet on Stack OverflowIf a serializable class does not explicitly declare a
serialVersionUID, then the serialization runtime will calculate a defaultserialVersionUIDvalue for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declareserialVersionUIDvalues, since the defaultserialVersionUIDcomputation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpectedInvalidClassExceptionsduring deserialization. Therefore, to guarantee a consistentserialVersionUIDvalue across different java compiler implementations, a serializable class must declare an explicitserialVersionUIDvalue. It is also strongly advised that explicitserialVersionUIDdeclarations use the private modifier where possible, since such declarations apply only to the immediately declaring class โserialVersionUIDfields are not useful as inherited members.
java - What is a serialVersionUID and why should I use it? - Stack Overflow
How to manually generate a serialVersionUID with Eclipse?
java - What means 1L serialVersionUID? When could I use this default value 1L? - Stack Overflow
Java Externalizable serialVersionUID - Stack Overflow
Videos
The docs for java.io.Serializable are probably about as good an explanation as you'll get:
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. If the receiver has loaded a class for the object that has a differentserialVersionUIDthan that of the corresponding sender's class, then deserialization will result in anInvalidClassException. A serializable class can declare its ownserialVersionUIDexplicitly by declaring a field namedserialVersionUIDthat must be static, final, and of typelong:
ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
If a serializable class does not explicitly declare a
serialVersionUID, then the serialization runtime will calculate a defaultserialVersionUIDvalue for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declareserialVersionUIDvalues, since the defaultserialVersionUIDcomputation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpectedInvalidClassExceptionsduring deserialization. Therefore, to guarantee a consistentserialVersionUIDvalue across different java compiler implementations, a serializable class must declare an explicitserialVersionUIDvalue. It is also strongly advised that explicitserialVersionUIDdeclarations use the private modifier where possible, since such declarations apply only to the immediately declaring class โserialVersionUIDfields are not useful as inherited members.
If you're serializing just because you have to serialize for the implementation's sake (who cares if you serialize for an HTTPSession, for instance...if it's stored or not, you probably don't care about de-serializing a form object), then you can ignore this.
If you're actually using serialization, it only matters if you plan on storing and retrieving objects using serialization directly. The serialVersionUID represents your class version, and you should increment it if the current version of your class is not backwards compatible with its previous version.
Most of the time, you will probably not use serialization directly. If this is the case, generate a default SerialVersionUID by clicking the quick fix option and don't worry about it.
I need to generate a value for a:
private static final long serialVersionUID
I Googled around went to a few sites, and several posts on stackoverflow.
All said that Eclipse should underline a variable and offer to generate such a value.
That isn't happening for me.
Is there a way to manually make Eclipse generate such a value?
Thank You
What is the meaning? Is that useful?
Yes. The point of serialVersionUID is to give the programmer control over which versions of a class are considered incompatible in regard to serialization. As long as the serialVersionUID stays the same, the serialization mechanism will make a best effort to translate serialized instances, which may not be what you want. If you make a semantic change that renders older versions incompatible, you can change the serialVersionUID to make deserializing older instances fail.
If all classes have the same serialVersionUID 1L, is there no problem?
No - the serialVersionUID is per class.
This is explain here:
The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown.
From the javadoc:
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. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:
Useful Links
- java.io.Serializable
- Why should I bother about serialVersionUID? (StackOverflow)
- serialVersionUID in Java Serialization