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