Title: Test03- Requires Respondus LockDown Browser
Course: Java Programming Intermediate (APT TEMPLATE) > Section: Test03

Exam to test the JSP competency of this course.

Q: When a JSP is requested for the first time, the JSP
- calls the servlet that it is associated with
- calls the built-in request object
- is converted into a servlet
- is converted into HTML
A: is converted into a servlet

Q: Which of the following is true about JSP compared to servlets?
- JSP and servlets are both used for presentation and processing
- JSP consist of JavaScript code within an HTML page and servlets consist of HTML code within a Java page.
- JSP are used for processing and servlets for presentation
- JSP consist of Java code within an HTML page and servlets consist of HTML code within a Java page.
A: JSP consist of Java code within an HTML page and servlets consist of HTML code within a Java page.

Q: Which of the following JSP tags is used to display string values?
- <%   %>
- <%=   %>
- <%-- --%>
- <%!   %>
A: <%=   %>

Q: Which of the following JSP tags is used to set whole page conditions?
- <%   %>
- <%=   %>
- <%-- --%>
- <%@   %>
A: <%@   %>

Q: Which of the following JSP tags is used to declare scriptlet sections of code?
- <%   %>
- <%=   %>
- <%-- --%>
- <%@   %>
A: <%   %>

Q: Which of the following is a valid HTML comment?
- // comment
- <!--comment -->
- <%-- comment -->
- </comment>
A: <!--comment -->

Q: The css-1.css file is located in which directory?

<link rel="stylesheet" href="../css/css-1.css" />
- In the current directory.
- In the css directory that is one level up from the current directory
- In the css directory located in the WEB-INF directory
- In the css directory located at the same level as the current directory
A: In the css directory that is one level up from the current directory

Q: What is true about the following line of code?

<%! int myNumber = 0; %>
- The same myNumber variable will be accessible to all browsers accessing the page.
- The myNumber variable will be different for browsers accessing the page from different computers.
- The myNumber variable will be different for all browsers accessing the page even if on the same computer.
- The myNumber variable can store decimal numbers.
A: The same myNumber variable will be accessible to all browsers accessing the page.

Q: An HTML form can be used to pass data to
- another HTML page
- a JavaScript server
- a CSS page
- a JSP
A: a JSP

Q: What happens when the button in the following form is selected?

<form action="employeeProcessor.jsp" method="GET"
Address: <input type="text" name="address"><br>
<input type="submit"></form>
- The data in the address text box is passed to the get method.
- The user is prompted to enter an address.
- Data in the address text box is passed to the employeeProcessor.jsp file.
- Address data is passed but does not appear in the URL.
A: Data in the address text box is passed to the employeeProcessor.jsp file.

Q: Which one of the following attributes specify the destination for form submissions?
- href
- location
- action
- method
A: action

Q: Which of the following attribute values should be used if a database is accessed in the application?
- PROCESS
- GET
- METHOD
- POST
A: POST

Q: Which of the following is true regarding the form element name attribute?
- Its use is encouraged in XHTML.
- It can indicate the id of the form.
- It is a primitive type.
- It is supported in HTML5.
A: It is supported in HTML5.

Q: Which of the following JSP expressions is valid?
- <%= request.getParameter("phoneNumber"); %>
- <%= request.getParameter("phoneNumber") %>
- <%= String occupation = request.getParameter("phoneNumber"); %>
- <%= String occupation = request.getParameter("phoneNumber") %>
A: <%= request.getParameter("phoneNumber") %>

Q: Which is true about the following code:

<% String skillLevel= request.getParameterValues("skillLevel"); %>
- The skillLevel variable will be assigned the string value "skillLevel".
- Returns all values of the skillLevel parameter or null if none exist.
- The skillLevel variable will be assigned the string value of the skillLevel attribute in the Request object.
- Returns NULL since the statement is not formatted correctly.
A: The skillLevel variable will be assigned the string value of the skillLevel attribute in the Request object.

Q: In general, the GET method is preferred to the Post method when:
- When no data changes are made on the server.
- The request calls a web service.
- The request writes data to the server.
- When transferring more than 4 KB of data
A: When no data changes are made on the server.

Q: To use a custom Java class in a JSP, the class can be imported using a:
- JSP scriptlet
- JSP expression
- JSP directive
- JSP declaration
A: JSP directive

Q: Which of the following is a valid JSP comment?
- <b><span style="font-family:'Courier New'"><span style="font-size:9pt">// comment</span></span></b>
- <b><span style="font-family:'Courier New'"><span style="font-size:9pt"><!--comment --></span></span></b>
- <b><span style="font-family:'Courier New'"><span style="font-size:9pt"><%-- comment --%></span></span></b>
- <b><span style="font-family:'Courier New'"><span style="font-size:9pt"></comment></span></span></b>
A: <b><span style="font-family:'Courier New'"><span style="font-size:9pt"><%-- comment --%></span></span></b>

Q: The employeeCount variable below:

<%! int employeeCount = 1; %>
- is initialized each time the page is requested
- is an instance variable that is not thread-safe
- is optimized by the JSP engine
- is invalid JSP code
A: is an instance variable that is not thread-safe

Q: When a JSP is requested for the first time, the JSP engine:
- generates a servlet for the JSP and creates one instance (compiled executable) of the servlet class
- generates a servlet for the JSP and creates multiple instances (compiled executables) of the servlet class
- returns back a confirmation to the browser that multiple servlets were created correctly
- returns back a confirmation to the browser that a single servlet was created correctly
A: generates a servlet for the JSP and creates one instance (compiled executable) of the servlet class

Q: When a JSP is requested after the first time by a browser, the JSP engine:
- creates a thread that has its own copy of the instance variables
- creates a thread that has its own copy of the local variables
- creates an instance of the JSP that has its own copy of the instance variables
- creates an instance of the JSP that has its own copy of the local variables
A: creates a thread that has its own copy of the local variables

Q: A session object is created:
- every time a browser makes a request for a web page
- every time a browser requests a servlet
- every time a browser requests a jsp
- the first time a browser requests a servlet or JSP from a web site
A: the first time a browser requests a servlet or JSP from a web site

Q: The current session object can be retrieved by using the getSession method of the
- HttpSession class
- response object
- the request object
- the ServletContext object
A: the request object

Q: The current session object is available:
- only to JSP with authentication
- only to servlets less than 4KB
- to both servlets and JSP
- to HTML pages
A: to both servlets and JSP

Q: Which of the following statements is true about cookies?
- Cookies are small text files stored on the client.
- Cookies are small text files stored on the server.
- Cookies are objects that are stored on the client.
- Cookies are objects that are stored on the server.
A: Cookies are small text files stored on the client.

Q: Cookie data is/are stored in:
- value::key pairs
- attribute::name pairs
- name::key pairs
- name::value pairs
A: name::value pairs

Q: What is the result of the following line of code?

<%@ page import="college.*" %>
- a JSP directive tag is used to import the classes in the college package
- a JSP scriptlet tag is used to include the classes in the college package
- a JSP expression tag is used to import the classes in the college servlet
- a JSP declaration tag is used to include the servlets in the college package
A: a JSP directive tag is used to import the classes in the college package

Q: Which of the following is true about persistent cookies?
- are removed after the session ends
- exist after the session ends
- can’t be deleted
- are often called hidden fields
A: exist after the session ends

Q: Which of the following methods should be used to delete a cookie?
- deleteCookie(cookieName)
- setMaxAge(0)
- removeCookie(cookieName)
- setCookie(cookieName, NULL)
A: setMaxAge(0)

Q: What is the result of the following code?

<% Student student = new Student(firstName, lastName,
phoneNumber, skillLevel); %>
- creates an object named student based on the Student class calling a constructor with four arguments
- creates an object named Student based on the student class calling a constructor with four arguments
- creates an object named Student based on the student class calling an internal mutator method with four arguments
- creates an object named student based on the Student class calling an internal mutator method with four arguments
A: creates an object named student based on the Student class calling a constructor with four arguments