简体   繁体   English

实现可序列化的Java Transferable对象

[英]Java Transferable objects implementing serializable

If we need to transfer an Object across network we make the class implements Serializable . 如果我们需要跨网络传输一个Object,我们会让类实现Serializable。 Now my question is what difference does it make?How it all works? 现在我的问题是它有什么不同?它是如何工作的?

In brief, There are cases when you want to transfer an object but want not to transfer all the fields of the object. 简而言之,有些情况下您想要传输对象但又不想传输对象的所有字段。 Then you make the class implementing Serializable, that is a marker that any object of that class may be sent over a network. 然后,您使类实现Serializable,这是一个标记,可以通过网络发送该类的任何对象。 The fields inside the class that you want to to restrict from from transferring over network, mark them as transient with the keyword transient . 要限制的类中的字段不能通过网络传输,请使用关键字transient将其标记为瞬态 Those fields may have get default values on other end. 这些字段可能在另一端获得默认值。

You may see Serializable and transient for answer to why implement an interface in one place and keyword in other olac. 您可能会看到Serializable和transient可以回答为什么在一个地方实现接口而在其他olac中实现关键字。

For more details see documentation by oracle on Serializable 有关更多详细信息,请参阅oracle在Serializable上的文档

documentation by oracle on transient 由oracle提供的关于瞬态的文档

Thanks. 谢谢。

Below paragraph describes what Serilization is (Taken from book Effective Java). 下面的段落描述了什么是Serilization(摘自有效Java书)。

Serilization provides a framework for encoding objects as byte streams and reconstructing objects from their byte-stream encodings. Serilization提供了一个框架,用于将对象编码为字节流,并从字节流编码中重构对象。 Encoding an object as a byte stream is known as serializing the object; 将对象编码为字节流称为序列化对象; the reverse process is known as deserializing it. 反向过程称为反序列化。 Once an object has been serialized, its encoding can be transmitted from one running virtual machine to another or stored on disk for later deserialization. 一旦对象被序列化,其编码可以从一个正在运行的虚拟机传输到另一个或存储在磁盘上以便以后反序列化。 Serialization provides the standard wire-level object representation for remote communication, and the standard persistent data format for the JavaBeans component architecture. Serialization为远程通信提供标准的线级对象表示,为JavaBeans组件体系结构提供标准的持久数据格式。

You can read java docs or any other standard java book(for example Head First java) to know what Serilization is and how it works. 你可以阅读java文档或任何其他标准的Java书籍(例如Head First java)来了解Serilization是什么以及它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM