File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Serializable Method contains Any method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Serializable Method contains Any method" Watch "Serializable Method contains Any method" New topic
Author

Serializable Method contains Any method

Rajendra Prakash
Ranch Hand

Joined: Sep 10, 2009
Posts: 293
I read serializable interface has no methods.Then how we can override readObject() and writeObject() methods.
Except Serializable and Externalizable interface can we do serialization.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4420
    
    8

You aren't overriding readObject(), you're just providing it. If it's there then it's used, if it's not then the default behaviour is used (which basically involves trying to serialize every member variable that's not marked transient).

If Serializable declared the methods then you'd have to implement them. This way you only implement them when you need to (which is usually when you want to serialize a member variable that's not serializable).
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

Rajendra Prakash wrote:I read serializable interface has no methods.Then how we can override readObject() and writeObject() methods.

The interface has no methods nor any fields but serves only to identify the semantics of being serializable. Check out the Marker Interface.

Except Serializable and Externalizable interface can we do serialization.

There are many other ways like XStream, XmlEncoder etc

http://muhammadkhojaye.blogspot.com/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serializable Method contains Any method