| CONTENTS | PREV | NEXT | Java Object Serialization Specification |
Object Serialization produces a stream with information about the JavaTM classes for the objects which are being saved. For serializable objects, sufficient information is kept to restore those objects even if a different (but compatible) version of the implementation of the class is present. TheSerializableinterface is defined to identify classes which implement the serializable protocol:package java.io; public interface Serializable {};A Serializable class must do the following:
serialPersistentFields member to explicitly declare them serializable or use the transient keyword to denote nonserializable fields.)
The class can optionally define the following methods:
- A
writeObjectmethod to control what information is saved or to append additional information to the stream- A
readObjectmethod either to read the information written by the correspondingwriteObjectmethod or to update the state of the object after it has been restored- A
writeReplacemethod to allow a class to nominate a replacement object to be written to the stream
ObjectOutputStreamandObjectInputStreamallow the serializable classes on which they operate to evolve (allow changes to the classes that are compatible with the earlier versions of the classes). See Section 5.5, "Compatible JavaTM Type Evolution" for information about the mechanism which is used to allow compatible changes.