aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HF SCJP mock exam question: flush() vs. write() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HF SCJP mock exam question: flush() vs. write()" Watch "HF SCJP mock exam question: flush() vs. write()" New topic
Author

HF SCJP mock exam question: flush() vs. write()

Jean-Christian Imbeault
Greenhorn

Joined: Dec 08, 2004
Posts: 19
Chapter 5, page 209, mock exam question #1 asks:

"When using a requestDispatcher, the use of which method can often lead to an IllegalStateException (choose all that apply):

A. read
B. flush
C. write
D. getOutputStream
E. getResourceAsStream

The correct answer is given as B, but I would have though the answer should have been B *and* C.

Couldn't writing 'theoretically' cause the response to be commited and hence cause and IllegalStateException if we try and forward the request?

Or is it in the specification that nothing is sent to the browser until flush() is called or the servlet's service method returns?
Nitish Bahadur
Ranch Hand

Joined: Aug 25, 2003
Posts: 118
The author of the question, probably, wants you to realize that a 'write' "often" implicitly does not lead to a 'flush'. Hence B is more correct than C.

>>Couldn't writing 'theoretically' cause the response to be commited and >>hence cause and IllegalStateException if we try and forward the request?
Good question. If you write a buffer > response.getBufferSize(), the OutputStream will automatically flush the stream, consequently leading you to IllegalStateException. So C can also be a correct answer. (not sure how to interpret 'often')

HFS authors allude to this on Pg 137, Para 3 of HFS book.
Jean-Christian Imbeault
Greenhorn

Joined: Dec 08, 2004
Posts: 19
Hum ... so I wonder if this is a trick question?

Hopefully this kind of question where a 'well it's theoritically possible' answer doesn't come up on the exam
Dave Wood
bronco
Ranch Hand

Joined: Aug 02, 2004
Posts: 161
I don't think it's intended to be a trick question. The nice thing about the exam is that they tell you how many correct answers to choose. I believe they also try to avoid loose terms like "often" in the real exam questions (though I was not personally involved in writing those questions, so I can't say for sure).

(as an aside, in case anyone's paying extra close attention and matched my name to page xxxi of the book, I feel the urge to point out that I didn't write this particular question )


Co-Author of <a href="http://www.oreilly.com/catalog/jswing2" target="_blank" rel="nofollow">Java Swing</a><br />Co-Creator of <a href="http://www.sun.com/training/catalog/courses/CX-310-055.xml" target="_blank" rel="nofollow">SCJP 5.0</a> and <a href="http://www.sun.com/training/certification/java/associate_beta.xml" target="_blank" rel="nofollow">SCJA</a> exams
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HF SCJP mock exam question: flush() vs. write()