java 序列化对象,Java序列化对象与非序列化对象

1) Can a non-serialised java object be sent over the network to be executed by another JVM or stored in local file storage to get the data restored?

2) What is the difference between serialising and storing the java object vs storing the java object without serialising it?

解决方案

Serialization is a way to represent a java object as a series of bytes. Its just a format nothing more.

A "build-in" java serialization is a class that provides an API for conversion of the java object to a series of bytes. That's it. Of course, deserialization is a "complementary" process that allows to convert this binary stream back to the object.

The serialization/deserialization itself has nothing to do with the "sending over the network" thing. Its just convenient to send a binary stream that can be created from the object with the serialization.

Even more, sometimes the built-in serialization is not an optimal way to get the binary stream, because sometimes the object can be converted by using less bytes.

So you can use you're custom protocol, provide your own customization for serialization (for example, Externalizable)

or even use third party libraries like Apache Avro

I think this effectively answers both of your questions:

You can turn the non-serialized object (I guess the one that doesn't implement "Serializable" interface) to the series of bytes (byte stream) by yourself if you want and then send it over the network, store in a binary file, whatsoever.

Of course you'll have to understand how to read this binary format for converting back.

Since serialization is just a protocol of conversion and not a "storage related thing", the answer is obvious.

Hope this helps.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值