0 votes
6.5k views
in Java by
What is the difference between serialization and deserialization in java?

2 Answers

0 votes
by

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();

 

0 votes
by

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

Diffrence between serialization and deserialization in java

by
I like this answer. This is very good for understanding in graphical view.

Share:- Whatsapp Facebook Facebook


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

Categories

...