MY mENU


Thursday 9 February 2012

Serialization in Java


Serialization is the process of converting a set of object instances that contain references to each other into a linear stream of bytes, which can then be sent through a socket, stored to a file, or simply manipulated as a stream of data. 

Serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments in a method invocation from a Client to a Server or as return values from a method invocation. In the first section of this book, There are three exceptions in which Serialization doesnot necessarily read and write to the stream.

These are :

1. Serialization ignores static fields, because they are not part of any particular object's state.
2. Base class fields are only handled if the base class itself is serializable.
3. Transient fields. There are four basic things you must do when you are making a class serializable.  They are
a. Implement the Serializable interface.
b. Make sure that instance-level, locally defined state is serialized properly.
c. Make sure that superclass state is serialized properly.
d. Override equals( )and hashCode( ).

It is possible to have control over Serialization process. The class should implement Externalizable interface. This interface contains two methods namely readExternal and writeExternal. You should implement these methods and write the logic for customizing the Serialization process.

No comments:

Post a Comment