Overview of Object Serialization
by, 04-25-2012 at 10:14 PM (581 Views)
Object serialization is that mechanism which is considered useful in all programs which save objectís state to the file and then reads objects for reconstruction of the state of program, or using the sockets to send object at the network. Class serialization could be done very easily by using class implement java.io.Serializable interface. It is marker interface which has no methods to be implemented. This is used for informing the JVM (Java Virtual Machine) which one wants an object to get serialized.
Two main classes used to write or read objects, to stream:
ObjectInputStream & ObjectOutputStream
ObjectOutputStream gives a method called writeObject to write object to output stream. On the other hand, ObjectInputStream gives a method known as readObject so that from input stream an object could be read. Important thing is that objects shall be serialized that are used by the objects. This actually means that Serializable interface shall be implemented by the classes.