When you transmit Java objects on the network, store Java objects in a file, store Java objects as BLOBs in a database, you need to serialize and deserialize Java objects, and the standard mode is to implement the serializable interface.
When implementing the above interface, a serial version UID is required to identify the version of the class. Once an object is serialized, it can be deserialized as long as its version is unchanged, once
Changes that cause version inconsistencies will throw invalidclassexception exceptions.
It is recommended that the definition UID be displayed, and if the definition is not displayed, the JVM automatically generates a value that is related to the compiler's implementation, is unstable, and may cause a invalidclassexception exception to be thrown in different JVM environments.
In eclipse, there are two ways to display the definition uid, one is "add default serial Version ID", the default value is 1L, the other is "add generated serial version ID", the default value is a large number, is based on
class, and the value changes when the Class property is changed.
The first method of automatic generation is recommended, and the UID needs to be modified when the class is modified for incompatibility.
When using the second method, if the property is modified and the UID is not regenerated, the default value will not change, or it can be deserialized normally, but it is not recommended, after all, the value of the UID does not match the actual.
For compatibility and incompatibility modification of classes, see the following url:http://docs.oracle.com/javase/7/docs/platform/serialization/spec/version.html.
Hibernate's Pojo class recommendations are also used in this way to facilitate expansion.
For an inheritance relationship, the parent class implements the serialization interface, and the subclass can inherit the implementation of the interface, but the definition UID needs to be displayed, because the parent class UID type is private static and cannot be inherited, and the subclass requires a separate UID as a separate class.
Some notes about the Java Serial Version UID