Serialization of Java objects (serialization object)

Source: Internet
Author: User

Official documents: https://docs.oracle.com/javase/tutorial/jndi/objects/serial.html

Excellent blog:

Http://www.cnblogs.com/gw811/archive/2012/10/10/2718331.html

Http://www.cnblogs.com/vicenteforever/articles/1471775.html

Interface code:

1  Package java.io; 2 3  Public Interface Serializable {4 }

Concept: Serialization is the conversion of an object into a byte stream, and it can also be converted from a byte stream into a copy of the original object.

Note: after an object is serialized, all its child class objects are also automatically serialized.

When a class declares that it is implementing the Serializable interface, it simply indicates that the class participates in the serialization protocol and does not need to implement any special methods.

To serialize an object, you must first create a outputstream and then insert it into the objectoutputstream. At this point, the object can be written to OutputStream using the WriteObject () method.

The WriteObject () method is responsible for writing the state of an object of a particular class so that the corresponding ReadObject () method can restore it. By calling Out.defaultwriteobject, you can invoke the default mechanism of the field that holds the Object. The method itself does not need to involve states that belong to its superclass or subclass. The state is saved by writing the fields to ObjectOutputStream by using the WriteObject method or by using DataOutput supported methods for the base data type.

Serialization of Java objects (serialization object)

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.