• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

serializable interface

 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22818
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 5100
82
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops...

got it.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Popeye has his spinach. I have this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic