wood burning stoves 2.0*
The moose likes Mock Exam Errata and the fly likes JQ Plus - I/O streams Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "JQ Plus - I/O streams" Watch "JQ Plus - I/O streams" New topic
Author

JQ Plus - I/O streams

James Baud
Ranch Hand

Joined: Jan 06, 2001
Posts: 60
Question ID :953742349090

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 file
  • a pipe
  • 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)
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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 Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
James Baud
Ranch Hand

Joined: Jan 06, 2001
Posts: 60
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)
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
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
  • File class
  • RandomFileAccess class
  • 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).]
  • James Baud
    Ranch Hand

    Joined: Jan 06, 2001
    Posts: 60
    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)
     
     
    subject: JQ Plus - I/O streams
     
    Similar Threads
    InputStream
    inputstream and outputstreams
    Can such a situation arise in the real exam??
    Reg. Stream basic question
    About I/O streams