Java object serialization

Source: Internet
Author: User

Java object serialization requires the implementation of a Serializable interface, but the implementation of another interface also works, called Externalizable.

Only non-static member variables are serialized. If a referenced variable exists, the referenced variable must also implement the interface.

If you do not want to serialize a member variable, add the keyword transient before it.

If you want to operate serialization, serialize some members, or serialize some Members, you can complete serialization in your own class.

Write down the following method

Private void writeObject (java. io. ObjectOutputStream oos) throws IOException

{

}

Private void readObject (java. io. ObjectOutputStream oos) throws IOException

{

}

These two methods will be called during serialization. Www.2cto.com

These two methods are private. It is reasonable to say that they can only be called in the class. How can they be called outside the class?


 


Author: zhy_cheng

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.