• Register
Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

What is the difference between serialization and deserialization in java?

0 votes
5,760 views
What is the difference between serialization and deserialization in java?
asked Nov 15, 2013 in Java by Sheela

2 Answers

0 votes

There are following difference between serialization and deserialization in java:

Serialization Deserialization
Serialization is the process through which we can store the state of an object into any storage medium. We can store the state of the object into a file, into a database table etc. Deserialization is the opposite process of serialization where we retrieve the object back from the storage medium.
An object is serialized by writing it an ObjectOutputStream. An object is deserialized by reading it from an ObjectInputStream.

Example:-

           FileOutputStream out = new FileOutputStream("abc.txt");
           ObjectOutputStream oos = new ObjectOutputStream(out);
           oos.writeObject(new String ());
           oos.close ();

Example:-

FileInputStream in = new FileInputStream("abc.txt");
    ObjectInputStream ois = new ObjectInputStream(in);
    String s = (String) ois.readObject();
    ois.close();

 

answered Nov 16, 2013 by Piyush agrawal
0 votes

You see the following diagram and try to understand difference between serialization and deserialization:

Diffrence between serialization and deserialization in java

answered Nov 16, 2013 by Sudhakar Dadhich
I like this answer. This is very good for understanding in graphical view.
...