views:

272

answers:

6

Hi

In not so technical way, what is object serialization and the purpose of it? When should it be used?

(any analogies exampls welcome)

Thank You

+6  A: 

Object serialization allows you to transform objects (datastructures) into a binary or another custom representation. This in turn can be used to send those binary representations over the wire or to store them on a filesystem.

Serialization can be used for

  • Sending objects over the network
  • Persistence
  • Deepcopy objects trees
  • ?

In fact the interesting thing about Java object serialization is that you can use either the standard serialization mechanism, which transforms data from objects into binary representations, or customize it by implementing methods from the Serializable interface. In addition to that you can read data of your object and serialize it "by hand", i.e. read the values and transform them into whatever format you want and however you want.

Have a look at the following resources:

lewap
Did you mean to put something where the question mark is?
Bob Cross
No, I was just wondering what the other use-cases of serialization might be. Do you have an idea?
lewap
+3  A: 

Basically it's a way of saving the data stored in an object, e.g. to disk or to transmit across a network. The object can then be reconstructed later.

Jon Skeet
A: 

Not technical: serialization is the process of streaming a memory based structure (like an object which lives normaly in the main memory) to something persistent, usualy hard disk. Therefor you map the structure of the object into something like XML perhaps.

Mork0075
+1  A: 

Object serialization is the process of saving an object's state to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time.

Here's an article that discusses the Secrets of the Java Serialization

TStamper
+2  A: 

The simplest way to explain it is this:

Serialization is a way to take the objects in your application and describe them in some permanent format (binary, xml, etc.).

Once Serialized, you can store the indefinitely...send them over the wire...read them back in later...use your imagination.

Justin Niessner
+1  A: 

There is a very good summary here in another Stack Overflow question. To quote the accepted answer:

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link. The byte stream can then be deserialised - converted into a replica of the original object.

Bob Cross