Basic concepts of object serialization
Almost as long as it is java development, there must be a concept of serialization, and because the concept of serialization has gradually developed, there will be more serialization annotations gradually.
The basic definition of serialization: The objects stored in the memory are processed in the form of a binary data stream, which can realize the storage of the objects or network transmission.
However, not all objects can be serialized. There is a mandatory requirement in Java: If you want to serialize an object, the class where the object is located must implement the java.io.Serializable parent interface as a serialization mark. This interface has no methods, it describes the capabilities of a class.
Example: Define a class that can be serialized
class Person implements Serializable{ //Person类可以被序列化
private String name;
private int age;
public Person(String name,int age){
this.name = name ;
this.age = age;
}
@Override
public String toString(){
return "姓名:"+this.name+"、年龄:"+this.age;
}
}
At this time, every object generated by Person can realize binary data transmission and belongs to a program class that can be serialized.