Java Basic Learning summarizes serialization and deserialization of--java objects

Source: Internet
Author: User

I. The concept of serialization and deserialization

The process of converting an object to a sequence of bytes is called the serialization of an object.

The process of reverting a sequence of bytes to an object is called an object's deserialization

Main uses for object serialization:

1) The object's byte sequence is permanently saved to the hard disk, usually placed in a file;

2) A sequence of bytes that transmits an object over the network.

In many applications, some objects need to be serialized, so that they leave the memory space, to stay in the physical hard disk for long-term storage, such as the most common is the Web server session object, when there are 100,000 users concurrent access, there may be 100,000 session objects, memory may be unbearable , the Web container will serialize some sessions to the hard disk, wait for it to be used, and then restore the objects stored on the hard disk to memory.

When two processes in the remote communication, each other can send various types of data, regardless of the type of data, will be in the form of binary sequence on the network, the sender needs to convert the Java object to a sequence of bytes, to be transferred on the network, the receiver will need to restore the byte sequence to Java objects.

Second, the serialization API in the JDK class library

Java.io.ObjectOutputStream represents an object output stream, and its writeobject (object obj) method serializes the Obj object specified by the parameter and writes the resulting sequence of bytes to a target output stream.

Java.io.ObjectInputStream represents an object input stream, and its readobject () method reads a sequence of bytes from a source input stream, serializes them into an object, and returns them.

Java Basic Learning summarizes serialization and deserialization of--java objects

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.