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