0 votes
1.6k views
in Java by
Why serialization needed in java? What is the advantage and disadvantage of serialization?

1 Answer

+1 vote
by
 
Best answer

You see the following reason to use serialization in our your java application or project:

  1. Serialization is usually used When we need to send our data over network or stored in files. That means objects and not text.
  2. Now the problem is occured in our Network infrastructure and our Hard disk. Both are hardware components that understand bits and bytes but not JAVA objects.
  3. Serialization is the translation of our Java object's values/states to bytes and send it over network or save it.


So, serialization allows us to read/write arbitrarily complicated Java objects, automatically from/to disk or from/to the network. Whereas XML and JSON are textual formats, serialization is a binary format.

Advantages:
At first, you get serialization pretty much for free. You don't need to make very many changes to your objects in order to let the serialization mechanism work with it. Another advantage is that, because it is a binary format, it is much more compact than the textual format, and so will probably use less space (which is good for conserving network bandwidth or for conserving storage space on disk).

Disadvantages:
The disadvantage to serialization is that, if you make changes to your object, making the different serialization formats compatible can really be a major nightmare. Also, whereas you can manually edit XML and JSON, you cannot edit a serialized Java object (without reading it into Java). For the same reasons, it is often easier to debug XML and JSON than binary formats, because XML and JSON are human-readable.

Share:- Whatsapp Facebook Facebook


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

Categories

...