• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

HFSJ 2nd edition - Final Mock Exam incorrect answers!?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have few questions about Final Mock Exam in Head First Servlets and JSP (second edition).

Why in question 6 answer c isn't correct?

Question 6
6. When creating session listeners which is true?
a) They are all declared in the DD.
b) Not all of them must be declared in the DD
c) The DD tag used to declare them is <listener>
d) The DD tag used to declare them is <session-listener>
e) The DD tag used to declare them is placed within the <web-app> tag.
f) The DD tag used to declare them is placed within the <servlet> tag.

I think answer b, c and e are correct. Ok there must by tag <listener-class> inside this tag but this is not strict question.

Question 11
In question 11 there is answer b
b) It is valid for more instanced of <auth-constraint> to exist within the single tag describe above.
And this answer is marked as correct, but within tag <security-constraint> you can�t put more instances of this tag(<auth-constraint> !!

Question 14
It is true that JEE container must support SSL?

Question 21
Who create this question the philosopher? It's very strange and less precise. This question is not easy to understand for person who isn�t good English skills. Why there isn't WEB-INF, META-INF, and �example.war� instead of WARdir, APPdir, ValidApp.war. Or there should be some tree. In my opinion this question doesn�t check knowledge.

Question 26
In my opinion correct answer should be C and E. Not B and D.

Question 30
Why the correct answer isn't F!
If you have
<auth-constraint><role-name>student</role-name></auth-constraint>
and
<auth-constraing/>
for this same resources, this mean that nobody can access for this resource.
And if you have only two roles student and philosopher and you remove second tag <auth-constraint> only student role have access not both!

Question 32
Next philosopher question, if you want use some pattern for remote registers you can think about:
- service locator
- bussiness delegate
- and Object Transfer
and this I think mean when you use this patterns not only answer a and b are correct, but also b and d!

Question 34
When there is something in question about resource accessible, also answer c should be correct, because everything inside WEB-INF and META-INF isn�t directly accessible for user. Why I should know that question maker think only about programmatically accessible or via dd mappings?

Question 49
Why c is correct answer? Why not d?

Question 50
Given a portion of Java EE web application's deployment descriptor:
<error-page>
<exception-type>IOException</exception-type>
<location>/mainError.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/notFound.jsp</location>
</error-page>
What is true?
a) The DD is not valid
b) If the application throws IOException nothing will be served
c) If the application throws IOException notFound.jsp will be served
d) If the application throws IOException mainError.jsp will be served
The correct answer is a. But in my opinion DD is valid, because tags are valid, when we tell about valid xml file we usually think about it syntax. Only value is not valid there should be java.io.IOException if we really want catch java.io.IOException not some other own IOException in default package. I think answer b should be correct. Because DD is valid, only
there isn't correct class. But what if author doesn�t think about java.io.Exception but about some other IOException?

Question 60
Why answer D isn't correct?
d) Both (init and context parameter) can be directly accessed from a JSP
What does it mean �directly�?
I can use:
${initParam.someContextParam}
<%= config.getInitParameter("some servlet init param") %>
Why first is directly and second isn't?

Question 63
Only c is correct but if in DD somebody use el-ignored also b is correct.

Question 69
If BEGINER should see only directory2, and EXPERT directory1 and directory2
The correct answer should be a not d.

I think there are three king of SCWCD question maker:
normal - person who want check your knowledge, and want strict answer
philospopher - person who don't want strict answer, but what see how your brain looking all possible correct answer
and idiot - person who want show you that if you think that you know answer, only he have right, because he always could say: "I thought about something else"

But if you don't know who create witch question, you can't choose correct answer.

Sorry for my English,
Regards,
 
