Skip to content

Serialization of Objects

August 6, 2009
tags:
Serialization of Objects means to store the value of an object at any given point of time. For example when you use MS Paint to draw certain figures and save them, then you actually serialize the state of the object (figure) when saving.
In Java you have got APIs for drawing certain figures which you can use to draw and to be able to persist the state of the figures drawn so that they can be retrieved later you can serialize them.
In case of advanced Java programming, consider a situation where your application wants to communicate with a remote object and wants reference to that remote object. As long as objects are on the same virtual space, they can be passed by reference(default behavior) but in case when an object needs to be passed in a different virtual space, in such a scenario, objects needs to be passed by value because the remote later does not have any reference to the object. So to meet this situation, objects needs to be serialized. While serializing, the parameters are marshalled and demarshalled on deserialization.
To implement serialization, you need to implement the java.io.Serializable interface. It is just a marker interface which is understood by JVM and contains no methods. In case if you want an attribute of the object not to be serialized, then make it transient.
Marshalling and Demarshalling
When objects in memory are to be passed across a network to another host or persisted to storage, their in-memory representation must be converted to a suitable out-of-memory format. This process is called Marshalling, and converting back to an in memory representation is called Demarshalling.
Advertisements
No comments yet

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

%d bloggers like this: