Serialization allows storing (and restoring) objects as streams – allowing them to be saved to disk or sent over network connections.
A class which implements the java.io.Serializable interface will be available to serialize. The interface itself is empty – there are no methods on it, it’s just a marker interface.
If you mark an object as being available for serialization you can use the transient keyword to mark variables which should not be serialized – passwords for instance.
Over time you may make changes to a class which you’re using serialization with. Because of this it’s important to know if we’ve made any significant changes (e.g. changing a field from transient). We use a versioning marker for this which you have probably seen your IDE prompt you to use:
static final long serialVersionUID;
If you restore an object having changed the serialVersionUID then an InvalidClassException will be thrown. If you do not specify the serialVersionUID then a default one will be generated for you. It may be over sensitive to changes to your class though and result in more InvalidClassException errors than may be necessary.
Serialization, while useful where required, is slow. That’s not so much a bad thing as just something to keep in mind.