Java provides a mechanism, called object serialization where an object
can be represented as a sequence of bytes that includes the object's
data as well as information about the object's type and the types of
data stored in the object.
Adding Serializable
marks them having exactly the described functionality.
Example use of serialisation:
The serializability allows you to stream your class in a file and read it again from the file.
Classes ObjectInputStream and ObjectOutputStream are high-level
streams that contain the methods for serializing and deserializing an
object.
public final void writeObject(Object x) throws IOException
public final Object readObject() throws IOException, ClassNotFoundException
These methods allow you to serialize and deserialize a class that is marked as serializable.
Additional information:
As mentioned by @Basil Bourque - when you read the documentation about a.e. BigInteger you find this:
static BigInteger ONE //The BigInteger constant one.
static BigInteger TEN // The BigInteger constant ten.
static BigInteger ZERO //The BigInteger constant zero.
source: JavaDocs
Compared to Integer the BigInteger is not a single primitve object. It rather consists of several objects. Together they behave like a primitive Integer. Except if a serializer meets this object it does not know if the class is serializable (No true primitive type). This you can handle by manually marking the class as Serializable by adding the implements Serialiable
.