Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

serializable interface

 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The writeObject and ReadObject are the part of ObjectOutputStream class
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
s begri wrote:We know that marker interface has method



No the marker interface doesn't contains any methods
 
Rob Spoor
Sheriff
Pie
Posts: 20606
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops...

got it.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again ,
actually am little confused then what actually this marker interface is doing ?


regards,
S
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic