1. What is serialization?
This is simply to preserve the state of various objects in memory (i.e., instance variables, not methods), and to read the saved object state again. Although you can save object states in a variety of ways, Java provides you with a mechanism that should be better than your own to preserve the state of objects, which is serialization.
2. What situations require serialization
A) When you want to save the state of an object in memory in a file or in a database;
b) When you want to use sockets to transfer objects on the network;
c) When you want to transfer objects through RMI;
3, the related matters needing attention
A) When serializing, only the state of the object is saved, regardless of the object's method;
b) When a parent class is serialized and the subclass is automatically serialized, no explicit implementation of the serializable interface is required;
c) When an instance variable of an object refers to another object, the object is serialized as well.
D) Not all objects can be serialized, and there are a number of reasons why not, such as:
1. Security reasons, such as an object has Private,public and other fields, for a transmission of the object, such as writing to a file, or RMI transmission, etc., during the serialization of the transfer process, the object's private domain is not protected.
2. Resource allocation reasons, such as the Socket,thread class, can be serialized, transmitted or saved, and cannot be re-allocated, and there is no need to implement this.
Serialization in Java