In this chapter we have explored how we can write objects to a file and read them back. Making your class serializable makes it very easy to save your application data in a file. While what we have discussed is by no means exhaustive, you now know enough to deal with straightforward object serialization. The important points in this chapter are:
To make objects of a class serializable the class must implement the Serializable interface.
Objects are written to a file using an ObjectOutputStream object and read from a file using and ObjectInputStream object.
Objects are written to a file by calling the writeObject() method for the ObjectOutputStream object corresponding to the file.
Objects are read from a file by calling the readObject() method for the ObjectInputStream object corresponding to the file.
When necessary, for instance if a superclass is not serializable, you can implement the readObject() and writeObject() methods for your classes.
A good horse cannot be of a bad color.