What is Java serialization and how to implement Java serialization? Alternatively, explain the functions of the serializable interface.

Source: Internet
Author: User

We sometimes convert a Java object into a byte stream or restore it to a Java object from a byte stream. For example, to store Java objects to hard disks or transmit them to other computers on the network, we can write this process by ourselves.CodeTo convert a Java object into a byte stream of a certain format for re-transmission. However, JRE itself provides this support. We can call the writeobject method of outputstream to do this, if you want Java to help us, the object to be transmitted must implement the serializable interface, so that special processing will be performed during javac compilation, and the compiled class can be operated by the writeobject method, this is the so-called serialization. The class to be serialized must implement the serializable interface, which is a mini interface with no implementation method, implements
Serializable is only used to indicate that the object can be serialized.

 

 

For example, in web development, if an object is stored in a session, Tomcat will serialize the session object to the hard disk during restart, and the object must implement the serializable interface. If the object needs to be transmitted over the network or remotely called through RMI in the distributed system, the object needs to be transmitted over the network, and the transmitted object must implement the serializable interface.

Related Article

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.