• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

serializable interface

 
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
 
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
 
Sheriff
Posts: 21922
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
 
Master Rancher
Posts: 3507
37
  • 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
 
Bartender
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
 
mooooooo ..... tiny ad ....
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic