Free SCWCD Mock Exam for EL


This practice exam focuses on EL. For those using Head First Servlets and JSP, 2nd Edition it provides a lot of practice for the last part of chapter 8.

  1. In EL you may use the . operator to access maps and beans.
    1. true
    2. false

  2. In EL you may use the [] operator to access maps, beans, lists and arrays.
    1. true
    2. false

  3. Which of the following are EL implicit objects? (4 correct answers)
    1. pageScope
    2. requestScope
    3. sessionScope
    4. contextScope
    5. applicationScope

  4. Which of the following are EL implicit objects? (2 correct answers)
    1. param
    2. parameter
    3. params
    4. parameters
    5. paramValues
    6. parameterValues

  5. Which of the following are EL implicit objects? (1 correct answer)
    1. initParam
    2. servletParam
    3. contextParam
    4. applicationParam

  6. Which of the following EL implicit objects are maps? (3 correct answers)
    1. cookie
    2. pageContext
    3. headerValues
    4. applicationScope

  7. What is the output of the following code? (1 correct answer)
    <% session.setAttribute("name", "Diogenes"); %>
    ${session.name}
    
    1. “Diogenes”
    2. “”

  8. What is the output of the following code? (1 correct answer)
    <% session.setAttribute("name", "Diogenes"); %>
    ${sessionScope.name}
    
    1. “Diogenes”
    2. “”

  9. What is the output of the following code? (1 correct answer)
    <% session.setAttribute("name", "Diogenes"); %>
    ${sessionScope[name]}
    
    1. “Diogenes”
    2. “”

  10. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  11. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${request.yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  12. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${requestMap.yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  13. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${requestScope.yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  14. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${pageScope.yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  15. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${param.yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  16. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${param[yourname]} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”

  17. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${paramValues.yourname} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”
    3. None of the above.

  18. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${paramValues[yourname]} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”
    3. None of the above.

  19. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${paramValues.yourname.0} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”
    3. None of the above.

  20. Consider this code.
    <%-- input.jsp --%>
    <html>
      <body>
        <form action="output.jsp">
          <input type="text" name="yourname" value="Bond"/>
          <input type="submit" value="OK" />
        </form>
      </body>
    </html>
    
    <%-- output.jsp --%>
    <html>
      <body>
        Hello ${paramValues.yourname[0]} !!
      </body>
    </html>
    

    What is the output when the form is submitted? (1 correct answer)

    1. “Hello !!”
    2. “Hello Bond !!”
    3. None of the above.

  21. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Number ${14 + 3}
      </body>
    </html>
    
    1. “Number “
    2. “Number 17”

  22. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Number ${"14" + 3}
      </body>
    </html>
    
    1. “Number 17”
    2. “Number 143”

  23. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${2 > 3}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  24. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${"2" > 3}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  25. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${"a" > "b"}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  26. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${"a" < "b"}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  27. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${a < b}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  28. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${"a literal"}
      </body>
    </html>
    
    1. “Result is “
    2. “Result is a literal”

  29. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${'a literal'}
      </body>
    </html>
    
    1. “Result is “
    2. “Result is a literal”

  30. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${"a literal" + " indeed."}
      </body>
    </html>
    
    1. “Result is a literal indeed.”
    2. An exception is thrown at runtime.

  31. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${2 / 0}
      </body>
    </html>
    
    1. “Result is Infinity”
    2. An exception is thrown at runtime.

  32. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${2 mod 0}
      </body>
    </html>
    
    1. “Result is Infinity”
    2. An exception is thrown at runtime.

  33. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${null mod 1}
      </body>
    </html>
    
    1. “Result is 0”
    2. “Result is null”
    3. An exception is thrown at runtime.

  34. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${null + 1}
      </body>
    </html>
    
    1. “Result is 0”
    2. “Result is 1”
    3. “Result is null”

  35. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${true and null}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  36. What is the output of this page? (1 correct answer)
    <html>
      <body>
        Result is ${empty null}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  37. What is the output of this page? (1 correct answer)
    <% request.setAttribute("list", new String[100]); %>
    <html>
      <body>
        Result is ${empty list}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  38. What is the output of this page? (1 correct answer)
    <% request.setAttribute("list", new String[0]); %>
    <html>
      <body>
        Result is ${empty list}
      </body>
    </html>
    
    1. “Result is true”
    2. “Result is false”

  39. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${request.names}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey null!!”
    3. “Hey Rihanna!!”
    4. None of the above.

  40. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${request.names[0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  41. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${requestScope.names[0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  42. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${requestScope.names[12 - 12]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  43. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${requestScope.names[<%= names.length - 2%>]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  44. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${requestScope["names"]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  45. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${requestScope["names"].0}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  46. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${requestScope["names"][0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  47. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${pageScope["names"][0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  48. What is the output of this page? (1 correct answer)
    <% String[] names = new String[]{"Rihanna", "Lopez", "Kylie"};
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${names[0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  49. What is the output of this page? (1 correct answer)
    <% java.util.List names = new java.util.LinkedList();
       names.add("Rihanna");
       names.add("Lopez");
       names.add("Kylie");
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${names[0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  50. What is the output of this page? (1 correct answer)
    <% java.util.List names = new java.util.LinkedList();
       names.add("Rihanna");
       names.add("Lopez");
       names.add("Kylie");
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${names[-1]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  51. What is the output of this page? (1 correct answer)
    <% java.util.Map names = new java.util.HashMap();
       names.put("0", "Rihanna");
       names.put("1", "Lopez");
       names.put("2", "Kylie");
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${names["0"]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  52. What is the output of this page? (1 correct answer)
    <% java.util.Map names = new java.util.HashMap();
       names.put("0", "Rihanna");
       names.put("1", "Lopez");
       names.put("2", "Kylie");
       request.setAttribute("names", names); %>
    <html>
      <body>
        Hey ${names[0]}!!
      </body>
    </html>
    
    1. “Hey !!”
    2. “Hey Rihanna!!”
    3. None of the above.

  53. What is the output of this page? (1 correct answer)
    <% request.setAttribute("1007", Integer.valueOf(10)); %>
    <html>
      <body>
        Number is ${1007}!!
      </body>
    </html>
    
    1. “Number is !!”
    2. “Number is 10!!”
    3. “Number is 1007!!”

  54. What is the output of this page? (1 correct answer)
    <% request.setAttribute("1007", Integer.valueOf(10)); %>
    <html>
      <body>
        Number is ${"1007"}!!
      </body>
    </html>
    
    1. “Number is !!”
    2. “Number is 10!!”
    3. “Number is 1007!!”

  55. What is the output of this page? (1 correct answer)
    <% request.setAttribute("1007", Integer.valueOf(10)); %>
    <html>
      <body>
        Number is ${requestScope["1007"]}!!
      </body>
    </html>
    
    1. “Number is !!”
    2. “Number is 10!!”
    3. “Number is 1007!!”

  56. Consider the following code.
    package model;
    public class Person {
       private String fullName;
       public String getFullName() {
          return fullName;
       }
       public void setFullName(String fullName) {
          this.fullName = fullName;
       }
    }
    
    <jsp:useBean id="person" class="model.Person">
      <jsp:setProperty name="person" property="fullName" value="Josh Childress" />
    </jsp:useBean>
    <html>
      <body>
        Hey you ${person.fullName}!
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. Hey you !
    2. Hey you Josh Childress!
    3. None of the above.

  57. Consider the following code.
    package model;
    public class Person {
       private String name;
       public String getFullName() {
          return name;
       }
       public void setFullName(String fullName) {
          this.name = fullName;
       }
    }
    
    <jsp:useBean id="person" class="model.Person">
      <jsp:setProperty name="person" property="fullName" value="Josh Childress" />
    </jsp:useBean>
    <html>
      <body>
        Hey you ${person.fullName}!
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. Hey you !
    2. Hey you Josh Childress!
    3. None of the above.

  58. Consider the following code.
    package model;
    public class Person {
       private String fullName;
       public String getFullName() {
          return fullName;
       }
       public void setFullName(String fullName) {
          this.fullName = fullName;
       }
    }
    
    <jsp:useBean id="person" class="model.Person">
      <jsp:setProperty name="person" property="fullName" value="Josh Childress" />
    </jsp:useBean>
    <html>
      <body>
        Hey you ${person}!
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. Hey you !
    2. Hey you Josh Childress!
    3. None of the above.

  59. Consider the following code.
    package model;
    public class Person {
       private String fullName;
       public String getFullName() {
          return fullName;
       }
       public void setFullName(String fullName) {
          this.fullName = fullName;
       }
       public String toString() {
          return fullName;
       }
    }
    
    <jsp:useBean id="person" class="model.Person">
      <jsp:setProperty name="person" property="fullName" value="Josh Childress" />
    </jsp:useBean>
    <html>
      <body>
        Hey you ${person}!
      </body>
    </html>
    

    What is the output? (1 correct answer)

    1. Hey you !
    2. Hey you Josh Childress!
    3. None of the above.

  60. What is the output of this code? (1 correct answer)
    <%
      request.setAttribute("email", "request@info");
      session.setAttribute("email", "session@info");
      pageContext.setAttribute("email", "page@info");
      application.setAttribute("email", "application@info");
    %>
    <html>
      <body>
        Contact an administrator at ${email}.
      </body>
    </html>
    
    1. Contact an administrator at page@info.
    2. Contact an administrator at session@info.
    3. Contact an administrator at request@info.
    4. Contact an administrator at application@info.

  61. What is the output of this code? (1 correct answer)
    <%
      session.setAttribute("email", "session@info");
      application.setAttribute("email", "application@info");
    %>
    <html>
      <body>
        Contact an administrator at ${email}.
      </body>
    </html>
    
    1. Contact an administrator at session@info.
    2. Contact an administrator at application@info.

  62. What is the output of this code? (1 correct answer)
    <%
      request.setAttribute("email", "request@info");
      session.setAttribute("email", "session@info");
    %>
    <html>
      <body>
        Contact an administrator at ${email}.
      </body>
    </html>
    
    1. Contact an administrator at request@info.
    2. Contact an administrator at session@info.

  63. What is the output of this code? (1 correct answer)
    <%
      request.setAttribute("email", null);
      session.setAttribute("email", "session@info");
    %>
    <html>
      <body>
        Contact an administrator at ${email}.
      </body>
    </html>
    
    1. Contact an administrator at .
    2. Contact an administrator at session@info.

© 2009 Nikos Pougounias. A free contribution to the Java community. Please distribute it for free. https://nikojava.wordpress.com

Answers

  1. a
  2. a
  3. a, b, c, e
  4. a, e
  5. a
  6. a, c, d
  7. b
  8. a
  9. b
  10. a
  11. a
  12. a
  13. a
  14. a
  15. b
  16. a
  17. c
  18. a
  19. c
  20. b
  21. b
  22. a
  23. b
  24. b
  25. b
  26. a
  27. b
  28. b
  29. b
  30. b
  31. a
  32. b
  33. a
  34. b
  35. b
  36. a
  37. b
  38. a
  39. a
  40. a
  41. b
  42. b
  43. c
  44. c
  45. c
  46. b
  47. a
  48. b
  49. b
  50. a
  51. b
  52. a
  53. c
  54. c
  55. b
  56. b
  57. b
  58. c
  59. b
  60. a
  61. a
  62. a
  63. b

2 Responses to Free SCWCD Mock Exam for EL

  1. priya says:

    Thanks for the questions.Quite interesting.

  2. […] Free SCWCD Mock Exam for EL […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: