1. Today `s Famous quotes
Nothing is impossible as long as it is possible
Serializable :
1.Its a varification code between two files
2.Its keep your file guaranteed security(安全性), and its very defalut for eclipse and Java,its must be.
3.If you didnt set SerialSVersionUID and the jvm will set the Defalut UID for you .
There are two king of SerialVersionUID here , first is defalut UID and notdefalut UID.
Example :
//Serializable Example one
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(st);
oos.flush();
oos.close();
fos.close();
//Seralizbale Example two
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("my.out"));
MyTest myTest=new MyTest();
oos.writeObject(myTest);
oos.flush(); //BufferedIO
oos.close(); // close
private static final long serialVersionUID = 1L; and
private static final long serialVersionUID = -1172613597422125119L;
//Deserializable
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
Student st1 = (Student) ois.readObject();
System.out.println("name = " + st1.getName());
System.out.println("sex = " + st1.getSex());
System.out.println("year = " + st1.getYear());
System.out.println("gpa = " + st1.getGpa());
ois.close();
fis.close();
4. There is another interface for Serializable , Externalizable
Example :
void writeExternal(ObjectOutput out) throws IOException;
void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
public interface Externalizable extends java.io.Serializable {
/**
* The object implements the writeExternal method to save its contents
* by calling the methods of DataOutput for its primitive values or }
Note : 1.When subclass implement serializable , and supclass shouldnt implement Serializable.
2。static , transient cant implements Serializable interface.
Serializable is very simple that you just implements Serializable.that is OK! Good luck!
Iparhan_Java 2016-6-22
Nothing is impossible as long as it is possible
Serializable :
1.Its a varification code between two files
2.Its keep your file guaranteed security(安全性), and its very defalut for eclipse and Java,its must be.
3.If you didnt set SerialSVersionUID and the jvm will set the Defalut UID for you .
There are two king of SerialVersionUID here , first is defalut UID and notdefalut UID.
Example :
//Serializable Example one
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(st);
oos.flush();
oos.close();
fos.close();
//Seralizbale Example two
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("my.out"));
MyTest myTest=new MyTest();
oos.writeObject(myTest);
oos.flush(); //BufferedIO
oos.close(); // close
private static final long serialVersionUID = 1L; and
private static final long serialVersionUID = -1172613597422125119L;
//Deserializable
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
Student st1 = (Student) ois.readObject();
System.out.println("name = " + st1.getName());
System.out.println("sex = " + st1.getSex());
System.out.println("year = " + st1.getYear());
System.out.println("gpa = " + st1.getGpa());
ois.close();
fis.close();
4. There is another interface for Serializable , Externalizable
Example :
void writeExternal(ObjectOutput out) throws IOException;
void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
public interface Externalizable extends java.io.Serializable {
/**
* The object implements the writeExternal method to save its contents
* by calling the methods of DataOutput for its primitive values or }
Note : 1.When subclass implement serializable , and supclass shouldnt implement Serializable.
2。static , transient cant implements Serializable interface.
Serializable is very simple that you just implements Serializable.that is OK! Good luck!
Iparhan_Java 2016-6-22