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 2, 2009

SCWCD Questions

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

Answer
14 What is the default scope for

A application
B session
C page
D request

Answer
C
The default scope attribute for useBean is page.
Answer
15 Which of the following is the proper way to include java.util package in your jsp page?

A <%@page:import package="java.util">
B <%@ page import = "java.util.*" %>
C <%= import java.util.*; %>
D <%@ page import="java.util.*" %>

Answer
D
Answer D is the correct choice. Answer A is incorrect because, there is no such thing called page import package. Answer B is incorrect because , we cannot have space between page and = sign. Answer c is correct, because it is a JSP expression.
Answer
16 To send binary output to response, which method of HttpServletResponse is used to get the Writer/ Stream object ?

A getStream
B getWriter
C getBinaryOutputStream
D getOutputStream
E getBinaryStream

Answer
D
The getOutputStream is used for sending binary data. The getWriter is used for sending character data only.
Answer
17 <%@ page language ="java" session="false" isErrorPage="false" %>
which of the following JSP implicit object will not be available to the JSP page ? Select two

A session
B request
C application
D exception

Answer
A and D
Since we are disabling the session by using session="false", session will not be available. And since this page is not an error page , so exception also will not be available.
Answer
18 Which among the following will compile ?

A <% int x=10 %>
B <%= "hello how are you" %>
C <%= "hello" ;% >
D <%! int x=10 %>

Answer
B
Option B is the correct choice. A is in correct because there is no semi colon present. The same rule applies to option D also. Option C is in correct because of semi colon.
Answer
19 In a JSP custom tag , which method would you use to access JSP implicit variable that references application scope ?

A PageContext.getOut()
B jspFactory.getPageContext()
C TagSupport.getValue(String)
D pageContext.getServletContext()

Answer
D

Answer
20 Which method is used to retrieve objects from session?

A getAttribute method of javax.servlet.ServletSession.
B getAtrribute method of javax.servlet.HttpSession
C getAttribute method of javax.servlet.http.Session
D getAttribute method of javax.servlet.http.HttpSession
E getAttribute method of javax.servlet.HttpSession

Answer
D
All other answers are invalid because no such classes present.

http://www.javacertificate.net/scwcd_2.htm

No comments: