• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can such a situation arise in the real exam??

 
sonir shah
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question in JQ+...
Which of these can act as a source for an input stream as well as a destination for an output stream?
Select all the 3 correct answers:
A)A network Connection
B)A file
C)A pipe
D)A string
E)Array of chars
Here there are 4 correct answers: ie. A)B)C)E)..But the question asks for 3 correct answers?/
If such case arises in the exam, then what are we supposed to do?.
Sonir
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Streams only work with single bytes. A java character is a 2 byte char type; thus, streams can't use arrays of characters as a source or destination.
A Reader or Writer can work with characters, however.
The correct answers for this question are A, B, and C.
Rob
 
Rajinder Yadav
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob, I agree that E is also a correct answer. I came across this bit of info,
http://java.sun.com/docs/books/tutorial/essential/io/datasinks.html
About the following streams: CharArrayReader, CharArrayWriter, ByteArrayInputStream, ByteArrayOutputStream, it states.
"Use these streams to read from and write to memory. You create these streams on an existing array and then use the read and write methods to read from or write to the array."
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3764
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Readers/Writers and In(Out)outStreams form two different branches of the i/o classes tree.
All the "readers" (or writers) extend from java.io.Reader (or java.io.Writer), while all input "streams" (or output streams) extend from java.io.InputStream (or java.io.OutputStream).
This question is asking about "streams" and so CharArrayReader, CharArrayWriter are not valid (because they are not streams but reader and writer).
I do not remember the question id but I believe this explanation is given in the question.
HTH,
Paul.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic