Java Object Serialization --What 1902 11 Object Serialization extends the core Java Input/Output classes with support for objects. Object Serialization supports the encoding of objects,and the objects reachable from them,into a stream of bytes;and it supports the complementary reconstruction of the object graph from the stream. Institute of Computer Software 2022-2-27 Nanjing University
Java Object Serialization -- What Object Serialization extends the core Java Input/Output classes with support for objects. Object Serialization supports the encoding of objects, and the objects reachable from them, into a stream of bytes; and it supports the complementary reconstruction of the object graph from the stream. 2022-2-27 Institute of Computer Software Nanjing University 11
Java Object Serialization -Goal 102 12 Have a simple yet extensible mechanism. Maintain the Java object type and safety properties in the serialized form. Be extensible to support marshaling and unmarshaling as needed for remote objects. Be extensible to support simple persistence of Java objects. Require per class implementation only for customization. Allow the object to define its external format. Institute of Computer Software 2022-2-27 Nanjing University
Java Object Serialization -- Goal Have a simple yet extensible mechanism. Maintain the Java object type and safety properties in the serialized form. Be extensible to support marshaling and unmarshaling as needed for remote objects. Be extensible to support simple persistence of Java objects. Require per class implementation only for customization. Allow the object to define its external format. 2022-2-27 Institute of Computer Software Nanjing University 12
Java Object Serialization --How 1902 13 Objects to be saved in the stream may support either the Serializable or the Externalizable interface. For Serializable objects,the stream includes sufficient information to restore the fields in the stream to a compatible version of the class. For Externalizable objects,the class is solely responsible for the external format of its contents. Institute of Computer Software 2022-2-27 Nanjing University
Java Object Serialization -- How Objects to be saved in the stream may support either the Serializable or the Externalizable interface. For Serializable objects, the stream includes sufficient information to restore the fields in the stream to a compatible version of the class. For Externalizable objects, the class is solely responsible for the external format of its contents. 2022-2-27 Institute of Computer Software Nanjing University 13
&扇 The Serializable Interface 102 14 public interface java.io.Serializable {}i A Serializable class must do the following: Implement the java.io.Serializable interface Identify the fields that should be serializable Have access to the no-arg constructor of its first nonserializable superclass Institute of Computer Software 2022-2-27 Nanjing University
The Serializable Interface public interface java.io.Serializable { }; A Serializable class must do the following: Implement the java.io.Serializable interface Identify the fields that should be serializable Have access to the no-arg constructor of its first nonserializable superclass 2022-2-27 Institute of Computer Software Nanjing University 14
The Serializable Interface 15 The class can optionally define the following methods: writeObject(ObjectOutputStream) readObject (ObjectInputStream) ▣writeReplace() ▣readResolve() 思若:如果一个可序列化的类实现了以上四个方 法,那么在序列化和反序列化的过程中,这几个 方法的调用次序如何? Institute of Computer Software 2022-2-27 Nanjing University
The Serializable Interface The class can optionally define the following methods: writeObject (ObjectOutputStream) readObject (ObjectInputStream) writeReplace () readResolve () 2022-2-27 Institute of Computer Software Nanjing University 15 思考:如果一个可序列化的类实现了以上四个方 法,那么在序列化和反序列化的过程中,这几个 方法的调用次序如何?