Sheriff
Posts: 67734
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"MyMyselfAndI", please check your private messages for an important administrative matter.
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with the OP (I won't put his/her username in case it gets changed )

I found the HFSJ 2nd edition mock quite disappointing. With a large number of errors, and an ambiguity that isn't IMHO a good reflection of the actual exam it was for me discouraging.

I believe that some of the errors have been ironed out for the July 08 reprint of the book, and it's always worth checking the errata:

http://oreilly.com/catalog/9780596516680/errata/

HTH - Rufus.
 
Joseph Muller
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks Rufus for information about errata.
Questions: 6, 11, 26, 34, 49, as I thought are in errata.
But in my opinion not all bugs are in errata. Also answer for question 30 isn't correct.

(When I wrote first time about Q50 I mean Q54.)

Regards,
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rufus for mentioning the errata. I re-evaluated my mock-test and surprisingly i got passed. Thanks!!
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by MyMyselfAndI:
Question 14
It is true that JEE container must support SSL?


I don't think so either..
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q33:

What is generally true about the lifecycle of a servlet? (Choose all that apply.)
X A. You should NOT write a constructor for a servlet.
B. You should NOT override a servlet�s init() method.
C. You should NOT override a servlet�s doGet() method.
D. You should NOT override a servlet�s doPost() method.
X E. You should NOT override a servlet�s service() method.
F. You should NOT override a servlet�s destroy() method.

I think E is not correct.. If you call super(), you can do some general stuff in there.

And if the 'servlet' is not an HttpServlet, but a GenericServlet, it even has to!
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Q33:

What is generally true about the lifecycle of a servlet? (Choose all that apply.)
X A. You should NOT write a constructor for a servlet.
B. You should NOT override a servlet�s init() method.
C. You should NOT override a servlet�s doGet() method.
D. You should NOT override a servlet�s doPost() method.
X E. You should NOT override a servlet�s service() method.
F. You should NOT override a servlet�s destroy() method.

I think E is not correct.. If you call super(), you can do some general stuff in there.

And if the 'servlet' is not an HttpServlet, but a GenericServlet, it even has to!



You can but you could also override the constructor and call it's parent constuctor there as well.

You CAN override all these method/constructor in the Servlet but they're all not meant to be overriden. The question uses the word "Generally" so the point is that you GENERALLY shouldn't be overriding in case you break it I think.
[ September 06, 2008: Message edited by: Eurig Jones ]
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q45:

Given this fragment from a valid doGet() method:

12. OutputStream os = response.getOutputStream();
13. byte[] ba = {1,2,3};
14. os.write(ba);
15. RequestDispatcher rd = request.RequestDispatcher("my.jsp");
16. rd.forward(request, response);

Assuming that "my.jsp" adds the bytes 4, 5, and 6 to the response, what is the result?
A. 123
B. 456
C. 123456
D. 456123
E. An exception is thrown

Answer according to HF is B: - because os.flush() wasn�t called, the uncommitted output (123), is cleared, and forward is invoked without exception. If os.flush() had been called before forward, an IllegalStateException would have been thrown.

This is not true. The above code will always cause an IllegalArgumentException, flushed or not. The implementation class of the JSP page will create a PageContext object, which in turn will call getWriter() on the response object (to set its out property). Because the response object already called getOutputStream(), it will throw an exception.
[ September 07, 2008: Message edited by: Jan Sterk ]
 
Ericson James
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jan Sterk reply to Q45:

Answer according to HF is B: - because os.flush() wasn�t called, the uncommitted output (123), is cleared, and forward is invoked without exception. If os.flush() had been called before forward, an IllegalStateException would have been thrown.

This is not true. The above code will always cause an IllegalArgumentException, flushed or not. The implementation class of the JSP page will create a PageContext object, which in turn will call getWriter() on the response object (to set its out property). Because the response object already called getOutputStream(), it will throw an exception.


Yes Jan, you're right. Just tried it myself now..

Even if you call getWriter() in the servlet instead of getOutputStream() it throws an IllegalStateException.

I also tried getWriter() and then getOutputStream() alone in a Servlet without request dispatch. Throws an IllegalStateException from Servlet.

But If getWriter is called twice in the same servlet (or if getOutputStream is called twice), it DOESN'T throw an IllegalStateException. Why is this? what is happening when the RequestDispatcher forwards? is it flushing? It doesn't mention this in the API.
[ September 07, 2008: Message edited by: Eurig Jones ]
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Eurig.

Originally posted by Eurig Jones:
Even if you call getWriter() in the servlet instead of getOutputStream() it throws an IllegalStateException.


I don't Could you copy/paste your code and the exception?

Originally posted by Eurig Jones:
I also tried getWriter() and then getOutputStream() alone in a Servlet without request dispatch. Throws an IllegalStateException from Servlet.

But If getWriter is called twice in the same servlet (or if getOutputStream is called twice), it DOESN'T throw an IllegalStateException. Why is this?


See the API of both ServletResponse methods. I'm not exactly sure why the container has to throw an exception when both methods are mixed. Maybe because it is to prevent bad code design.

Originally posted by Eurig Jones:
what is happening when the RequestDispatcher forwards? is it flushing? It doesn't mention this in the API.


No, on the contrary: it clears the buffer.

Note that the cause that the exception is thrown in the above code, is not the forwarding. It is actually because both getWriter() and getOutputStream() are called on the same ServletResponse object.

The flush-then-forward that the answer of HF mentions, also throws an IllegalStateException, but that's another story.
[ September 07, 2008: Message edited by: Jan Sterk ]
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q67:

Answers: B,D,G

I think method1 should be contextDestroyed, since the comment is:
// shutdown related method here
 
Ericson James
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply Jan,

I don't Could you copy/paste your code and the exception?


You're right. It doesn't on mine. Sorry. MyEclipse must not've swapped the servlet correctly.

So..

- RequestDispatcher clears the buffer as you mentioned.
- You cannot mix the use of getWriter() and getOutputStream() on the same Response object
- If you call getOutputStream() in a JSP even if it only has 1 character in it, it'll throw an IllegalStateException because it's allready pinched the PrintWriter
- But you CAN use getWriter() in the Servlet and forward it on to the JSP.

I think that's correct?
[ September 07, 2008: Message edited by: Eurig Jones ]
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eurig Jones:


- RequestDispatcher clears the buffer as you mentioned.

Nope, only the forward() method does; include() doesn't.


Originally posted by Eurig Jones:

- You cannot mix the use of getWriter() and getOutputStream() on the same Response object
- If you call getOutputStream() in a JSP even if it only has 1 character in it, it'll throw an IllegalStateException because it's allready pinched the PrintWriter

Right. Even if you don't write anything to/in the stream/JSP, just making the call getOutputStream() in a JSP will throw an exception.


Originally posted by Eurig Jones:

- But you CAN use getWriter() in the Servlet and forward it on to the JSP.

Right.

 
no wonder he is so sad, he hasn't seen this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic