A concept,

Serialization: Saving Java objects locally as binary bytecode (or transferring them over the network to another machine, which is not well understood at present).

Deserialization: Converts serialized binary bytecode into Java objects.

Second, the purpose of

Java objects exist only when the service is started and are stored in memory. When the program is finished, the objects are destroyed. If you need to run a procedural object, you can save it as a serialization.

Third, practice

  1. Implement the Serializable interface. Add transient to JavaBean properties to serialize objects with default values, and override writeObject(Object obj) and readObject() methods.
  2. Implement **Externalizable, ** writeExternal(ObjectOutput Out) and readExternal(ObjectInput in) methods

The function of serialVersionUID

private static final long serialVersionUID = 1l; // The entity class makes the display declarationCopy the code

The JVM also implicitly declares a serialVersionUID when the JavaBean class implements the serialization interface and does not explicitly declare a serialVersionUID, but when the JavaBean changes, the de-ordering will report an error.

That is, when deserializing, the JVM compares the serialVersionUID of the local binary bytecode to the serialVersionUID of the JavaBean, The implicit serialVersionUID is recalculated after code changes (such as adding whitespace), resulting in version inconsistencies. SerialVersionUID is used to generate Java objects based on the current JavaBean. Even if the JavaBean code changes, new objects are generated based on the JavaBean.

In addition, the JavaBean property is modified after serialization, and the deserialized object is still the same as the previously serialized object. JavaBean attributes that are static are excluded.

5. JavaBean classes have reference (or inherit) types. Reference (parent) types also need to implement Serializable interface.

www.cnblogs.com/9dragon/p/1…

Blog.csdn.net/u014750606/…

www.cnblogs.com/chenbenbuyi…