This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question regarding answers in HFSJ 2nd ed mock exam

 
Marlo Magpantay
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just like to confirm 2 items in HFSJ 2nd edition mock exam. Thanks in advance for your comments.

#26 - Answers in the book are B and D. Are they really the correct answers? But the comments in the book say otherwise.
Given:
01. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
02.
03. <%
04. java.util.List books = new java.util.ArrayList();
05. // add line here
06. request.setAttribute("myFavoriteBooks", books);
07. %>
08.
09. <c:choose>
10. <c:when test="${not empty myFavoriteBooks}">
11. My favorite books are:
12. <c:forEach var="book" items="${myFavoriteBooks}">
13. <br/> * ${book}
14. </c:forEach>
15. </c:when>
16. <c: otherwise>
17. I have not selected any favorite books.
18. </c: otherwise>
19. </c:choose>

Which of the following lines of code, if inserted independently at Line 5, will cause the text within the c: otherwise tag to display? (Choose all that apply)
A. books.add("");
B. books.add(null); -Answer in the book
C. books.clear();
D. books.add("Head First"); -Answer in the book
E. books = null;

Comments:
-Options A, B, and D all add something to the books List, making it NOT empty.
-Option C empties out the already empty List.
-Option E: Making the List reference a null value satisfies the empty operator.

#49 - Answer in the book is C, which I don't agree.
Given:
1. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
2. <%@ taglib prefix="tables" uri="http://www.javaranch.com/tables" %>
3. <%@ taglib prefix="jsp" tagdir="/WEB-INF/tags" %>
4. <%@ taglib uri="UtilityFunctions" prefix="util" %>

What about the above taglib directives would cause the JSP to not function?
A. Line 4 is wrong because the prefix attribute must come before the
uri attribute.
B. Line 3 is wrong because there is no uri attribute.
C. Line 4 is wrong because the uri value must begin with http:// -Answer in the book
D. Line 3 is wrong because the prefix jsp is reserved for standard actions.

Comments:
-Option A: attributes can be in any order.
-Option B: when using Tag Files, tagdir is used instead of uri.
-Option C: a URI simply must match how the TLD is identified by the container.
-Option D: the jsp prefix is reserved for standard actions.
 
Luis Centeno
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marlo...

Please take a look at HFSJ errata. There, you will find answers to any doubt you might have about correctness on HFSJ book.

Regards

Luis
 
Marlo Magpantay
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool! Thanks for the link!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic