What is use of serialization?

What is use of serialization?

Serialization can be obtained in a class by implementing the java.io.Serializable interface. 

All the subclasses of a serializedclass are also themseleves serialize. 

This interface contains no methods and used simply to identify being serialized.

 Its main purpose is to save the object state into a device or filefor the future use.

 This process is calles serialization. When we want to access the state of the object we make it deserialized.The classes that require serialization must implement the following methods for the serialization and deserialization process.

 private void writeObject(java.io.ObjectOutputStream out) throws IOException{//write the object state} private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException{//read the object state} The writeObject() method is responsible for saving the state of the object into a resource, i.e. device or a file. The readObject()method is responsible for the accessing the object state.

Date:2011-01-09 00:00:00

Post Your Answers

User Email:

User Name:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher