1. /*
  2. * @(#)Serializable.java 1.16 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.io;
  11. /**
  12. * Serializability of a class is enabled by the class implementing the
  13. * java.io.Serializable interface. Classes that do not implement this
  14. * interface will not have any of their state serialized or
  15. * deserialized. All subtypes of a serializable class are themselves
  16. * serializable. The serialization interface has no methods or fields
  17. * and serves only to identify the semantics of being serializable. <p>
  18. *
  19. * To allow subtypes of non-serializable classes to be serialized, the
  20. * subtype may assume responsibility for saving and restoring the
  21. * state of the supertype's public, protected, and (if accessible)
  22. * package fields. The subtype may assume this responsibility only if
  23. * the class it extends has an accessible no-arg constructor to
  24. * initialize the class's state. It is an error to declare a class
  25. * Serializable in this case. The error will be detected at runtime. <p>
  26. *
  27. * During deserialization, the fields of non-serializable classes will
  28. * be initialized using the public or protected no-arg constructor of
  29. * the class. A no-arg constructor must be accessible to the subclass
  30. * that is serializable. The fields of serializable subclasses will
  31. * be restored from the stream. <p>
  32. *
  33. * When traversing a graph, an object may be encountered that does not
  34. * support the Serializable interface. In this case the
  35. * NotSerializableException will be thrown and will identify the class
  36. * of the non-serializable object. <p>
  37. *
  38. * Classes that require special handling during the serialization and deserialization
  39. * process must implement special methods with these exact signatures: <p>
  40. *
  41. * <PRE>
  42. * private void writeObject(java.io.ObjectOutputStream out)
  43. * throws IOException
  44. * private void readObject(java.io.ObjectInputStream in)
  45. * throws IOException, ClassNotFoundException;
  46. * </PRE><p>
  47. *
  48. * The writeObject method is responsible for writing the state of the
  49. * object for its particular class so that the corresponding
  50. * readObject method can restore it. The default mechanism for saving
  51. * the Object's fields can be invoked by calling
  52. * out.defaultWriteObject. The method does not need to concern
  53. * itself with the state belonging to its superclasses or subclasses.
  54. * State is saved by writing the individual fields to the
  55. * ObjectOutputStream using the writeObject method or by using the
  56. * methods for primitive data types supported by DataOutput. <p>
  57. *
  58. * The readObject method is responsible for reading from the stream and restoring
  59. * the classes fields. It may call in.defaultReadObject to invoke
  60. * the default mechanism for restoring the object's non-static and non-transient
  61. * fields. The defaultReadObject method uses information in the stream to
  62. * assign the fields of the object saved in the stream with the correspondingly
  63. * named fields in the current object. This handles the case when the class
  64. * has evolved to add new fields. The method does not need to concern
  65. * itself with the state belonging to its superclasses or subclasses.
  66. * State is saved by writing the individual fields to the
  67. * ObjectOutputStream using the writeObject method or by using the
  68. * methods for primitive data types supported by DataOutput. <p>
  69. *
  70. * Serializable classes that need to designate an alternative object to be
  71. * used when writing an object to the stream should implement this
  72. * special method with the exact signature: <p>
  73. *
  74. * <PRE>
  75. * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
  76. * </PRE><p>
  77. *
  78. * This writeReplace method is invoked by serialization if the method
  79. * exists and it would be accessible from a method defined within the
  80. * class of the object being serialized. Thus, the method can have private,
  81. * protected and package-private access. Subclass access to this method
  82. * follows java accessibility rules. <p>
  83. *
  84. * Classes that need to designate a replacement when an instance of it
  85. * is read from the stream should implement this special method with the
  86. * exact signatute.<p>
  87. *
  88. * <PRE>
  89. * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
  90. * </PRE><p>
  91. *
  92. * This readResolve method follows the same invocation rules and
  93. * accessibility rules as writeReplace.
  94. *
  95. * @author unascribed
  96. * @version 1.16, 02/02/00
  97. * @see java.io.ObjectOutputStream
  98. * @see java.io.ObjectInputStream
  99. * @see java.io.ObjectOutput
  100. * @see java.io.ObjectInput
  101. * @see java.io.Externalizable
  102. * @since JDK1.1
  103. */
  104. public interface Serializable {
  105. }