aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes mock exam question doubt from javacertifications.net ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "mock exam question doubt from javacertifications.net ?" Watch "mock exam question doubt from javacertifications.net ?" New topic
Author

mock exam question doubt from javacertifications.net ?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

following is the question ;

Questions no -20

What get printed when the following JSTL code fragment is executed?

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="item" value="2"/>
<c:forEach var="item" begin="0" end="0" step="2">
<cut value="${item}" default="abc"/>
</c:forEach>



options
A)0
B)2
C)abc
D)4

the correct answer is OPTION A i.e. 0. i thought the answer should be 2. i ran it but it is coming out to be 0. checked syntax for forEach tag and didnt find a thing. please help ?
Vijay Vishwa
Greenhorn

Joined: Nov 21, 2010
Posts: 28
Let put it through similar simple java loop



This is what happening is the JSTL code also

item varable is declared and set to 2

Next in the for loop, the counter varaible is item and loop starts and ends with 0
So in the first iteration 0 is assigned to the item and that is what printed.




SCJP 5.0 OCBCD 5.0(Formerly SCBCD)
harshvardhan ojha
Ranch Hand

Joined: Jul 26, 2007
Posts: 157
    
    1

you have initialized your item variable again for looping, so has nothing to do with your previous assignment.
Atul Shrivastava
Greenhorn

Joined: Jan 12, 2009
Posts: 19

you started with 0 and the loop ended on 0 itself, resulting in the output 0.


OCP (SCJP) - Java 1.6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mock exam question doubt from javacertifications.net ?