JAVATECH NEWS

Java

CORE JAVA

Interview

OFF-CAMPUS

Sunday 23 November 2014

Advance Java Interview Question Set-1

50 Advance Java Interview Questions with answer.

1.Which of the following statement is true for the Type 2 JDBC driver?

A) A Type 2 driver converts JDBC calls into calls for a specific database.
B) This driver is referred to as a "native-API, partly Java driver."
C) As with the Type 1 driver, some binary code may be required on the client machine, which means this type of driver is not suitable for downloading over a network to a client.
D) All of the above
Ans-B

2. What is the key difference between using a <jsp:forward> and HttpServletResponse.sendRedirect()?

A. forward executes on the client while sendRedirect() executes on the server.
B. forward executes on the server while sendRedirect() executes on the client.
C. The two methods perform identically.
Ans-B

3. What exception is thrown when Servlet initialization fails ?

A. IOException
B. ServletException
C. RemoteException
Ans-B

4.Which of the following is true?

A.Servlet is instantiated every time when request is made.
B.They are the mechanism used by the class loader to load to download applets
C.They can be used instead of CGI scripts
D.They requires a web browser that support jdk 1.1.
Ans-A

5. Which of the following can not be used as the scope when using a JavaBean with JSP?

A.application
B.session
C.request
D.response
Ans-D

6. Which JSTL snippet can be used to perform URL Rewritng?

A. <a href='<c:url ="foo.jsp”/>'/>
B. <a href='<c:link url="foo.jsp”/>'/>
C. <a href='<c:url value="foo.jsp”/>'/>
D. <a href='<c:link value="foo.jsp”/>'/>
Ans: C

7. The JDBC-ODBC Bridge supports multiple concurrent open statements per connection?

A- True
B- False
Ans-B

8.Which of the following is not a standard method called as part of the JSP life cycle?

A. jspService()
B.jspInit()
C.jspDestroy()
D._jspService()
Ans-A

9. In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object ?

A. getServletInfo()
B. getInitParameters()
C. getServletConfig()
ANS: C

10. For a given ServletResponse response, which retrieves an object for writing binary data?

A. response.getWriter()
B. response.getOutputStream()
C. response.getOutputWriter()
D. response.getWriter().getOutputSTream()
Ans-B

11. What is wrong with the following code ?
<jsp:include page="MainMenu.jsp" flush="true"/>
<%
Cookie c = new Cookie("UserName", "Alastair Gulland");
response.addCookie(c);
%>

 A.Cookie class can not take parameters in it's constructor
 B.Although no error will be reported the use of the <jsp:include/> action means that the response object can't be used to create cookies.
 C.The <jsp:include/> action must be placed inside the script block
 D.The request object is used for creating cookies
Ans-B

12.  Are ResultSets updateable?

A.Yes, but only if you call the method openCursor() on the ResultSet, and if the driver and
database support this option
B. Yes, but only if you indicate a concurrency strategy when executing the statement, and
if the driver and database support this option
C. Yes, but only if the ResultSet is an object of class UpdateableResultSet, and if the driver
and database support this option
D. No, ResultSets are never updateable. You must explicitly execute DML statements (i.e.
insert, delete and update) to change the data in the underlying database
Ans:B

13. Which code line must be set before any of the lines that use the PrintWriter?

A.setpageType()
B.setContentType()
C.setcontextType()
D.setResponseType()
Ans B

14.Which of the following statements makes your compiled JSP page implement the SingleThreadModel interface?

A. <%@ page isThreadSafe="false" %>
B. <%@ page isThreadSafe="true" %>
Ans-A

15.Which of the following are session tracking technique?

A,URL rewriting, using session object, using response object, using hidden fields

B.URL rewriting, using session object, using cookies, using hidden fields

C.URL rewriting, using servlet object, using response object, using cookies

D.URL rewriting, using request object, using response object, using session object
Ans:B

16. Which method must be used to encode a URL passed as an argument to
HttpServletResponse.sendRedirect when using URL rewriting for session tracking?

A. ServletResponse.encodeURL
B. HttpServletResponse.encodeURL
C. ServletResponse.encodeRedirectURL
D. HttpServletResponse.encodeRedirectURL
Ans-D

17. Which JSTL code snippet can be used to import content from another   web resource?

