SCWCD
Question 11
What will be the output of the following JSP code?
<html><body> <%! int a = 20; %> <% int a = 10; %> <%! int b = 30; %> Now b = <%= b * a %> </body></html>
A Now b = 300
B Now b = 600
C The code will not compile
D Now b = 30
E Now b = 0
AnswerBThe local variable a in scriptlet overwrites the variable a in global declaration
Question 12
Consider the following code snippet of servlet code:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
String value = getValue ();
if (value == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "Failed");
response.sendRedirect ("test.jsp");
}
If the getValue () method returns null , which of the following statements are true?
A The code will work without any errors or exceptions B An IllegalStateException will be thrown
C An IOException will be thrown
D A NullPointerException will be thrown
Answer
B
Since response is already commited
Question 13
Which of the following statements is true regarding MyServlet?
import javax.servlet.*;
import javax.servlet.http.*:
import java.io.*;
public class MyServlet extends HttpServlet implements SingleThreadModel
{
String myName;
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
response.setContentType("text/plain");
PrintWriter out = res.getWriter();
myName = req.getParameter("name");
sayHello(out);
out.close();
}
public void sayHello(PrintWriter out) {
out.println("Hello " + myName);
}
}
A MyServlet is thread safe
B MyServlet is not thread safe because myName is an instance variable
C MyServlet is not thread safe because MyServlet implements SingleThreadModel.
D None of the above
Answer
A
Question 14
Which of the following combinations regarding Design Patterns are correct?
A Business Delegate - Reduces the coupling between presentation-tier clients and business services.
B Data Access Object - Allows for Multiple Views using the same model
C MVC - Enables easier migration to different persistence storage implementations.
D Value Object - Reduces Network Traffic
Answer
A and D
Question 15
Which of these is true about deployment descriptors. Select one correct answer.
A The order of elements in deployment descriptor is important. The elements must follow a specific order.
B The elements of deployment descriptor are not case insensitive
C The servlet-mapping element, if defined, must be included within the servlet element.
D The web-app element must include the servlet element
Answer
A