|
|
|
| javaprepare.com
your tool for Java Certification |
SCWCD home | SCWCD questions | SCWCD links | SCJP home
Questions on JSTL and EL
-
What gets printed when the following expression is evaluated? Select the one correct answer.
${(1==2) ? 4 : 5}
- 1
- 2
- 4
- 5
-
What gets printed when the following expression is evaluated? Select the one correct answer.
${4 div 5}
- 0
- 0.8
- 1
- -1
-
What gets printed when the following expression is evaluated? Select the one correct answer.
${12 % 4}
- 0
- 3
- 8
- 16
-
What is the effect of executing the following JSP statement, assuming a class with name Employee exists in classes package.
<%@ page import = "classes.Employee" %>
<jsp:useBean id="employee" class="classes.Employee" scope="session"/>
<jsp:setProperty name="employee" property="*"/>
- The code does not compile as there is no property attribute of setProperty tag.
- The code does not compile as property attribute cannot take * as a value.
- The code sets value of all properties of employee bean to "*".
- The code sets the values of all properties of employee bean to matrching parameters in request object.
-
What is the effect of evaluation of following expression? Select the one correct answer.
${(5*5) ne 25}
- true
- false
- 25
- The expression does not compile as ne is not a valid operator.
-
What is the effect of evaluation of following expression? Select the one correct answer.
${'cat' gt 'cap'}
- true
- false
- catcap
- The expression does not compile as gt operator cannot be applied on strings.
-
How many numbers are printed, when the following JSTL code fragment is executed? Select the one correct answer.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:forEach var="item" begin="0" end="10" step="2">
${item}
</c:forEach>
- 1
- 5
- 6
- 11
-
What gets printed when the following JSTL code fragment is executed? Select the one correct answer.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="item" value="2"/>
<c:if test="${var==1}" var="result" scope="session">
<c:out value="${result}"/>
</c:if>
- The JSTL code does not compile as attribute for if tag are not correct.
- true
- false
- Nothing gets printed.
-
What gets printed when the following JSTL code fragment is executed? Select the one correct answer.
<%@ 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">
<c:out value="${item}" default="abc"/>
</c:forEach>
- The JSTL code does not compile as an attribute for forEach tag is not correct.
- 0
- 2
- ABC
- Nothing gets printed as c.out statement does not get executed.
-
How many numbers gets printed when the following JSTL code fragment is executed? Select the one correct answer.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="item" value="2"/>
<c:choose>
<c:when test="${item>0}">
<c:out value="1"/>
</c:when>
<c:when test="${item==2}">
<c:out value="2"/>
</c:when>
<c:when test="${item<2}">
<c:out value="3"/>
</c:when>
<c:otherwise>
<c:out value="4"/>
</c:otherwise>
</c:choose>
- No number gets printed.
- One number gets printed.
- Two numbers gets printed.
- Three numbers gets printed.
- Four numbers gets printed.
-
Which numbers gets printed when the following JSTL code fragment is executed? Select the two correct answers.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" begin="1" end="2">
<c:out value="${item}" default="abc"/>
</c:forEach>
- 1
- 2
- 3
- 4
- abc
- The program does not compile.
-
Which numbers gets printed when the following JSTL code fragment is executed? Select the two correct answers.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" begin="1" end="2" varStatus="status">
<c:out value="${status.count}" default="abc"/>
</c:forEach>
- 1
- 2
- 3
- 4
- abc
- The program does not compile.
-
Which number gets printed when the following JSTL code fragment is executed? Select the one correct answers.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="j" value="4,3,2,1"/>
<c:forEach items="${j}" var="item" varStatus="status">
<c:if test="${status.first}">
<c:out value="${status.index}" default="abc"/>
</c:if>
</c:forEach>
- 1
- 2
- 3
- 4
- abc
- The program does not compile.
-
Which of these represent the correct path for the core JSTL library in JSTL version 1.1? Select the one correct answer.
- http://java.sun.com/jsp/jstl/core
- http://java.sun.com/jsp/core
- http://java.sun.com/core
- http://java.sun.com/jsp/jstl1.1/core
Answers to questions on EL and JSTL
- D. As 1 is not equal to 2, 5 gets printed.
- B. div operator is used for dividing in EL.
- A. % operator gives the remainder after performing division.
- D. This is a valid syntax for
setProperty. All properties of the bean are set from the corresponding parameter names in the request object.
- B. The code prints false. ne is a valid operator. Since both left hand side and right hand side are equal to 25, false gets printed.
- A. EL considers <cat> to be greater than <cap>, as the letter t comes after the letter p.
- C. The following numbers get printed - 0, 2, 4, 6, 8, 10.
- D. if evaluates to false, hence the
c.out statement does not get executed.
- B. The
forEach tag gets executed once, and prints zero.
- B. Only one number gets printed - the number 1.
- B, C. In this case the forEach tag iterates through two elements of the array named j.
- B, C. varStatus is set to a class of type LoopTagStatus. This class has a property named count which is being printed. count is the loop index, beginning with 1. So for two iterations 1 and 2 get printed.
In this case the
forEach tag iterates through two elements of the array named j.
- A. status.first is true for the first iteration. The index is set to 0 in the first iteration.
- A. The path of core tag library in JSTL 1.1 is http://java.sun.com/jsp/jstl/core .
SCWCD home | SCWCD questions | SCWCD links | SCJP home
|