A. <c:import url="foo.jsp"/>
B. <c:import page="foo.jsp"/>
C. <c:include url="foo.jsp"/>
D. <c:include page="foo.jsp"/>
E. Importing cannot be done in JSTL. A standard action must be used instead.
Answer: A

18.What is the full form of JDBC?

A.Java Database Connection
B.Java Database Connectivity
C.Java Database Commitment
D.Java Database Console
Ans-B

19. Instantiate the Spring IoC Container?

A. ApplicationContext context =new ClassPathXmlApplicationContext(“spring.xml”)
B. ApplicationContext context =new ClassPathxmlApplicationContext(“spring.xml”)
C. ApplicationContext context =new XmlApplicationContext(“Spring.bean.xml”)
D. ApplicationContext context =new  ApplicationContext(“spring.xml”)
Ans-A

20. Which type of Statement can execute parameterized queries?

A. PreparedStatement
B. ParameterizedStatement
C .ParameterizedStatement and CallableStatement
D. All kinds of Statements (i.e. which implement a sub interface of Statement)
Ans-A

21. Which packages contain the JDBC classes?
A.java.jdbc and javax.jdbc
B java.jdbc and java.jdbc.sql
C java.sql and javax.sql
D java.rdb and javax.rdb
Ans-C

22.How many JDBC drivers are there?

A.2
B.1
C.4
D.3
Ans-C.

23. State true or false :-The JDBC-ODBC bridge from Sun's Java Software does not provide network access to desktop databases like Microsoft access by itself.
A.True
B.False
Ans-B.

24. In servlet parameters are passed as pair in get request

A.value
B.name/value
C.Both can be used
D.None of the above
Ans:B

25. Which two are true about the JSTL core iteration custom tags? (Choose two.)

A. It may iterate over arrays, collections, maps, and strings.
B. The body of the tag may contain EL code, but not scripting code.
C. When looping over collections, a loop status object may be used in the tag body.
D. It may iterate over a map, but only the key of the mapping may be used in the tag body.
E. When looping over integers (for example begin='1' end='10'), a loop status object may not be used in the tag body.
Ans-A,C

26. When using a JavaBean to get all the parameters from a form, what must the property be set to (??? in the following code) for automatic initialization?
<jsp:useBean id="fBean" class="govi.FormBean" scope="request"/>
<jsp:setProperty name="fBean" property="???" />
<jsp:forward page="/servlet/JSP2Servlet" />

A.?
B.@
C.$
D.*
Ans-D

29.Which of the following is used to get servlet environment information?

A.ServletConfig object
B.ServletException object
C.ServletContext object
D.ServletRequest objects
Ans-C

30. What happens if you call the method close() on a ResultSet object?

A the method close() does not exist for a ResultSet. Only Connections can be closed.
B the database and JDBC resources are released
C you will get a SQLException, because only Statement objects can close ResultSets
D the ResultSet, together with the Statement which created it and the Connection from
which the Statement was retrieved, will be closed and release all database and JDBC resources
Ans:B

31. What is the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE?

A A result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does.
B Both types of result sets will make changes visible if they are closed and then reopened.
C You will get a scrollable ResultSet object if you specify one of these ResultSet constants.
D All of the above
Ans-D

32. How can a Servlet call a JSP error page ?

A This capability is not supported.
B When the servlet throws the exception, it will automatically be caught by the calling JSP page.
C The servlet needs to forward the request to the specific error page URL. The exception is passed along as an attribute named "javax.servlet.jsp.jspException".
D The servlet needs to redirect the response to the specific error page, saving the exception off in a cookie.
Ans-C

33. Different types of exceptions in JDBC are
1. BatchUpdateException
2. DataTruncation
3. SQLException
4. SQLWarning

A) 1,2,3
B) 1,3,4
C) 1,2,4
D) 1,2,3,4
Ans-D

34. how can a whole class be mapped as immutable in hibernate?
A.mutable-mapping=”false”;
B.mutable=”true”;
C.mutable=”false”;
D.None
Ans:C

35. Which retrieves all cookies sent in a given HttpServletRequest request?

A.request.getCookies()
B.request.getAttributes()
C.request.getSession ().getCookies()
D.request.getSession (). GetAttributes()
Ans:A

36.Servlet mapping defines

