Q) Which of these can act as a source for an input stream as well as a destination for an output stream? Correct Answers: A network connection A file A pipe Wrong Answer: An array of chars - Option comment "You can create a CharArrayReader and CharArrayWriter but there is nothing like CharArrayInputStream and CharArrayOutputStream" As explained by JQ+ tech support, "Array of chars is not a correct choice as you cannot create any "stream" out of it. You can only create "Reader" and "Writer" out of it."
Sec. 18.1, p549 Programmer's Guide to Java Certification 2, Rev1 by Khalid Mugal and Rolf Rasmussen says, "There are two kinds of streams byte streams and character streams. An input stream acts as a source of data. An output stream acts as a destination of data. The following entities can act as both input and output stream:
an array of bytes or characters
a network connection
" Also, Jane Griscti's notes on I/O seems to agree with Mughal and Rasmussen's assertions. My thought is that the correct answers given above are specific to InputStream and OutputStream classes (byte-oriented) as opposed to input and output streams (byte and character-oriented) in general. Im confused , I'd appreciate it if anyone clarify if array of chars/bytes is a legitimate answer to the JQ+ question above and if not, how does it differ in Khalid and Jane's assertions? ------------------ ~James Baud He who asks, is a fool for five minutes; but, he who does not ask, remains a fool forever. (Chinese proverb)
<B>~James Baud</B><P>He who asks, is a fool for five minutes;<BR>but, he who does not ask, remains a fool forever. (Chinese proverb)
Hi James, I think the question is taking the term 'character' literally ie they are not considering characters as bytes. If that's the case, the answer is correct. You cannot take a character array and pass it directly to an input/output stream; to do that you'd first have to convert the character array to a byte array. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
Jane, Thanks for your post. I don't have a firm grasp of Java I/O and find myself really struggling w/ the topic, but one thing is clear in my mind, input stream is different from InputStream class. To me, input stream is a generic term that encompasses both Reader (character-stream) and InputStream (byte-stream) classes & its subclasses supporting input stream operations. As I read the question carefully, it is the generic term and not the specific abstract classes (InputStream and OutputStream) that is being suggested. There is no suggestion here of taking a literal interpretation of "character", either. Creating a "Reader" out of a character array still falls under the "stream" (as input source) interpretation. I guess my question boils down to this. If you find yourself in the examination room staring upon such a question, how would you choose your answers based on your interpretation of the question? ------------------ ~James Baud He who asks, is a fool for five minutes; but, he who does not ask, remains a fool forever. (Chinese proverb)
Joined: Aug 30, 2000
Honestly, I would have answered the question just as you did. You're right, the question is worded generically (sp?) but the answer was based on specifics. One thing I do know, the real exam does not contain ambiguous phrases. The I/O questions are clearly worded and use class names vs general references. I managed to get through them by remembering that any class ending with InputStream can take any other class ending with InputStream as an argument; same for OutputStream, Reader, Writer classes. ie if a class is named xxxReader it can't take a class named xxxInputStream as an argument and vice versa. If you keep that straight and have a basic understanding of the
and how Filter streams are used you should be ok. Basically, focus on the classes specifically mentioned in the objectives and don't fret too much over the others. Hope that helps. ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
[This message has been edited by Jane Griscti (edited March 22, 2001).]
Joined: Jan 06, 2001
I'll keep your advice in mind. Thank you so much.
------------------ ~James Baud He who asks, is a fool for five minutes; but, he who does not ask, remains a fool forever. (Chinese proverb)