Skip to main content
Serialization
- The classes you need to understand are all in the java.io package;
they include: ObjectOutputStream and ObjectInputStream primarily, and
FileOutputStream and FileInputStream because you will use them to create
the low-level streams that the ObjectXxxStream classes will use.
- A class must implement Serializable before its objects can be serialized.
- The ObjectOutputStream.writeObject() method serializes objects, and
the ObjectInputStream.readObject() method deserializes objects.
- If you mark an instance variable transient, it will not be serialized even thought the rest of the object's state will be.
- You can supplement a class's automatic serialization process by
implementing the writeObject() and readObject() methods. If you do this,
embedding calls to defaultWriteObject() and defaultReadObject(),
respectively, will handle the part of serialization that happens
normally.
- If a superclass implements Serializable, then its subclasses do automatically.
- If a superclass doesn't implement Serializable, then when a subclass
object is deserialized, the superclass constructor will be invoked,
along with its superconstructor(s).
- DataInputStream and DataOutputStream aren't actually on the exam, in spite of what the Sun objectives say.