9 Replies Latest reply: May 24, 2007 4:27 PM by 807606 RSS

    implements Serializable

      I saw many classes "implements Serializable". What type of class (for what usage), must "implements Serializable"?


        • 1. Re: implements 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.

          • 2. Re: implements Serializable
            Thanks for the help.

            Actually I need some explanation which is more entry-level based, and better yet in layman's wording, or some examples and usages.

            • 3. Re: implements Serializable
              Quick demo of "implements Serializable" versus not:
              import java.io.*;
              class S implements Serializable {}
              class NotS {}
              public class SerializableTest {
                  public static void main(String[] args) {
                      test(new S());
                      test(new NotS());
                  static void test(Object o) {
                      try {
                          ByteArrayOutputStream baos = new ByteArrayOutputStream(); //just for a sink
                          ObjectOutputStream out = new ObjectOutputStream(baos);
                      } catch (IOException e) {
              • 4. Re: implements Serializable
                I'll giveyou a quick break down, since I just got done wrangling it myself.

                Serializable basically means that that class can be written to a file. If you don;t include it, it can't be translated and encrypted. It's used with pretty much all I/O (Input/Output) applications.
                • 5. Re: implements Serializable
                  Serializable basically means that that class can be
                  written to a file.
                  to be a bit more clear, it actually turns the object into a byte stream.
                  that in turn can be written to a file or transmitted over a network, etc.
                  • 6. Re: implements Serializable
                    Thank you all for the help.

                    But one thing. I saw in some application, it has something like this:

                    public class TestForm implements Serializable {

                    List testList;
                    String test;


                    But I did not find corresponding OutputStream and InputStream (to serialize and deserialize the object). Any idea why the TestForm (a form bean class) need to implements the Serializable? What if it does not implements the Serializable?


                    • 7. Re: implements Serializable
                      Perhaps the serialization was being done behind the scenes by an application framework.
                      • 8. Re: implements Serializable
                        This application will interface with a database. So all the persistent changes will be saved to a database. It does not need to use the Serialized form bean to store the data.

                        So actually I am thinking this form bean unnecessarily implmented the Serializable.

                        • 9. Re: implements Serializable
                          My crystal ball is a little foggy, but you could be right.