Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Sybex 816, Chapter 11, pag. 596

 
Greenhorn
Posts: 19
1
  • 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: 73738
332
  • 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: 19
1
  • 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: 73738
332
  • 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: 19
1
  • 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: 73738
332
  • 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: 19
1
  • 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: 40722
827
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
 
You can't have everything. Where would you put it?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic