A summary of the Java Foundation-serializable Serialization Learning

Source: Internet
Author: User

First, the Java Foundation-serializable serialization solves what problem

1, Java object to achieve data persistence through IO stream, or read and write to the hard disk must be serialized, if not serialized will throw Java.io.notserializableexception,java implementation of serialization, there are two ways to implement Serializable (no code required) interface or externalizable (requires writing 2 empty methods).

Ii. What problems may be encountered with Java serialization

1, a object refers to the B object, if you want the serial number a object must serialize the B object, and so on.

2. Invalid serialization to create a parameterless construction method.

3, after serializing an object B, a object refers to B, serializes a object, or B object properties modified after the B object is serialized, the B object is deserialized, familiar unchanged, the Java serialization mechanism all objects are serialized only once, no matter how many times after he was serialized, All deserialization gets the first serialized B object.

4, for special characters need to be safe and confidential, can be serialized at the time of the addition of custom serialization, custom serialization of the way there are several, 1. You can use the transient keyword so that there are not many corresponding values for deserialization, that is, the field will not be serialized, or you can write WriteObject ReadObject Method (these two methods can use encryption algorithm and decryption algorithm to encrypt the important data, so that people can not obtain the important confidential information after deserialization) or the replication Writereplace, this method returns a list.

Third, the use of serialization considerations

1. Objects and properties can be serialized, methods, static properties, and transient properties are not serialized.

A summary of the Java Foundation-serializable Serialization Learning

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.