aspose file tools*
The moose likes Java in General and the fly likes serializable interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "serializable interface" Watch "serializable interface" New topic
Author

serializable interface

S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Serializable interface is a "marker" interface .We know that marker interface has method , but when we impliment the serializable interface we use the readObject and writeObject methods.So from where these methods come ?

Thanks,
S
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

The writeObject and ReadObject are the part of ObjectOutputStream class


SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

s begri wrote:We know that marker interface has method



No the marker interface doesn't contains any methods
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

Shanky Sohar wrote:The writeObject and ReadObject are the part of ObjectOutputStream class

These are also private methods that a serializable class can optionally implement to have a bit more control over their serialization / deserialization.

s beqri, these methods are just there, as part of the serialization mechanism specification. They aren't defined by any interface or base class. They get special treatment because Sun said they should.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Thank you all
If the serializable interface has no method at all , so why should we implement it when we try to serialize an object ? We can use only the ObjectOutputStream class.

regards,
S
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Rob Spoor wrote:
Shanky Sohar wrote:The writeObject and ReadObject are the part of ObjectOutputStream class
These are also private methods that a serializable class can optionally implement to have a bit more control over their serialization / deserialization.


Yes you are right,but the methods are the part of ObjectOutputStream class,we are implementing them just to have a little more control over the serialization or deserilization.These methods are not within the serialization interface.
Please correct me if i am wrong
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Shanky Sohar wrote:Yes you are right,but the methods are the part of ObjectOutputStream class,we are implementing them just to have a little more control over the serialization or deserilization.These methods are not within the serialization interface.
Please correct me if i am wrong

We are NOT implementing the methods in ObjectOutputStream and ObjectInputStream. Those are different methods, with different signatures.

Method in ObjectOutputStream:

Method in ObjectInputStream:

Optional methods in the object to be serialized:

Not the same methods. Same names, but different arguments, different classes, not inherited, overridden, or overloaded.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Oops...

got it.
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Thanks again ,
actually am little confused then what actually this marker interface is doing ?


regards,
S
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

It is just to inform the serialization process that that kind of object is serializable. The decision was made that not all objects can be serialized but only if the developer declares so.

So you can do something like


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: serializable interface