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

Sybex 816, Chapter 11, pag. 596

 
Greenhorn
Posts: 24
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Table 11.2, the parameters of writeObject() and readObject() seem to be inverted. writeObject() should take an ObjectOutputStream as parameter, while readObject() should take an ObjectInputStream.
Right?
 
Marshal
Posts: 79953
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please supply more details of what the book says. The types you have given are the types the methods are called on, not their parameters. See ObjectOutputStream#writeObject(Object) and ObjectInputStream#readObject().
I can't find such an erratum here, so you may get recognition for finding a “new” error.
 
Ilenia Salvadori
Greenhorn
Posts: 24
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, in Table 11.2 at pag. 596 there is a list of the methods for serialization and deserialization. The table lists the return type, the method name, the method parameters and the description.
The two lines which correspond to the methods writeObject() and readObject() are the following:

Return TypeMethodParametersDescription
voidwriteObject()ObjectInputStreamSerializes optionally using PutField
voidreadObject()ObjectOutputStreamDeserializes optionally using GetField


I think in the third column (Parameters) the two should be inverted, meaning writeObject() takes an ObjectOutputStream as parameter, while readObject() takes an ObjectInputStream.
 
Campbell Ritchie
Marshal
Posts: 79953
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those would seem to be different methods from what I linked to. Which classes are those methods in? The readObject method I told you about earlier returns Object, not void. I think we need more information please.
 
Ilenia Salvadori
Greenhorn
Posts: 24
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The methods I am referring to are not the ones from ObjectInputStream and ObjectOutputStream, but are the ones that you can optionally provide in a class that implements the Serializable interface, when you want to use ObjectInputStream.getField and ObjectOutputStream.putField respectively.
 
Campbell Ritchie
Marshal
Posts: 79953
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can verify the method signatures in the Serializable documentation. There are fuller descriptions in several books, e.g. Thinking in Java by Bruce Eckel, and many cert exam books.
 
Ilenia Salvadori
Greenhorn
Posts: 24
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, which prove my point. In the documentation you find


Classes that require special handling during the serialization and deserialization process must implement special methods with these exact signatures:

private void writeObject(java.io.ObjectOutputStream out)
    throws IOException
private void readObject(java.io.ObjectInputStream in)
    throws IOException, ClassNotFoundException;



so, writeObject takes an ObjectOutputStream as parameter, and readObject takes an ObjectInputStream. Which is the opposite of what is written in tab 11.2 pag. 596 of the book.
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Confirmed and added to the errata
 
Onion rings are vegetable donuts. Taste this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic