1.java object serialization, saving only the object's type information and property type and property values, three parts of the data. The method in the object, no matter how many, is not serialized.
Package Com.hs.javafan; Import java.io.Serializable; public class Serializableobject implements Serializable {private string name, private int age, private string address, PU Blic String GetName () {return name.} public void SetName (String name) {this.name = name.} public int getage () {return Age public void Setage (int age) {this.age = age;} public string toString () {return ' Test ';} public string getaddress () { return address; public void setaddress (String address) {this.address = address;}}
Remove:
Public String toString () {
return "Test";
}
Package Com.hs.javafan; Import java.io.Serializable; public class Serializableobject implements Serializable {private string name, private int age, private string address, PU Blic String GetName () {return name.} public void SetName (String name) {this.name = name.} public int getage () {return Age public void Setage (int age) {this.age = age;} public String getaddress () {return address;} public void Setaddress (St Ring address) {this.address = address;}}
Package Com.hs.javafan; Import java.io.FileNotFoundException; Import Java.io.FileOutputStream; Import java.io.IOException; Import Java.io.ObjectOutputStream; public class Serializabletest {/** * @param args */public static void main (string[] args) {Serializableobject Serializa Bleobject = new Serializableobject (); Serializableobject.setname ("Kaiserfan"); Serializableobject.setage (30); Serializableobject.setaddress ("Hangzhou"); try {fileoutputstream out = new FileOutputStream ("test.txt"); ObjectOutputStream objectout = new ObjectOutputStream (out); Objectout.writeobject (Serializableobject); Out.close (); Objectout.close (); catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();}} }
The file size result is the same.
Regardless of how many methods are added to the Serializableobject object, serialization saves only the object type, the property type, and the property value, which three data information.