x

JSTL and EL Questions

PREV  

JSTL and EL Questions:


  1. What gets printed when the following expression is evaluated? Select the one correct answer.${(1==2) ? 4 : 5}
    1. 1
    2. 2
    3. 4
    4. 5
  2. What gets printed when the following expression is evaluated? Select the one correct answer.${4 div 5}
    1. 0
    2. 0.8
    3. 1
    4. -1
  3. What gets printed when the following expression is evaluated? Select the one correct answer.${12 % 4}
    1. 0
    2. 3
    3. 8
    4. 16
  4. 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=”*”/>
    1. The code does not compile as there is no property attribute of setProperty tag.
    2. The code does not compile as property attribute cannot take * as a value.
    3. The code sets value of all properties of employee bean to “*”.
    4. The code sets the values of all properties of employee bean to matrching parameters in request object.
  5. What is the effect of evaluation of following expression? Select the one correct answer.                                  ${(5*5) ne 25}
    1. true
    2. false
    3. 25
    4. The expression does not compile as ne is not a valid operator.
  6. What is the effect of evaluation of following expression? Select the one correct answer.                                 ${‘cat’ gt ‘cap’}
    1. true
    2. false
    3. catcap
    4. The expression does not compile as gt operator cannot be applied on strings.
  7. 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. 1
    2. 5
    3. 6
    4. 11
  8. 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>
    1. The JSTL code does not compile as attribute for if tag are not correct.
    2. true
    3. false
    4. Nothing gets printed.
  9. 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>
    1. The JSTL code does not compile as an attribute for forEach tag is not correct.
    2. 0
    3. 2
    4. ABC
    5. Nothing gets printed as c.out statement does not get executed.
  10. 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>
    1. No number gets printed.
    2. One number gets printed.
    3. Two numbers gets printed.
    4. Three numbers gets printed.
    5. Four numbers gets printed.
  11. 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. 1
    2. 2
    3. 3
    4. 4
    5. abc
    6. The program does not compile.
  12. 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. 1
    2. 2
    3. 3
    4. 4
    5. abc
    6. The program does not compile.
  13. 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. 1
    2. 2
    3. 3
    4. 4
    5. abc
    6. The program does not compile.
  14. Which of these represent the correct path for the core JSTL library in JSTL version 1.1? Select the one correct answer.
    1. http://java.sun.com/jsp/jstl/core
    2. http://java.sun.com/jsp/core
    3. http://java.sun.com/core
    4. http://java.sun.com/jsp/jstl1.1/core

Answers to questions on EL and JSTL

  1. D. As 1 is not equal to 2, 5 gets printed.
  2. B. div operator is used for dividing in EL.
  3. A. % operator gives the remainder after performing division.
  4. D. This is a valid syntax for setProperty. All properties of the bean are set from the corresponding parameter names in the request object.
  5. 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.
  6. A. EL considers <cat> to be greater than <cap>, as the letter t comes after the letter p.
  7. C. The following numbers get printed – 0, 2, 4, 6, 8, 10.
  8. D. if evaluates to false, hence the c.out statement does not get executed.
  9. B. The forEach tag gets executed once, and prints zero.
  10. B. Only one number gets printed – the number 1.
  11. B, C. In this case the forEach tag iterates through two elements of the array named j.
  12. 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.
  13. A. status.first is true for the first iteration. The index is set to 0 in the first iteration.
  14. A. The path of core tag library in JSTL 1.1 is http://java.sun.com/jsp/jstl/core .

PREV  



Like it? Please Spread the word!

Post Your Thoughts