Implementing the Serializable interface

Objects pass from the server to a client application in serialized form. For an object to be sent to a client application, it must implement the Serializable interface. Fortunately, this is a very simple task.

StepsImplementing the Serializable interface

  1. Add the words implements java.io.Serializable to your class definition.

    Reviewers   Question for reviewers:  ASIQ-12_7\Samples\ASA\JavaSQL\manual-examples\, but I don’t see the Product class at all.

    For example, the Product class in the in $ASDIR/samples/asa/java/asademo (UNIX) or %ASDIR%\samples\asa\java\asademo (Windows) subdirectory implements the Serializable interface by virtue of the following declaration:

    public class Product implements java.io.Serializable 
    

    Implementing the Serializable interface amounts to simply declaring that your class can be serialized.

The Serializable interface contains no methods and no variables. Serializing an object converts it into a byte stream which allows it to be saved to disk or sent to another Java application where it can be reconstituted, or deserialized.

A serialized Java object in a database server, sent to a client application and deserialized, is identical in every way to its original state. Some variables in an object, however, either don't need to be or, for security reasons, should not be serialized. Those variables are declared using the keyword transient, as in the following variable declaration.

transient String password;

When an object with this variable is deserialized, the variable always contains its default value, null.

Custom serialization can be accomplished by adding writeObject() and readObject() methods to your class.

For more information about serialization, see Sun Microsystems' Java Development Kit (JDK).