Demo源码:
https://gitlab.com/caiqiqi/Java_Serialization
为什么要进行Java对象的序列化
参考:
http://www.hollischuang.com/archives/1140
Java平台允许我们在内存中创建可复用的Java对象,但一般情况下,只有当JVM处于运行时,这些对象才可能存在,即,这些对象的生命周期不会比JVM的生命周期更长。但在现实应用中,就可能要求在JVM停止运行之后能够保存(持久化)指定的对象,并在将来重新读取被保存的对象。Java对象序列化就能够帮助我们实现该功能。
➜ ~/GitProjects/Java_Serialization javac *.java
➜ ~/GitProjects/Java_Serialization java Serialization
➜ ~/GitProjects/Java_Serialization ls [1:56:37]
Deserialization.class Person.bin Person.java Serialization.java
Deserialization.java Person.class Serialization.class
➜ ~/GitProjects/Java_Serialization file Person.bin [1:56:38]
Person.bin: Java serialization data, version 5
➜ ~/GitProjects/Java_Serialization file Person.class [1:56:44]
Person.class: compiled Java class data, version 51.0 (Java 1.7)
➜ ~/GitProjects/Java_Serialization java Deserialization [1:56:51]
Person@454322ba
➜ ~/GitProjects/Java_Serialization javac Deserialization.java [1:58:08]
➜ ~/GitProjects/Java_Serialization java Deserialization [1:58:13]
Person@31955dd4
➜ ~/GitProjects/Java_Serialization vi Deserialization.java [1:58:17]
➜ ~/GitProjects/Java_Serialization javac Deserialization.java [1:59:28]
➜ ~/GitProjects/Java_Serialization java Deserialization [1:59:32]
Name: caiqiqiBirthDate: Thu Jan 01 08:00:04 CST 1970
➜ ~/GitProjects/Java_Serialization vi Deserialization.java [1:59:35]
➜ ~/GitProjects/Java_Serialization javac Deserialization.java [2:00:08]
➜ ~/GitProjects/Java_Serialization java Deserialization [2:00:15]
Name: caiqiqi
BirthDate: Thu Jan 01 08:00:04 CST 1970