The concept of the serialization of Java objects

Source: Internet
Author: User

The concept of the serialization of Java objects

Serialization is the process of converting an object's state information to a storage or transport, and when serialized, the object writes the current state to a temporary or persistent store.

The concept of a Java object serialization

1. The concept of serialization is the idea of converting an object directly into a byte stream to a hard disk or spread over a network. The Java serialization technique can write the state of an object into a byte stream, and can read the data from that byte stream elsewhere and reconstruct the same object. This mechanism allows objects to be propagated through the network and can be persisted to the database, files and other systems at any time. The Java serialization mechanism is the technical foundation of RMI, EJB and other technologies.

2. Serialization is a mechanism for dealing with object flow, which is the flow of object content. It is possible to read and write to a Fluidized object, or to transfer the streamed object between the networks. Serialization is a problem that is raised when reading and writing to an object stream.

twonote points for serialization

Note 1.
If a class can be serialized, its subclasses can also be serialized. If the class has a parent class, it is considered in two cases if the parent class has implemented a serializable interface. The corresponding fields and properties of the parent class are treated the same as the class, and if the parent class of the class does not implement a serializable interface, all field properties of the class's parent class will not be serialized

Note 2.
member data declared as static and transient types cannot be serialized. Because static represents the state of a class, transient represents the temporary data for the object

Note 3.
The classes and interfaces provided in the java.io package that involve the serialization of objects have

ObjectOutput interface
The interface inherits the DataOutput interface and supports serialization of the object, and its WriteObject () method implements the storage of an object.

ObjectInput interface
The interface inherits the Datainput interface and supports serialization of the object, and its ReadObject () method implements reading an object.

ObjectOutputStream class
This class inherits the OutputStream class and implements the ObjectOutput interface, which invokes the WriteObject method in the interface.

ObjectInputStream class.
This class inherits the InputStream class and implements the ObjectInput interface, which invokes the ReadObject method in the interface.

。

Note 4.
When processing a parent class, if the parent class does not implement a serialization interface, it must have a default constructor, or it will be compiled with an error. At the time of deserialization, the default constructor is called. If the parent class is marked as serializable, its default constructor is not called when deserializing. Because Java deserializes a serialized object, it takes its object data directly from the stream to generate an object instance instead of its constructor.

The concept of the serialization 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.