`
中国爪哇程序员
  • 浏览: 167899 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

序列化(一)英文API

    博客分类:
  • java
阅读更多
JDK Serializable 描述

/**
* Serializability of a class is enabled by the class implementing the
* java.io.Serializable interface. Classes that do not implement this
* interface will not have any of their state serialized or
* deserialized.  All subtypes of a serializable class are themselves
* serializable.  The serialization interface has no methods or fields
* and serves only to identify the semantics of being serializable. <p>
*
* To allow subtypes of non-serializable classes to be serialized, the
* subtype may assume responsibility for saving and restoring the
* state of the supertype's public, protected, and (if accessible)
* package fields.  The subtype may assume this responsibility only if
* the class it extends has an accessible no-arg constructor to
* initialize the class's state.  It is an error to declare a class
* Serializable if this is not the case.  The error will be detected at
* runtime. <p>
*
* During deserialization, the fields of non-serializable classes will
* be initialized using the public or protected no-arg constructor of
* the class.  A no-arg constructor must be accessible to the subclass
* that is serializable.  The fields of serializable subclasses will
* be restored from the stream. <p>
*
* When traversing a graph, an object may be encountered that does not
* support the Serializable interface. In this case the
* NotSerializableException will be thrown and will identify the class
* of the non-serializable object. <p>
*
* Classes that require special handling during the serialization and
* deserialization process must implement special methods with these exact
* signatures: <p>
*
* <PRE>
* private void writeObject(java.io.ObjectOutputStream out)
*     throws IOException
* private void readObject(java.io.ObjectInputStream in)
*     throws IOException, ClassNotFoundException;
* private void readObjectNoData()
*     throws ObjectStreamException;
* </PRE>
*
* <p>The writeObject method is responsible for writing the state of the
* object for its particular class so that the corresponding
* readObject method can restore it.  The default mechanism for saving
* the Object's fields can be invoked by calling
* out.defaultWriteObject. The method does not need to concern
* itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput.
*
* <p>The readObject method is responsible for reading from the stream and
* restoring the classes fields. It may call in.defaultReadObject to invoke
* the default mechanism for restoring the object's non-static and
* non-transient fields.  The defaultReadObject method uses information in
* the stream to assign the fields of the object saved in the stream with the
* correspondingly named fields in the current object.  This handles the case
* when the class has evolved to add new fields. The method does not need to
* concern itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput.
*
* <p>The readObjectNoData method is responsible for initializing the state of
* the object for its particular class in the event that the serialization
* stream does not list the given class as a superclass of the object being
* deserialized.  This may occur in cases where the receiving party uses a
* different version of the deserialized instance's class than the sending
* party, and the receiver's version extends classes that are not extended by
* the sender's version.  This may also occur if the serialization stream has
* been tampered; hence, readObjectNoData is useful for initializing
* deserialized objects properly despite a "hostile" or incomplete source
* stream.
*
* <p>Serializable classes that need to designate an alternative object to be
* used when writing an object to the stream should implement this
* special method with the exact signature: <p>
*
* <PRE>
* ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
* </PRE><p>
*
* This writeReplace method is invoked by serialization if the method
* exists and it would be accessible from a method defined within the
* class of the object being serialized. Thus, the method can have private,
* protected and package-private access. Subclass access to this method
* follows java accessibility rules. <p>
*
* Classes that need to designate a replacement when an instance of it
* is read from the stream should implement this special method with the
* exact signature.<p>
*
* <PRE>
* ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
* </PRE><p>
*
* This readResolve method follows the same invocation rules and
* accessibility rules as writeReplace.<p>
*
* The serialization runtime associates with each serializable class a version
* number, called a serialVersionUID, which is used during deserialization to
* verify that the sender and receiver of a serialized object have loaded
* classes for that object that are compatible with respect to serialization.
* If the receiver has loaded a class for the object that has a different
* serialVersionUID than that of the corresponding sender's class, then
* deserialization will result in an {@link InvalidClassException}.  A
* serializable class can declare its own serialVersionUID explicitly by
* declaring a field named <code>"serialVersionUID"</code> that must be static,
* final, and of type <code>long</code>:<p>
*
* <PRE>
* ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
* </PRE>
*
* If a serializable class does not explicitly declare a serialVersionUID, then
* the serialization runtime will calculate a default serialVersionUID value
* for that class based on various aspects of the class, as described in the
* Java(TM) Object Serialization Specification.  However, it is <em>strongly
* recommended</em> that all serializable classes explicitly declare
* serialVersionUID values, since the default serialVersionUID computation is
* highly sensitive to class details that may vary depending on compiler
* implementations, and can thus result in unexpected
* <code>InvalidClassException</code>s during deserialization.  Therefore, to
* guarantee a consistent serialVersionUID value across different java compiler
* implementations, a serializable class must declare an explicit
* serialVersionUID value.  It is also strongly advised that explicit
* serialVersionUID declarations use the <code>private</code> modifier where
* possible, since such declarations apply only to the immediately declaring
* class--serialVersionUID fields are not useful as inherited members. Array
* classes cannot declare an explicit serialVersionUID, so they always have
* the default computed value, but the requirement for matching
* serialVersionUID values is waived for array classes.
*
* @author  unascribed
* @version 1.25, 11/17/05
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @see java.io.ObjectOutput
* @see java.io.ObjectInput
* @see java.io.Externalizable
* @since   JDK1.1
分享到:
评论

相关推荐

    jdk1.5 api 英文 part2

    `java.io.Serializable`接口标记一个类可以被序列化。这个文件通常包含了类如何序列化的详细信息,包括字段的顺序和类型,这对于理解和恢复序列化数据至关重要。 2. **常量值(Constant Values)** `constant-...

    tensorflow api 英文版

    TensorFlow API英文版是针对开发者提供的官方文档,其中包含了构建数据流图(Graphs)、操作(Operation)和张量(Tensor)等核心组件的详细说明。 构建数据流图是TensorFlow工作的基础。数据流图由节点(Node)...

    JDK1.4.2官方英文API

    - `java.io.ObjectInputStream`和`ObjectOutputStream`支持序列化流的版本控制。 这些知识点构成了JDK 1.4.2的核心特性,对于那些需要兼容旧版本或者研究Java历史演进的开发者来说,官方API文档是非常宝贵的参考...

    Java API英文版

    9. **反射**: Java反射API允许程序在运行时动态地获取类的信息并操作类的对象,这是许多高级功能(如序列化、动态代理)的基础。 10. **泛型**: 泛型引入于Java 5,增强了类型安全性,允许在编译时检查类型。...

    SwingX api 帮助文档

    这对于理解和实现持久化或网络传输非常重要,因为SwingX的一些组件可能涉及到对象的序列化。 `overview-tree.html`展示了库中所有类的层次结构,以树形结构列出,帮助开发者快速定位和理解类之间的关系。这对于理解...

    java1.7-API-英文版

    4. **I/O流**:Java 7的`java.io`包中,流类如`FileInputStream`和`FileOutputStream`用于文件操作,`BufferedReader`和`PrintWriter`用于文本读写,`ObjectInputStream`和`ObjectOutputStream`则支持对象的序列化和...

    jdk api(英文+中文)

    3. **I/O流**:如`java.io`,支持文件读写、网络数据传输、对象序列化等。 4. **网络编程**:如`java.net`,提供套接字、URL、URI等网络通信相关类。 5. **多线程**:如`java.lang.Thread`和`java.util.concurrent`...

    apache api

    Avro API提供了数据模式定义和数据序列化/反序列化的功能,支持动态类型。 理解Apache API的关键在于熟悉每个组件的核心概念、接口和类。通过阅读英文版的API文档,开发者可以获得详细的方法描述、参数说明和示例...

    JavaAPI(官方英文版)

    这个"Java API(官方英文版)"很显然是官方提供的文档,详细阐述了Java API中的每一个类、接口、方法和枚举,是Java程序员不可或缺的参考资料。 在Java API文档中,你可以找到以下关键知识点: 1. **包(Package)**...

    Jdk中文API第一部分

    中文API文档是为了解决英文API阅读困难,方便中国开发者理解Java类库中的各种类、接口和方法。 在给定的压缩包文件中,我们有以下几个关键文件: 1. `serialized-form.html`: 这个文件通常用于描述Java对象序列化...

    Tweener的SWC、AS文件和英文API

    Tweener是一款强大的动画库,尤其在ActionScript 3(AS3)开发中广泛应用,用于创建平滑的过渡效果和复杂的动画序列。它允许开发者轻松地在不同属性之间进行缓动,包括对象的位置、大小、颜色等。Tweener不仅支持...

    JAVA-EE-api-5.0-中英文对照经理版.chm.7z

    10. **JAXB(Java Architecture for XML Binding)**:JAXB用于XML和Java对象之间的转换,方便XML数据的序列化和反序列化。 这个“JAVA-EE-api-5.0-中英文对照经理版”的文档是学习和开发Java EE 5.0应用的重要参考...

    java jdk 1.8 api 中文英文版

    Stream API是Java 8中的新特性,提供了一种序列处理数据的方式,支持集合操作的并行化。通过`stream()`方法,我们可以对集合进行操作,如过滤、映射、查找、排序等。这使得处理大量数据变得更加高效且易于理解。 3...

    redis2.8+jedis2.5+jedis英文api

    Redis是一款高性能的键值对数据库,常用于缓存和数据持久化。它的高效性得益于其内存存储特性,但同时也提供了可选的持久化机制来保证数据安全。在本压缩包中,包含的是Redis 2.8版本,适用于Windows 64位操作系统。...

    Cocos2dx 3.2 3.6 英文API 中文API

    这个压缩包包含的是Cocos2d-x版本3.2和3.6的英文与中文API文档,方便开发者查阅和理解框架的各种功能。以下是这些版本中一些核心知识点的详细解释: 1. **Cocos2d-x架构**: Cocos2d-x是基于C++的,它提供了面向...

    最全,最新,j2ee中文api

    Java 7中文API是官方英文API的中文翻译版,对于那些英语阅读能力有限或者希望更快速理解API的开发者来说,是一份非常实用的参考资料。 **CHM 文件格式** CHM是Microsoft的Compiled HTML Help文件格式,它将HTML...

    JDK7-API-帮助文档(英文版完整版)

    **此“JDK7-API-帮助文档(英文版完整版)”是一个离线版的官方文档,包含了Java 7的所有公共类和接口的详细信息,对于学习和查阅Java 7的API非常有用。** **文档中包含的主要文件有:** 1. **stylesheet.css** - ...

    JDK1.8 API 中文 英文 高清完整CHM版

    2. **Stream API**:Stream API为处理集合提供了新的方式,支持序列化操作,可以进行高效且易于理解的并行操作。它非常适合数据聚合操作,如查找、过滤、映射和归约。 3. **方法引用**:方法引用允许直接引用已有...

    hibernate annotaion api 中文与英文版

    Hibernate是一个流行的Java持久化框架,它允许开发者将对象模型映射到关系数据库,极大地简化了数据库操作。在Hibernate中,注解(Annotation)API是一种声明式的方法,用于定义对象-关系映射(ORM)。让我们深入...

    HttpClient4.2.3API(英文)

    - `serialized-form.html`:序列化形式的类描述。 - `overview-summary.html`:概述摘要。 - `help-doc.html`:帮助文档,介绍如何使用API文档。 以上是HttpClient 4.2.3 API的核心功能和相关知识点。开发者可以...

Global site tag (gtag.js) - Google Analytics