Welcome Message

Hi, welcome to my website. This is a place where you can get all the questions, puzzles, algorithms asked in interviews and their solutions. Feel free to contact me if you have any queries / suggestions and please leave your valuable comments.. Thanks for visiting -Pragya.

November 1, 2009

SCWCD Questions

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
Choices A and D are correct. In a normal scenario, presentation-tier components (e.g. a JSP) interact directly with business services. As a result, the presentation-tier components are vulnerable to changes in the implementation of the business services: when the implementation of the business services change, the code in the presentation tier must change. The goal of the Business Delegate object design pattern is to minimize the coupling between presentation-tier clients and the business service API, thus hiding the underlying implementation details of the service. Thus choice A is correct. Choice B is incorrect as it's the MVC design pattern rather than the DAO (Data Access Object), which provides Multiple Views using the same model. Choice C is incorrect as it's the DAO (Data Access Object) pattern, which enables easier migration to different persistence storage implementations. The Value Object is used to encapsulate the business data. A single method call is used to send and retrieve the Value Object. When the client requests business data from an enterprise bean, the enterprise bean can construct the Value Object, populate it with its attribute values, and pass it by value to the client. Thus choice D is also correct.

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
The servlet specifications specifies a specific order of deployment descriptor. b is incorrect because elements are case-sensitive. The servlet-mapping element should be included within the element. So c is incorrect. All the elements within the web-app element are optional. So d is incorrect.

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
The servlet specifications specifies a specific order of deployment descriptor. b is incorrect because elements are case-sensitive. The servlet-mapping element should be included within the element. So c is incorrect. All the elements within the web-app element are optional. So d is incorrect.

Which element of the deployment descriptor of a web application includes the welcome-file-list element as a sub element.

A
B
C
D
E

Answer
D
The contains the element.

Which of the following is legal JSP syntax to print the value of i. Select the one correct answer

A <<%int i = 1;%>
<%= i; %>
B <%int i = 1;
i; %>
C <%int i = 1%>
<%= i %>
D <%int i = 1;%>
<%= i %>
E <%int i = 1%>
<%= i; %>

Answer
D
When using scriptlets (that is code included within <% %>), the included code must have legal Java syntax. So the first statement must end with a semi-colon. The second statement on the other hand is a JSP expression. So it must not end with a semi colon.

Question
11 What will be the output of the following JSP code?
<%! int a = 20; %> <% int a = 10; %> <%! int b = 30; %> Now b = <%= b * a %>

A Now b = 300
B Now b = 600
C The code will not compile
D Now b = 30
E Now b = 0

Answer
A
In the first declaration <%! int a = 20; %>, the variable "a" will be declared as an instance variable. In the second declaration <% int a = 10; %>, the variable "a" will be declared as a local variable inside the service method. And at the time of multiplication it will use the local variable.

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 the response is already committed by calling the sendError() , we cannot redirect it once again.

No comments: