This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reg. Stream basic question

 
Angela Narain
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is a question from Khalid Mughal.

Which of these can act both as an input stream and as an output stream, based on classes :
a. File
b. A n/w connection
c. A pipe
d. A string
e. An array of character
The correct answers are a,b,c,e.
The question mention the phrase "based on classes" so i try to
figure out each one w.r.t to classes available.
So w.r.t all the option their respective classes can be :
a. File ==> FileInputStream,FileOutputStream
b. A n/w connection ofcourse can act as stream
c. A pipe ==> PipedInputStream, PipedOutputStream
d. A string ==> no equivalent methods in streams
but StringReader, StringWriter available
e. A array of characters ==> ?

Does it mean i have to look for equivalent methods in
InputStream or OutputStream.
Also suppose the last option e. had been "array of bytes"
would it be the correct answer anyway ..
Pls. explain to me

 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi angela!
i think the question states just about i/o streams, it may be either byte or char stream...for byte i/o streams, we can use array of bytes --> ByteArrayInputStream(byte[] arr)
ByteArrayOutputStream()
for char i/o streams, we have:
CharArrayReader(char[] c)
CharArrayWriter()
so if u need to choose four choices here, then (e) can be choosen. In short array(byte or char, depends!) can be used as input or output stream.
KAM doesn't describe these classes much so u need to find out some other material.
HIH.
ashok.
Originally posted by Angela Narain:
Following is a question from Khalid Mughal.

Which of these can act both as an input stream and as an output stream, based on classes :
a. File
b. A n/w connection
c. A pipe
d. A string
e. An array of character
The correct answers are a,b,c,e.
The question mention the phrase "based on classes" so i try to
figure out each one w.r.t to classes available.
So w.r.t all the option their respective classes can be :
a. File ==> FileInputStream,FileOutputStream
b. A n/w connection ofcourse can act as stream
c. A pipe ==> PipedInputStream, PipedOutputStream
d. A string ==> no equivalent methods in streams
but StringReader, StringWriter available
e. A array of characters ==> ?

Does it mean i have to look for equivalent methods in
InputStream or OutputStream.
Also suppose the last option e. had been "array of bytes"
would it be the correct answer anyway ..
Pls. explain to me

 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Angela , yes i agree wid u , correct ans shld be a) , b) n c)
d) is incorrect for obvious reason . e) is also incorrect based on same token
yes if last option wuld have been "array of bytes" , then that wuld have been one more correct choice
d) & e) culd hav been write choice for Readers /writers

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic