• 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

Shouldn't ObjectInputStream also be a (sublass of) FilterInputStream?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am appearing for my SCJP exam soon, and so was brushing up on my Java basics when I bumped into this tricky question.
Hope someone in here can shed some light on it.

From what I understand,
An ObjectInputStream basically lets you read a byte version(from an underlying stream) of an Object written
by a corresponding ObjectOutputStream.
A FilterInputStream lets you manipulate(or add new functionality to) data read from an underlying input stream.

Why then, isn't ObjectInputStream a sublass of FilterInputStream? Or am I missing something here?

This looks like a design decison to me, and quite frankly, a little too advanced for SCJP, but I'd still like to know the reason behind it, as it
has been bothering me for a while . Thanks.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you learn when you read the API documentation for ObjectInputStream and FilterInputStream?
 
Rahul Saple
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, first I apologize for the delay in replying to this post. Had been out of town for a while.

This is from the Java Docs

A FilterInputStream contains some other input stream, which it uses as its basic source of data, possibly transforming the data along the way or providing additional functionality


An ObjectInputStream deserializes primitive data and objects previously written using an ObjectOutputStream.



My question remains the same.

Why does ObjectInputStream not extend FilterInputStream like how DataInputStream does?

Unlike DataInputStream, ObjectInputStream has the additional functionality of reading Objects from the underlying stream.

When both provide additional functionality to the underlying stream, DataInputStream(although limited) chooses to extend FilterInputStream whereas ObjectInputstream chooses otherwise.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They simply chose not to. There is no added value in extending FilterInputStream, it's just a convenience class.
 
Space pants. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic