Java Serialization Technology

Source: Internet
Author: User

What is the serialization and deserialization of Java? Why do I need serialization and deserialization? How do I implement the serialization and deserialization of Java?

Java Serialization refers to the process of converting a Java object to a sequence of bytes, while Java deserialization refers to the process of reverting a sequence of bytes to a Java object.

Why need to use to serialize, two different processes need remote communication;

Various types of data can be sent to each other, including text, pictures, audio, video, and so on, which are transmitted over the network in the form of a binary sequence. So when two Java processes are communicating, can we implement the inter-process object transfer? The answer is yes. How do we do that? This requires the serialization and deserialization of Java. In other words, on the one hand, the sender needs to convert the Java object to a sequence of bytes and then transfer it over the network, on the other hand, the receiver needs to recover the Java object from the sequence of bytes.

After we have clarified why Java serialization and deserialization are needed, we naturally think of the benefits of Java serialization. The advantage of this is the persistence of data, through serialization can be permanently saved to the hard disk (usually stored in the file), the second, the use of serialization to achieve remote communication, that is, the transmission of the object's byte sequence on the network.

How to implement the serialization of Java:

Native method: Implement serializable or Externalizable interface; (native disadvantage cannot achieve cross-platform, the number of bytes occupies a large)

Transient key type: The field is not serialized;

Private Transient String name;

1) Java serialization is the conversion of an object into a sequence of bytes, while the Java deserialization is the restoration of a sequence of bytes to a Java object.

2) The use of Java serialization and deserialization technology, one can achieve the persistence of data, in the MVC pattern is very useful, and the other is the object data can be remote communication.

Data types are often difficult to choose when transmitting data in the socket in Java. You may want to consider issues such as bandwidth, cross-language, version compatibility, and so on. There are two common approaches: one is to wrap the object into a JSON string transfer, and the other is to use the serialization and deserialization of the Java object.

Java Serialization Technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.