Ask Google

Custom Search

Saturday, March 5, 2011

What is serialization in Java?

When you serialize a Java object, you will be able to save its state as a sequence of bytes that will persist even after your Java virtual machine is not running. Next time, when you program is up and running again, it can rebuild the last state into its Java object form for reuse in your application. Usually, a serialized object can be stored on a hard disk as a file stream. Since it is a file stream, it can be transferred over a network as well.

AXB uses the serialization approach to serialize a Java object into a XML form (marshal) and from a XML form to a Java object (unmarshal)

But, get back to your actual question: why we need to serialize? Is it necessary?

If you feel you need to persist your Java objects for short term purpose like a session and your interface definition stays the same across version revisions (that is an Animal object is still an Animal object despite an addition of new fields), use it.

If you feel you need to persist your Java objects over a wire, use it.

No comments:

Post a Comment

5L15K

  © Blogger template The Beach by Ourblogtemplates.com 2009

Back to TOP