aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes problems in questions from final mock exam in hfsj 2nd edition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "problems in questions from final mock exam in hfsj 2nd edition" Watch "problems in questions from final mock exam in hfsj 2nd edition" New topic
Author

problems in questions from final mock exam in hfsj 2nd edition

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

the mock exam at the end of hfsj is of very poor quality. though errata has been published but it does not cover all the errors. i tried searching the forum and i found some links which also deal with the errors. combining with those links, errata and whatever i shall be compiling here it would be helpful for those who are preparing for the web component certification.


QUESTION NO. 19

please find the question below :

A Classic tag handler exists in legacy code. The author wrote a handler that evaluates its tag body a hundred times, to be used in testing other tags that produce random content.
Given:
06. public class HundredTimesTag extends TagSupport {
07. private int iterationCount;
08. public int doTag() throws JspException {
09. iterationCount = 0;
10. return EVAL_BODY_INCLUDE;
11. }
12.
13. public int doAfterBody() throws JspException {
14. if(iterationCount < 100){
15. iterationCount++;
16. return EVAL_BODY_AGAIN;
17. }else{
18. return SKIP_BODY;
19. }
20. }
21. }
What is incorrect about the code?
A. Tag handlers are not thread safe, so the iterationCount can become out of sync if multiple users are reaching the page at the same time.
B. The doAfterBody method is never being called because it is not part of the tag handler lifecycle. The developer should have extended the IterationTagSupport class to include this method in the lifecycle.
C. The doTag method should be doStartTag. As written, the default doStartTag of TagSupport is called which simply returns SKIP_BODY, causing doAfterBody to never be called.
D. When doAfterBody returns EVAL_BODY_AGAIN the doTag method is called again. The doTag method resets iterationCount to 0, resulting in an infinite loop and java.lang.OutOfMemoryError is thrown



i never understood the question. i do understand all the options but the question asks WHAT IS INCORRECT ABOUT THE CODE. and the correct answer it says is C. i think it should be WHAT IS CORRECT ABOUT THE CODE ?



QUESTION NO. 11

please consider the following question as copied from the hfsj book :


Given these fragments from within a single tag in a Java EE DD:
343. <web-resource-collection>
344. <web-resource-name>Recipes</web-resource-name>
345. <url-pattern>/Beer/Update/*</url-pattern>
346. <http-method>POST</http-method>
347. </web-resource-collection>
...
367. <auth-constraint>
368. <role-name>Member</role-name>
369. </auth-constraint>
...
385. <user-data-constraint>
386. <transport-guarantee>CONFIDENTIAL</transport-guarantee>
387. </user-data-constraint>
Which are true? (Choose all that apply.)
A. A Java EE DD can contain a single tag in which all of these tags can legally co-exist.
B. It is valid for more instances of <auth-constraint> to exist within the single tag described above.
C. It is valid for more instances of <user-data-constraint>
to exist within the single tag described above.
D. It is valid for more instances of <url-pattern> to exist within the <web-resource-collection> tag described above.
E. It is valid for other tags of the same type as the single encasing tag described above to have the same <url-pattern> as the tag above.
F. This tag implies that authorization, authentication, and data integrity security features are all declared for the web application.


the book says option A, B, D, E, F as the correct answers.

while i understood optin A D and E i had doubt about B and F. lets come to option F first. i made a sample program without <login-config> element but WITH <security-constraint> element. when i tried to access constrained resource it gave me 403 access denied error. option f says that the above xml snippet(in the question) declared authenticatin, authorisation and data integrity. while authorisation and data integrity are undersood , it is not true for authentication. we cant predict whether it has declared authentication . it is true that for before authorisation , authentication has to happen and by 403 error we know that the user needs to be authenticated but the exact elements are not declared in the xml file.

option B is wrong unless i misinterpreted the question. i put more than 1 auth-constraint tags inside <Security-constraint> and the web.xml gave error. so in my opinion option B and option f should be rules out unless somebody interprets quesiton in a way that they are true. please respond if somebody else had doubt in the same question ?
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

i'm posting full questions and options here so that the people who dont have book can also try their hands on these questions.

QUESTION 26

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. <ctherwise>
17. I have not selected any favorite books.
18. </ctherwise>
19. </c:choose>
Which of the following lines of code, if inserted independently at Line 5, will cause the text within the ctherwise tag to display? (Choose all that apply)
A. books.add("");
B. books.add(null);
C. books.clear();
D. books.add("Head First");
E. books = null;


According to book the correct answers are B and D. the CORRECT ANSWER should be C and E. infact if you look at the explanation , the explanation in the book is right and it says that optin A B and D all adds something to the list , making it non-empty which means the test in the <c:when> tag will pass.

following is copied from EL specification 1.10 regarding empty operator

The empty operator is a prefix operator that can be used to determine if a value is
null or empty.
To evaluate empty A
■ If A is null, return true
■ Otherwise, if A is the empty string, then return true
■ Otherwise, if A is an empty array, then return true
■ Otherwise, if A is an empty Map, return true
■ Otherwise, if A is an empty Collection, return true
■ Otherwise return false
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5266
    
  13

Some of them are already confirmed in this topic.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Question 49

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://
D. Line 3 is wrong because the prefix jsp is reserved for standard actions.



the book says option C is correct. i tested it but it proves that we can have uri value that may not begin with http://.
also option D looks like correct answer. but the test code ran and produced output on tomcat 7.0.34. so there is no correct answer.

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

Roel De Nijs wrote:Some of them are already confirmed in this topic.


i'm only posting the questions which are not in the links i have found . there is one more link here at http://www.coderanch.com/t/177893/java-Web-Component-SCWCD/certification/HFSJ-edition-Final-Mock-Exam#860570 which is really nice and explains some of the other questions. im trying not to repeat them in my posts. i shall consolidate both the links in the end.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1675
    
  25

You are right, check the HFSJ errata

Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problems in questions from final mock exam in hfsj 2nd edition