What is the meaning of serialization in programmin

2020-05-11 12:00发布

What is the meaning of serialization concept in programming languages?

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

5条回答
家丑人穷心不美
2楼-- · 2020-05-11 12:11

Serialization is the process in which data translating data structure or object state into a format that can be stored

查看更多
可以哭但决不认输i
3楼-- · 2020-05-11 12:13

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

查看更多
相关推荐>>
4楼-- · 2020-05-11 12:16

Say you have two applications that run on two different physical machines. Both of the applications need to exchange data that is commonly used by both applications. These application talk to each other to share the data with some mediums, these mediums could be a file-system, tcp or udp connections or any other suitable network protocol or may be direct in-memory data exchange. Any of these mediums would only understand data that is described in the form of a series of bits. So when one application needs to send a value 10 to another, the value 10 would be sent as its binary representation 1010 and you would also pass some information that describes 1010. This meta information will also be a series of bits that the other application can easily 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 comes into the picture.

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

查看更多
做自己的国王
5楼-- · 2020-05-11 12:16

Why do we need a serialization?

In procedural language such as Cobol or C there is no concept of serialization. Why do we then use it in OOP? Let us take Java. You have a class which is instantiating multiple classes called Objects, and you want to pass one of those objects state (current values of variables) over network through Message Oriented Middleware in the form of byte stream, and you need serialization and de-serialization. If multiple languages agree on this byte stream format, serialization can even provide a way for otherwise incompatible systems to exchange data.

查看更多
女痞
6楼-- · 2020-05-11 12:30

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)]
查看更多
登录 后发表回答