O'Reilly logo

Component Development for the Java™ Platform by Stuart Dabbs Halloway

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.2. Serialization Basics

Not all Java classes are serializable. To indicate that you want a class to be serializable, you must implement the java.io.Serializable interface. This interface has no methods; rather, it simply acts as a marker interface indicating a class's willingness to have its instances serialized. In Listing 4-1, the Person class is serializable, but the Humanoid class is not. When an instance of Person is written to a stream, the serialization architecture uses reflection to extract the field values and write them to the stream.

Listing 4-1. The Humanoid and Person Classes
 public abstract class Humanoid { protected int noOfHeads; private static int totalHeads; public Humanoid() { this(1); } public Humanoid(int noOfHeads) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required