Results 1 to 5 of 5
  1. #1
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default Implementing Serializable interface

    Please review the code below:

    Java Code:
    public class ClassA implements Serializable{
    ...}
    I implemented Serializable interface and wrote methods according to my requirement. I did not implement any method of Serializable interface. I know that when you implement an interface, you have to implement its methods. I can compile my class and no error are shown.

    Is this some special behavior of interface?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    7

    Default

    This is called as a marker interface, which is use to mark a class for serialization purposes. By implementing this interface Java know that this class can be serialized.

    Yes, you don't need to implement a method when create a class a serializable because the interface itself doesn't define any method. But there are some rules for creating a good serializable class, you can read it here: Implementing Serializable.

  3. #3
    javaplus is offline Member
    Join Date
    Nov 2007
    Posts
    97
    Rep Power
    0

    Default

    Thanks a dozen for making this clear.
    So, is this right to say that "marker interfaces" are those interfaces, that have no method in them.

  4. #4
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    7

    Default

    Well, not really I think. It can have methods or fields. For more information see here: Marker interface pattern - Wikipedia, the free encyclopedia

  5. #5
    jaykishan is offline Member
    Join Date
    Dec 2007
    Posts
    3
    Rep Power
    0

    Default

    It is also known as null interface....but still you may use readObject() and writeObject() method to serialize and deserialize object....

Similar Threads

  1. Implementing Interface
    By mew in forum New To Java
    Replies: 4
    Last Post: 02-16-2010, 03:33 PM
  2. Implementing an interface
    By bugger in forum Advanced Java
    Replies: 1
    Last Post: 01-09-2008, 01:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •