Some notes about the Java Serial Version UID

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.