Java Interview Questions How to implement serialization in Java and what's the point?

How to implement serialization in Java and what's the point?

Answer: Serialization is a mechanism for processing object streams. The so-called object stream is to stream the content of objects. You can read and write the streamed objects, and you can also transfer the streamed objects to the network. In order to solve the problems that may be caused when the object stream is read and written during serialization (if serialization is not performed, there may be a problem of data disorder). To achieve serialization, you need to make a class implement the Serializable interface, which is an identifying interface, mark that the object of this class can be serialized, and then use an output stream to construct an object output stream and pass the writeObject(Object) method You can write out the object (that is, save its state); if you need to deserialize it, you can use an input stream to create an object input stream, and then read the object from the stream through the readObject method. In addition to achieving object persistence, serialization can also be used for deep cloning of objects.

Guess you like

Origin blog.csdn.net/weixin_44296929/article/details/108346561