A.an association between a URL pattern and a servlet
B.an association between a URL pattern and a request page
C.an association between a URL pattern and a response page
D.All of the above
Ans-A

37. A JSP page needs to set the property of a given JavaBean to a value that is calculated with the JSP page. Which three jsp:setProperty attributes must be used to perform this initialization? (Choose three)

A. id
B. val
C. name
D. param
E. value
F. property
G. attribute
Ans-C,E,F

38. How many ServletConfig and servlet context objects are present in one application?
A.one each per servlet
B.one each per request
C.one each per response
D.Only one for entire application.
Ans-D

39.Which is the correct web application deployment descriptor element for defining a servlet initialization parameter?

A.<init-param>
<param-name>timeout</param-name>
<param-value>1000</param-value>
</init-param>
B. <servlet-param>
<param-name>timeout</param-name>
<param-value>1000</param-value>
</servlet-param>
C. <init-parameter>
<parameter-name>timeout</parameter-name>
<parametervalue>1000</parametervalue>
</init-parameter>
D. <servlet-parameter>
<parameter-name>timeout</parameter-name>
<parametervalue>1000</parameter-value>
</servlet-parameter>
Ans-A

40. The include() method of requestdispatcher

A.sends a request to anther resources like servlet,jsp or html
B.include resource of  file like servlet,jsp or html
C.appends the request and response object to the current servlet
D.None of the above
Ans-B

41. Which implicit object is used in a JSP page to retrieve values associated with <context-param> entries in the deployment descriptor?

A. config
B. request
C. session
D. application
Answer: D

42. How can you retrieve information from a ResultSet?

A.By invoking the method get(..., String type) on the ResultSet, where type is the
database type
B.By invoking the method get(..., Type type) on the ResultSet, where Type is an object
which represents a database type
C. By invoking the method getValue(...), and cast the result to the desired Java type.
D. By invoking the special getter methods on the ResultSet: getString(...),
getBoolean (...), getClob(...)
Ans:D

43. Which ensures that a JSP response is of type "text/plain"?

A.   <%@ page mimeType="text/plain" %>
B.   <%@ page contentType="text/plain" %>
C.   <%@ page pageEncoding="text/plain" %>
D.   <%@ page contentEncoding="text/plain" %>
Ans-B

44.  What is wrong with the following code ?

<%
if(strPassword.equals("boss"))
{
< jsp:forward page="Welcome.jsp" flush="true" / >
}
else
{
}
%>
A.Unmatched bracket in for statement
B.Flush attribute must be false
C.Keyword 'file' should be used instead of 'page' in the action
D.Actions cannot be used within scriptlet blocks
Ans-D

45. Servlet A receives a request that it forwards to servlet B within another web
application in the same web container. Servlet A needs to share data with servlet B
and that data must not be visible to other servlets in A's web application.
In which object can the data that A shares with B be stored?

A. HttpSession
B. ServletConfig
C. ServletContext
D. HttpServletRequest
Ans-D

46. Given the definition of MyServlet:
public class MyServlet extends HttpServlet {
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
session.setAttribute("arg","value");
session.invalidate();
response.getWriter().println("value=" + session.getAttribute("arg"));
 }
 }
What is the result when a request is sent to MyServlet?

A.An IllegalStateException is thrown at runtime.
B. An InvalidSessionException is thrown at runtime.
C. The string "value=null" appears in the response stream.
D. The string "arg=value" appears in the response stream.
Ans-A

47.Can we retrieve a whole row of data at once, instead of calling an individual ResultSet.getXXX method for each column ?

A. No
B. Yes
Ans:A

48. What is, in terms of JDBC, a DataSource?

A. DataSource is the basic service for managing a set of JDBC drivers
B. A DataSource is the Java representation of a physical data source
C. A DataSource is a registry point for JNDI-services
D. A DataSource is a factory of connections to a physical data source
Ans-D

49.Which security mechanisms protect the response stream?
A. data integrity
B. confidentiality
C. authentication
D. 1 and 2
Ans:D

50. Which prevent a servlet from handling requests.?

A. The servlet's init method does NOT return within a time period defined by the servlet container.
B. The servlet's init method throws a Servlet Exception
C The servlet's init method sets the Servlet Response's context length to 0
D. 1 and 2
Ans:D

No comments:

Post a Comment

Designed By Blogger Templates