When two processes perform remote communication, they can send different types of data to each other. Regardless of the type of data, it is transmitted on the network in the form of binary sequence. The sender needs to convert the Java object into a byte sequence before it can be transmitted over the network. The receiver needs to restore the byte sequence to a Java object.
The process of converting a Java object to a byte sequence is called object serialization.
The process of restoring a byte sequence to a Java object is called object deserialization.
Object serialization has two main purposes:
1) the object's byte sequence is permanently stored on the hard disk, usually stored in a file;
2) transmits the object's byte sequence over the network.
I. serialization API in JDK class library
Java. io. ObjectOutputStream represents the Object output stream. Its writeObject (Object obj) method can serialize the obj Object specified by the parameter and write the obtained byte sequence to a target output stream.
Java. io. ObjectInputStream indicates the input stream of the object, its readObje