Adding persistence to application means storing data so that data persists beyond the lifetime of the application execution. Typically, for this to happen, we need to to write (i.e. store) data in a non-volatile storage.
The easiest way to go is perhaps to save data to (plain text) files.
Let's try that as a way of warming up to Java's syntax! Make a new package,
persistence and add the following interface to it:
When persisting data, you usually access the data in memory and write it out as a series of bytes to some storage or transmission medium (a file on disk), one after the other. This is called serializing, and the reverse process is deserializing.
Let's now implement a "persister" for the
You can give it a try:
The output must be
Moreover, if you open the
Author.txt file, it must contain: