views:

66

answers:

3

What is the meaning of serialization concept in programming languages?

when we use Serializable attribute above a class, what is the meaning?

+5  A: 

There is no better explanation than the one from wikipedia.

In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link to be "resurrected" later in the same or another computer environment.

http://en.wikipedia.org/wiki/Serialization

Also, the Serializable Attribute cannot be used on methods. Indicated by the Attribute Usage

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Delegate, Inherited = false)]
PieterG
+1  A: 

Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes.

Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.

more about this : http://www.allinterview.com/showanswers/20627.html

Pranay Rana
+2  A: 

Say you have two application that run on two different physical machines. Both the application need to exchange data that is commonly used by both the application. These application talk to each other to share the data with some mediums, these mediums could be file-system, tcp or udp connections or any other suitable network protocol or may be directly in memory data exchange. Any of these mediums would only understand data that is described in form of series of bits. So when one application need to send a value 10 to another, the value 10 would be sent as its binary representation 1010 and you will also pass some information that describes what is 1010, this meta information will also be a series of bits that the other application can very well understand. That was easy though.

Lets take another example, wherein these two apps need to exchange a more complex, non primitive data-type. Lets say they need to exchange the objects of type Book where Book is a custom defined class in your application and both the applications have the definition of type Book.

public class Book
{
    Book() { }

    public long BookId { get;set; }
    public string Author { get;set; }
    public string Title { get;set; }
}

How will you exchange the objects of type book between the two applications ? To be able to share the object between two apps, you will need to be able to convert the Book objects into binary representation. This is where serialization come into picture.

With the help of Serialization you can define, how an object can be converted into its binary representation. The receiving application would do reverse process that is De-Serialization, that constructs a Book object from its binary representation.

this. __curious_geek
Thank you very much for your complete answer.
masoud ramezani