I. The concept of serialization and deserialization
The process of converting an object to a sequence of bytes is called the serialization of an object.
The process of reverting a sequence of bytes to an object is called an object's deserialization
Main uses for object serialization:
1) The object's byte sequence is permanently saved to the hard disk, usually placed in a file;
2) A sequence of bytes that transmits an object over the network.
In many applications, some objects need to be serialized, so that they leave the memory space, to stay in the physical hard disk for long-term storage, such as the most common is the Web server session object, when there are 100,000 users concurrent access, there may be 100,000 session objects, memory may be unbearable , the Web container will serialize some sessions to the hard disk, wait for it to be used, and then restore the objects stored on the hard disk to memory.
When two processes in the remote communication, each other can send various types of data, regardless of the type of data, will be in the form of binary sequence on the network, the sender needs to convert the Java object to a sequence of bytes, to be transferred on the network, the receiver will need to restore the byte sequence to Java objects.
Second, the serialization API in the JDK class library
Java.io.ObjectOutputStream represents an object output stream, and its writeobject (object obj) method serializes the Obj object specified by the parameter and writes the resulting sequence of bytes to a target output stream.
Java.io.ObjectInputStream represents an object input stream, and its readobject () method reads a sequence of bytes from a source input stream, serializes them into an object, and returns them.
Java Basic Learning summarizes serialization and deserialization of--java objects