什么是Serialization序列化
”我们人类的生命是有限的,试想,如果有可能,将我们序列化将我们转化为byte,会存在于网络里、内存中,我们将无处不在,达到永生。“
Serialization 翻译为序列化,就是将一个Object序列化为series of bytes。
Deserialization翻译为去序列化,就是将series of bytes转化为Object。
Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent storage or streamed across a communication link.
Deserialization: a series of bytes converted into a replica of the original object.
参考
什么时候使用序列化
保存该Object
When we want to Persist the Object.
Object不会因为JVM的结束而消失
When we want the object to exist beyond the lifetime of the JVM.
其他JVM需要使用该Object
When we want object used by others JVM
网络传输Object中的数据
When we want to transfer the data inside of the object
序列化的作用
Persisting objects in java,将Object保存为本地文件以避免JVM lifetime结束时的消失
如果想保持一个live object的状态,我们可以将其序列化为一个本地文件,可以永久保存在memory、hardware、network中
冻结流动的水
如果需要使用object,可以再次将这个序列化的文件去序列化为一个live object就可以继续使用。
解冻冰
序列化的实际使用
ATM: When the account holder tries to withdraw money from the server through ATM, the account holder information like withdrawl details will be serialized and sent to server where the details are deserialized and used to perform operations.
当我们取款时,取款的信息将会序列化并且发送到服务器上,在服务器会去序列化并且执行相应的操作。
Q&A
为什么要对对象进行序列化
数据操作规范类似于还是等于XML文件,保证数据一致性和安全性
为什么不用参数传输数据而是传输序列化后的对象
参数所含有的信息 <= 对象所含有的信息
为什么要对对象进行序列化?为什么不直接用数据库来存储数据?
采用数据流来存储 ,以数据流传输会提高网络传输速度,在数据流进行操作可以直接操作数据流,少了对数据表进行操作的过程,减少数据出错的几率.
血与泪的教训:尽量不要对数据库进行操作
想要看到更多玮哥的学习笔记、考试复习资料、面试准备资料?想要看到IBM工作时期的技术积累和国外初创公司的经验总结?
敬请关注: