File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Reg. Stream basic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Reg. Stream basic question" Watch "Reg. Stream basic question" New topic
Author

Reg. Stream basic question

Angela Narain
Ranch Hand

Joined: Apr 14, 2001
Posts: 327
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

Joined: Jul 29, 2001
Posts: 153
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

Joined: Feb 28, 2001
Posts: 346
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 .


Gagan (/^_^\) SCJP2 SCWCD IBM486 <br />Die-hard JavaMonk -- little Java a day, keeps you going.<br /><a href="http://www.objectfirst.com/blog" target="_blank" rel="nofollow">My Blog</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reg. Stream basic question