A Brief introduction of Serialization in java

Imagine you want to save the state of one or more objects. What will you do is use one of the I/O classes to write out the state of the instancevariables of all the objects you want to save. The worst part is trying to reconstruct the new object that identical to the object that you have saved.In this case, yon need some protocol for the way you wrote and restored the state of each objects or you may end up setting wrong values to their respective variables.
For instance, while saving object that has instance variables for height and weight, you write the height and weight as 2 ints in a file, but the order in which  you wrote is significant.It would be all too easy to re-create the object but mix up the height and weight values—using the saved height as the value for the new object’s weight and vice versa.
Serialization lets you simply say “save this object and all of its instance variables.” unless you marked a variable as transient, which means don’t save the variable value.

Click here to read further

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s