• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

writeObject and defaultWriteObject()

 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The class ObjectOutputStream has two methods, writeObject and defaultWriteObject.

What is the difference between these 2 methods?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you use the writeObject method to serialize an instance of a serializable class.

you use the defaultWriteObject method in your custom writeObject method to do default processing of serialization.

It is a very long thing to explain and this is the best I can do for you... :roll:
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
up to my knowledge,

writeObject() is a method of ObjectOutputStream class.there are two options for you while serializing

1. calling writeObject() method
2. overriding writeObject() method

when you call wrirteObject() method it won't serialize the instances which are declared transient.consider a case of instance transient Object of another class and you want to serilaze a member of that transient Object.then you have to override the writeObject() according your need.

when your are overriding you have to use defaultWriteObject() to ensure normal overriding apart from the this transient Object.this should be the first call before before any serializing of transient Object's members.
you normally use writeXXX() method to serialize this transient Object's members
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic