Java Technologies - 2 PG DAC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Shriram Mantri Vidyanidhi Info Tech Academy

PG DAC JAVA Technoligies-2 Question Bank


JAVA

Contents
HIBERNATE ...................................................................................................................................................................... 1
JDBC................................................................................................................................................................................. 5
JSF.................................................................................................................................................................................... 8
JSP ................................................................................................................................................................................... 8
MVC ............................................................................................................................................................................... 14
SERVLET ......................................................................................................................................................................... 15
STRUTS .......................................................................................................................................................................... 23
SPRING .......................................................................................................................................................................... 26
SWING ........................................................................................................................................................................... 28

HIBERNATE
1. Hibernate entity can be
A: transient
B: detached
C: persistent
D: all of the above

2. When transaction completes, all the associated persistent objects still exists in memory but they lose
their association with the session on encountering one of the following method
A: session.flush()
B: trasaction.close()
C: session.close()
D: none of the above

3. In hibernate,If the developer is not certain about the existence of the object.
A: load() method should be used
B: get() method should be used
C: retrieve() method should be used
D: all the above are same with not much difference.

4. One of the following is not an interface from Hibernate core interfaces.


A: SessionFactory
B: Session
C: ConnectionFactory
D: Transaction

5. Session interface does


A: JDBC connection
B: gets Transaction
C: holds cache of persistent objects
D: all of the above

6. One of the following persist element index


1
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
A: <bag>
B: <list>
C: <set>
D: <map>

7. Which statement is wrong?


A: HQL is case insensitive for class names and properties
B: SQL operates on relations, HQL operates on objects.
C: HQL is ultimately generated into underlying SQL.
D: HQL supports polymorphic queries.

8. A join which combines result of both left and right outer join is
A: Left Right Join
B: Right Outer Join
C: Full Join
D: Left Join

9. Which class is used to create EntityManagerFactory ?


A: Persistence
B: EntityManager
C: EntityTranscation
D: EntityFactory

10. One of the following is ORM implementation


A: struts B: JSF C: hibernate D: spring

11. After EntityManager is closed, entity is in a __________ state.


A: dead
B: detached
C: managed
D: persistent
12. What is the root tag element in the hibernate configuration file?
A: <hibernate-cfg>
B: <hibernate-conf>
C: <hibemate-configuration>
D: <hibemate>

13. Once the hibernate session is closed, in which state the object remains?
A: detached
B: transient
C: pesistent
D: garbage collector

14. What is the root level element in hibernate mapping file?


a. <hibernate-mapping>
b. <session-mapping>
c. <sessionfactory-mapping>
d. None of the above

2
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
15. What does <generator-class=”native”/> means?
a. Generate primary key
b. Generate tables based on configuration
c. Generate sql statements on configuration
d. None

16. What does hibernate.hbm2ddl.auto.create this means?


a. Create tables automatically
b. Create session object automatically
c. Create session factory object automatically
d. None.

17. Which statement is correct about Hibernate?


a. The CacheMode controls how a particular session interacts with the second-level cache.
b. The CacheMode doesn’t control session interaction with the second-level cache.
c. Both the above
d. None of the above

18. When we integrate Hibernate via spring we don‘t need to take care of.
A: SessionFactory
B: Session
C: Both a and b. (since there is something called as “HibernateTemplate” in spring)
D: None of the above.

19. What is dirty checking in Hibernate?


a. object state changes in order to synchronize the updated state with the database
b. Remove the dirty data from data base.
c. Check the data when insert into data base.
d. None

20. What is the root level element in a hibernate mapping file?


a. < hibernate-mapping>
b. < session-mapping>
c. < sessionfactory-mapping>
d. none of the above

21. What does session.evict() method do?


a. remove the object and its collections from the first level cache
b. remove the object and its collections from the second level cache
c. remove the object and its collections from the data base
d. None of the above

22. What does hibernate.hbm2ddl.auto create this means?


a. create session object automatically
b. create tables automatically
c. create Session Factory object automatically
d. None

3
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
23. Is Hibernate Session threadsafe?
a) Yes b) no c) no relation with thread d) none

24. Which 2nd level cache is better in hibernate?


a. EHCache
b. GumoCache
c. DASCache
d. TestCache

25. Which statement is correct about session.load()?


a. load() will return null if there is no matching database row.
b. load() will throw an unrecoverable exception if there is no matching database row.
c. None of the above.

26. Which of the following is tag of hibernate.cfg.xml?


a. SQL variant to generate
b. Size of the database
c. All of the above
d. None of the above

27. How do we get a session object?


a. SessionFactory.get();
b. (session)SessionFactory.getObject();
c. SessionFactory.getSession();
d. SessionFactory.openSession();

28. How to enable query cache in hibernate?


a. hibernate.cache.query_cache true
b. hibernate.cache.use_query_cache true
c. hibernate.cache.query_cache yes
d. none

29. What does session.delete() do?


a. remove from sessionFactory
b. remove data from in momery.
c. remove from database.
d. All of the above.

30. The hibernate configuration file name is?


a. http.conf
b. web.config
c. persistence.xml
d. hibernate.cfg.xml

31. Load child object automatically when parent object is loaded?


a. lazy=yes
b. lazy=false
c. lazy=true
d. lazy=no
4
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
32. In order to create new session which function should be used ?
A: getSession(true)
B: getSession()
C: both A and B
D: getSession(false);

33. Which of the following is true?


a. Hibernate is a framework
b. Hibernate is an Object-Relational mapping (ORM) library for the java language.
c. Hibernate provides mapping for object-oriented domain model to a traditional relational database.
d. All of the above.

34. There are core interfaces that are used in just about every hibernate application. Using these
interfaces, you can store and retrieve persistent object and control transactions. Select all the interfaces
that you see.
a. Configuration interface
b. Query and Criteria interfaces
c. All of the above
d. None of the above

35. Which of the following is not hibernate session method?


a) Save () b) remove () c) persist () d) load ()

36. If the validation fails what will be returned by the validate () method?
a) Success b) input c) login d) error

JDBC
1. Which of the following code will you use to get a count of the columns in the result?
A. ResultMetaData rsmd=DatabaseMetaData.getMetaData();
int columns=rsmd.getColumnCount();
B. ResultSetMetaData rsmd=new ResultSetMetaData(result);
int columns=rsmd.getColumnCount();
C. ResultSetMetaData rsmd=result.getMetaData();
int columns=rsmd.getColumnCount();
D. DatabaseMetaData md=result.getMetaData();
int columns=md.getColumnCount();

2. The Jdbc driver that directly communicates with database protocol is


a. Type I c. Type II
b. Type III d. Type IV

3. What will the following line of code do? Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");


a. Load the Driver for Database access
b. Establish a connection with the specified database
c. Accesses data from a table
d. Create a ResultSet object
4. Which character is used to represent an input parameter in a PreparedStatement?
a. % b. * c. ? d. #

5
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
5. Which of the following statements is NOT true about a PreparedStatement
a. PreparedStatement is pre-compiled
b. PreparedStatement may have both IN and OUT parameters.
c. Execution of PreparedStatement is faster than Statement.
d. All of the above

6. Which class gives u connection from connection pool?


A: Driver B: DataSource C: DriverManager D: Connection

7. Which driver can be used for internet purpose?


A: Type 1 B: Type 2 C: Type 3 D: all the above

8. Which class gives connection?


A: Driver B: Statement C: DriverManager D: Connection

9. According to JDBC4, driver class name should be there inside


A: META-INF\java.sql.Driver file
B: Services\java.sql.Driver file
C: Services\META-INF\java.sql.Driver file
D: META-INF\services\java.sql.Driver file

10. If we use query statement inside “execute()” method of Statement, it will return
A: false B: true C: 1 D: 0

11. If we use update statement inside “execute()” method of Statement, it will return
A: false B: true C: 1 D: 0

12. When driver is not found, it results in


A: DriverNotFoundException
B: CIassNotfoundException
C: SQLException
D: None of the above.

13. Connection is
A: interface B: class C: package D: None of the above.

14. Name the most suitable execution method in JDBC , for firing DML queries.
a. executeQuery()
b. executeUpdate()
c. executeQueue()
d. executeDynamicQuery()

15. in the following code sample


Class.forName("Oracle.jdbc.OracleDriver");
String dbUrl="jdbc:oracle:thin:@host1:mydb";
Connection con=DriverManager.getConnection(dbUrl,"scott","tiger");
How to create PreparedStatement in order to support Scrollable and Read-only ResultSet?
a. con.prepareStatement(sql,TYPE_SCROLL_INSENSITIVE,CONCUR_UPDATABLE);
b. con.prepareStatement(sql,TYPE_FORWARD_ONLY,CONCUR_UPDATABLE);
6
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
c. con.prepareStatement(sql,TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY);
d. con.prepareStatement(sql,TYPE_SCROLLABLE,CONCUR_UPDATABLE);

16. PreparedStatements are actually _________________


a) Compiled b) not compiled
c) They don’t compile but directly get executed d) none of the above

17. Which driver is efficient and always preferable for jdbc applications?
a) Type – 4 b) Type –1 c) Type –3 d) Type –2

18. The parameters of PreparedStatement object are _______ when the user clicks on the query button.
a) Initialized b) started c) paused d) stopped

19. Name of Type4 driver is


A. Native-Protocol Driver C. JDBC-ODBC bridge
B. Network-Protocol Driver D.Native-API Driver

20. By default ResultSet is


A. None of these
B. TYPE_SCROLL_INSENSITIVE
C. TYPE_FORWARD_ONLY
D. TYPE_SCROLL_SENSITIVE

21. PreCompiled SQL statements are stored in


A. None of these C. CallableStatement
B. Statement D. PreparedStatement

22. The checked exception which we need to handle in case of jdbc is


A. None of these C. SQLException
B. IOException D. JDBCException

23. Type1 driver makes use of


A. None of these C. Odbc
B. Jdbc D. Middleware

24. If ResultSet is Scrollable we can invoke


A. Absolute
B. Next
C. Previous
D. all of the above
25. Stored Procedures can be called using
A. PreparedStatement
B. Statement
C. CallableStatement
D. None of these

26. One of the following is a class


a) Connection
7
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
b) Statement
c) ResultSet
d) none of the above

27. Every driver class has ________ which registers itself with the DriverManager
a) Static method
b) static block
c) constructor
d) none of the above
JSF
1. Front Controller in JSF is
a) DispatcherServlet
b) ActionServlet
c) FacesServlet
d) none of the above

2. Configuration file in JSF is


a) webconfig.xml
b) jsf-config.xml
c) applicationContext.xml
d) none of the above [it is “faces-config.xml”]

3. Annotation which is used to define bean in JSF is


a) @managedBean
b) @Bean
c) @Component
d) @JSFBean

4. In case of JSF component tree is stored inside


A. ServletContext
B. ApplicationContext
C. FacesContext
D. None of the above

JSP
1. Which of the attribute of JSP mentioned below is not available in servlet?
A: request
B: session
C: page
D: context

2. A method can be defined inside


A: JSP scriptlet
B: JSP declaration
C: JSP expression
D: none of the above

3. One of the following cannot be overridden while writing JSP page


A: _jspService
8
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
B: jspInit
C: JspDestroy
D: jspService

4. Which attribute cannot be used inside <jsp:useBean>


A: class B: id C: name D: scope

5. If we want to include some dynamic page in JSP we should use


A: <jsp:include page=”/somepage”/>
B: <%@ include file=”/somefile” %>
C: RequestDispatcher rd=request.getRequestDispatcher("/somepage");
rd.include(request,response);
D: none of the above

6. One of the following JSTL tag performs URL rewriting.


A: link B: url C: aHref D: import

7. Given
<jsp:useBean id=”a1” scope=”request” class=”mypack.Customer”/>
What is the syntax to read Customer object?
A: ${requestScope.a1}
B: <%=request.getAttribute(“a1”)%>
C: ${a1}
D: all the above

8. Which JSP expression tag will print the context initialization parameter named “uname”?
A: <%= application.getAttribute(“uname”)%>
B: <%= application.getInitParameter(“uname”)%>
C: <%= request.getParameter(“uname”)%>
D: <%=contextParam.get(“uname”)%>

9. When a JSP page is compiled, what is it turned into?


a. Applet
b. Servlet
c. Application
d. Mailet

10. The implicit JSP objects like request, response, and out are only visible in the _jspService() method.
a. True b. False
11. To fill up all bean properties with HTML form elements which of the following statements can be used,
a. <jsp:synchronize name="BeanName" />
b. <jsp:setProperty name="BeanName" property="" />
c. <jsp:setProperty name="BeanName" property="*" />
d. <jsp:setProperty name="BeanName" property="All" />

12. Why use RequestDispatcher to forward a request to another resource, instead of using a sendRedirect?
a. Redirects are no longer supported in the current servlet API.
b. Redirects are not a cross-platform portable mechanism
c. The RequestDispatcher does not use the reflection API.
9
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
d. The RequestDispatcher does not require a round trip to the client, and thus is more efficient and
allows the server to maintain request state.

13. The attribute which defines your jsp page as a exception handling page is
a. isExceptionPage
b. exceptionPage
c. isErrorPage
d. w. errorPage

14. To use the ServletContext in Jsp the implicit object is


a. Application c. context
b. Config d. page

15. Which attribute can be used inside <jsp:setProperty> and <jsp:getProperty>


A: class B: id C: name D: scope

16. What is the role of J2EE container in web application?


A: It provide the life-cycle.
B: It compiles the JSP.
C: Loads the classes of the JSP and servlet.
D: All of the above

17. How can we enable session tracking for JSP PAGES?


A: Enable cookies in the browser
B: set session attribute value is true in page directive
C: set is Session attribute true in page directive
D: Enable session tracking in the browser

18. What is the effect of executing the following JSP statement, assuming a class with name Employee
exists in class’s package?
<%@ page import = "classes.Employee" %>
<jsp:useBean id="employee" class="classes.Employee" scope="session"/>
<jsp:setPropertv name="employee" property="*"/>
A: The code does not compile as there is no properly attribute of setProperty tag.
B: The code does not compile as property attribute cannot take * as a value.
C: The code sets value of all properties of employee bean to "*".
D: The code sets the values of all properties of employee bean to matching parameters in request object.
19. If a JSP page overrides the jsplnit() method using a declaration JSP tag, which phase of the JSP page
life-cycle generates the overridden method in the servlet?
A: page translation. B: JSP page compilation.
C: call jsplnit() D: call_jspService().

20. <jsp:useBean id="a1" scope="request"class="mypack.Customer"./>


What is the syntax to read Customer object?
A: ${requestScope.a1}
B: <%=request.getAttribute("a1")%>
C: ${a1}
D: All the above

10
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
21. Which method can be overridden while writing JSP page
a. jspInit
b. JspDestroy
c. A and B both
d. None of the above

22. The implicit object “out” of Jsp is of type


a. PrintWriter
b. InputStream
c. JspWriter
d. JspPrintWriter

23. Two of the following are the attributes of <%taglib%> directive.


a) Name b) prefix c) value d) uri e) url

24. The attribute which informs container about a particular error jsp page is
A. isExceptionPage
B. exceptionPage
C. isErrorPage
D. errorPage

25. Which of the following is true for JavaBean?


a) It can not be a GUI component.
b) It never implement Serializable interface
c) It has Zero argument constructor
d) It is a distributed component

26. if a jsp page overrides the jspInit method using a declaration JSP tag , which phase of the jsp page life-
cycle generates the overridden method in servlet?
a) Page translation b) JSP page compilation c) call jspInit() d) call _jspService()

27. Select the correct statement about following code (Select one)
<%@page language="java"%>
<html><body>
<%
response.getOutputStream().print("hello");
out.print("World");
%>

</body></html>
a. It will print “hello World” in the output
b. It will generate compile time errors
c. It will throw runtime exceptions (java.lang.IllegalStateException: getOutputStream() has already
been called for this response)
d. It will only print “hello”

28. Which is not a valid scope for javabean in JSP?


a) Page b) session c) request d) global

11
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
29. Which among the following will compile?
a) <% int x=10 %>
b) <%= “hello how are you” %>
c) <%= “hello” ; %>
d) <%! Int x=10 %>

30. Which of the following statements is true regarding the scope of “request” in JSP?
a. Objects with request scope are accessible from pages processing the same request where they
were created.
b. All references to the object shall be released after the request is processed: in particular if the
request is forwarded to a resource in the same runtime , the object is still reachable.
c. References to the objects in request scope are stored in a request object.
d. All of the above.

31. Which of the following statements makes your compiled JSP page implement the SingleThreadModel
interface?
a. <%@ page isThreadSafe="false" %>
b. <%@ page isThreadSafe="true" %>

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.

33. 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. All c. @ d. =

34. Choose the statement that best describes the relationship between JSP and servlets:
a. Servlets are built on JSP semantics and all servlets are compiled to JSP pages for runtime usage.
b. JSP and servlets are unrelated technologies.
c. Servlets and JSP are competing technologies for handling web requests. Servlets are being
superseded by JSP, which is preferred. The two technologies are not useful in combination.
d. JSPs are built on servlet semantics and all JSPs are compiled to servlets for runtime usage.

35. What alternatives exist to embedding Java code directly within the HTML markup of your JSP page?
a. Moving the code into your session manager.
b. Moving the code into scriptlets.
c. Moving the code into JavaBeans and servlets
d. Moving the code into a transaction manager

36. What is the initial contact point for handling a web request in a Page-Centric architecture?
12
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
a. A JSP page
b. A JavaBean.
c. A servlet.
d. A session manager

37. Which object would you use to share user specific information between JSPs?
a. Request b. Response c. Session d. Application

38. Which of the following rules must a reusable JavaBeansTM component adhere to?
a. The Bean class must provide zero argument constructors.
b. The Bean must have a corresponding BeanInfo class.
c. The Bean must only use visible components.
d. The Bean must not be serializable.

39. Which of the following is not a standard method called as part of the JSP life cycle?
a. jspInit()
b. jspService()
c. _jspService()
d. jspDestroy()

40. If you want to override a JSP file's initialization method, within what type of tags must you declare the
method?
a. <@ @>
b. <%@ %>
c. <% %>
d. <%! %>

41. Which of the following cannot be used as the scope when using a JavaBean with JSP?
a. Application
b. Session
c. Request
d. Response
e. Page

42. 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.

43. Two of the following methods can be overridden in jsp page


a) jspInit b) _jspService c) jspGet d) doPost e) jspDestroy

44. One of the following is jsp expression


a) <%! %> b) <% %> c) <%@ %> d) <%= %>

45. One of the following is not an implicit jsp object


a) context b) config c) session d) pageContext

46. One of the following is an additional attribute in Jsp as compare to servlet attributes .
13
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
a) Request b) context c) page d) response e) session

47. Two of the following are used to call bean class setter and getter methods.
A) setAttribute b) getProperty c) getAttribute d) setProperty

48. One of the following is not a jsp standard action


a) forward b) include c) page d) param

49. When jsp is generated into servlet it is derived from which class
a) HttpServlet b) HttpJspBase c) HttpJspPage d) Servlet

50. Pure java code can be written inside


A: JSP scriptlet B: JSP declaration
C: JSP expression D: none of the above

51. For every tag encounter, a new instance of Tag Class is created.
a. True b. False

52. One of the following JSTL tag performs URL rewriting Select one:
A.url
B.aHref
C.import
D.link

53. Generated servlet in case of JSP extends _____.


A. None of these C. HttpJspBase
B. Service D. HttpServlet

54. Which attribute cannot be used inside <jsp:useBean>


a. scope
b. name
c. id
d. class
55. One of the following cannot be overridden while writing JSP page
A. jspService
B. JspDestroy
C. jspInit
D. _jspService

56. All EL implicit objects are internally


A. Map
B. List
C. Set
D. none of these

MVC
1. One of the following is responsible for responding to user input and perform interactions on the data
model objects.
14
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
A: model B: view C: controller D: none of them

2. In MVC architecture model is _____________


a) jsp b) javabean c) servlet

SERVLET
1. Select the correct statement
A: ServletConfig is not available inside constructor
B: servlet gets instantiated every time a new request comes.
C: programmer has to override “service()” method of parent class
D: GenericServlet is a concrete class

2. One of the following is not a Parameter


A: init B: request C: session D: context

3. In order to retrieve existing session only [not to create new] which function should be used ?
A: getSession(true) B: getSession()
C: getSession(false) D: all of the above

4. Select wrong statement


A: forward is faster than redirect
B: redirect is only within the same context
C: if client does not accept cookies, URLRewriting is the best option you have.
D: cookies are internally used inside session mechanism.

5. Cookies are always added to?


a) Request
b) Response
c) Session
d) r.Application

6. Select the wrong statement


A: ServletConfig is not available inside constructor
B: servlet gets instantiated every time a new request comes.
C: programmer need not override “service()” method of parent class, instead he can override required
doXXX() methods.
D: GenericServlet is abstract class

7. One of the following is not an attribute


A: init B: request C: session D: context

8. Which of the following variables are thread-safe?


a. session-scoped
b. application-scoped
c. servlet instance
d. request-scoped

15
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
9. execute() for any DML or DDL return Boolean

10. Technique for maintaining anonymous user transaction on web


a) cookies b) URL Rewriting c) session d) all of the above

11. what is recommended for servlet Thread safety


1. Your servlet service() method should not access any member variables, unless these member
variables are thread safe themselves.
2. Your servlet service() should not reassign member variables, as this may affect other threads
executing inside the service() method. If you really, really need to reassign a member variable, make sure
this is done inside a synchronized block.
3. Rule 1 and 2 also counts for static variables.
4. Local variables are always thread safe. Keep in mind though, that the object a local variable points
to, may not be so. If the object was instantiated inside the method, and never escapes, there will be no
problem. On the other hand, a local variable pointing to some shared object, may still cause problems.
Just because you assign a shared object to a local reference, does not mean that object automatically
becomes thread safe.
The request and response objects are of course thread safe to use. A new instance of these are created
for every request into your servlet, and thus for every thread executing in your servlet.

12. Which of the following method is not used to retrieve request parameters?
A: getParameterNames()
B: getParameter()
C: getParameterVaIue()
D: None of the Above

13. How to package and deploy web application in j2ee?


A: jar
B: ear
C: war
D: rar

14. Depending upon the events on servlet we can specify the following levels_____________.
A: Request level events
B: ServletContext level events
C: Only A
D: Both A and B

15. An __________ object always represents a client's HTTP request


A: ClientRequest
B: HttpServlet
C: HttpServletRequest
D: javax.servlet..http.HttpSession

16. You want to use URL rewriting to support client browsers, which do not use cookies. Which method
will you use to attach the session id to a URL that is to be used for the sendRedirect() method of the
HttpServletResponse?
A: encodeURL
B: encodeRedirectURL
16
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
C: encodeSessionURL
D: encodeSessionRedirectURL

17. Given that the service() method of a typical servlet is multithreaded, which one of the following issues
does NOT need to be addressed in a servlet's implementation?
a. Concurrent access to shared resources
b. Concurrent access to local variables
c. Concurrent access to static variables
d. Concurrent access to instance variables

18. _______ is the object used for reading “init” or “config” parameters.
A) ServletContext b) ServletConfig c) RequestDispatcher

19. Request parameters are set


a) in DD b) using setParameter c) implicitly

20. In case of redirect request is same. False

21. Following methods are the part of servlet lifecycle. [Choose 3 correct answers]
A) Start b) init c) stop d) service e) destroy

22. In case of servlet, for each request


a) each thread is created b) each process is created c) none of them

23. Container adds cookies inside


a) Response b) request c) context d) config

24. ___web.xml_________ file is called as Deployment Descriptor.

23. One of the following is not a servlet attribute


a) config b) context c) request d) session

24. If the request is get


a) service() calls “doPost()” method b) service() calls “doGet()”

c) container directly calls “doGet()” d) doGet() calls “service()”

25. One of the followings is must for a servlet class a)


it must override “service()” method b) it must have parameterized constructor c) it must have
public no-arg constructor d) it must implement Serializable interface.

26. Redirect can go beyond the context . True

27. HttpSession session =request.getSession()


a) Can create a new session only b) can retrieve an existing session only
c) Can either create a new or retrieve an existing session , depends upon session availability.

28. Following interface is used to either forward or include other web resource. A)
Servlet b) RequestDispatcher c) ServletConfig d) HttpResponse
17
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
29. Besides the cookie object which other object is also required to create a cookie on the browser?
a. Request
b. Response
c. Session
d. Application

30. The limitations of Cookies are


a. 20 cookies per site each of max 4Kb
b. 4 cookies per site each of max 20Kb
c. Any no of cookies per site each of max 4Kb
d. No limitation

31. Select correct statement


A: forward is faster than redirect
B: redirect has always a same request.
C: if client does not accept cookies , session mechanism is not possible at all.
D: cookies can store java objects.

32. Your web application named bank uses “WelcomeServlet”. Where will u store
“WelcomeServlet.class”?
a. bank/WEB-INF/classes
b. bank/WEB-INF/lib/classes
c. root/WEB-INF/lib
d. bank/WebContent/lib/classes

33. What method can be used to retrieve value of the request parameter being sent as a part of the
request by client?
a. Use the method “HttpServletRequest.getParameter(string name) which will return String form.
b. Use the method “HttpServletRequest.getParameterValues() which will return array of String
values.
c. Use the method “HttpServletResponse.getValues()” which will return array of string values.
d. There is no direct support in servlet api.

34. Which of these true about deployment descriptor?


a. The order of elements in deployment descriptor is important. The elements must follow a specific
order.
b. The servlet-mapping element if present must be defined within “servlet” element.
c. The elements of deployment descriptor are not case insensitive.
d. The web-app element must include the servlet element.

35. If the HTTP error 500 is generated by your servlet, you do not want to show the “Internal Server Error”
page to the client. Instead, you want a custom error page to be displayed. What is the best way to
accomplish this?
a. Forward the user to the error page using HttpServletResponse.sendRedirect() method.
b. Forward the user to the error page using RequestDispatcher.forward() method.
c. Specify the mapping of the error-code 500 and the error-page in the deployment descriptor.
d. It is not possible to accomplish this.
18
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
36. Which of the following should not be used to share data between servlets in a distributed web
application?
a. Attributes of ServletContext
b. Enterprise JavaBeans
c. Attributes of HttpSession
d. Database

37. You want to use URL Rewriting to support client browsers which do not use cookies. Which method
will you use to attach the session id to a url that is to be used for the “sendRedirect()” method of the
HttpServletResponse?
a) encodeURL b) encodeRedirectURL c) encodeSessionURL d) encodeSessionRedirectURL

38. What is the main difference between servlet and cgi?


a. Servlets are thread based , cgi are process based
b. Servlets execute slower compare to cgi
c. Servlets have no platform specific API, whereas cgi has
d. All of the above

39. A user types the URL http://www.cdac.in which Http request gets generated?
a. GET method
b. POST method
c. HEAD method
d. PUT method

40. Which object is used to forward the request processing from one servlet to another?
a. ServletContext
b. ServletConfig
c. RequestDispatcher
d. ResponseDispatcher

41. The method getWriter() returns an object of type PrintWriter. This class has println() method to
generate output. Which of these classes define the getWriter method? Select the one correct answer.
a. HttpServletRequest
b. HttpServletResponse
c. ServletContext
d. ServletConfig

42. Which of the following statements is correct?


a. The response from the dedicated server to a HEAD request consists of status line, content type
and the document.
b. The response from the server to a GET request does not contain a document.
c. The setStatus method defined in the HttpServletRequest class takes int as an argument and sets
the status of Http response.
d. The HttpServletResponse defines constants like SC_NOT_FOUND that may be used as a parameter
to setStatus method.

43. Which of the following method is not used to reterive request parameters
A: getParameterNames()
19
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
B: getParameter()
C: getParameterVaIue()
D: None of the Above

44. Redirect cannot go beyond context. False

45. Lifecycle methods of filters are [ select 3 correct answers ]


a) init b) service c) destroy d) doFilter e) intercept

46. If the request method is “get”, which method is called


A. DoGet
B. DoPut
C. DoPost
D. DoDelete

47. Select the correct statement.


A. Servlet is multithreaded
B. HttpServlet extends GenericServlet
C. CGI creates different process for each request
D. all of the above

48. In order to make Servlet entry inside DD, we need to mention _______.
A. Servlet-Class
B. Servlet-name
C. URL-pattern
D. All of these

49. Request and response are created for each thread


A. False B. True

50. One of the following is one per servlet


A. Request
B. Config
C. Context
D. All of these

51. Life cycle method in case of servlet is


A. Destroy
B. Service
C. Init
D. all of these

52. Service method is declared as throws


A. ServletException
B. IOException
C. both a and b
D. none of these
20
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
53. DD is _______.
A. Config.xml
B. None of these
C. Webconfig.xml
D. Web.xml

54. getWriter() method is invoked on ______ .


A. Request
B. Config
C. Response
D. context

55. HttpServlet class is abstract class


A. False B. True

56. Request Dispatcher reference can be used for forward as well as include
A. False B. True

57. One of the following is invoked for every request


A. Constructor
B. Service
C. Destroy
D. Init

58. Which one is one per context?


A. ServletContext
B. ServletConfig
C. Both
D. None

59. ServletConfig is available inside constructor


A. False B. True

60. Redirect can go outside container ________ .


A. False B. True

61. init() calls init(ServletConfig)


A. False B. True

62. Which one is one per servlet______.


A. ServletContext
B. ServletConfig
C. Both
D. None

63. sendRedirect() method is invoked on ________ .


A. HttpServletResponse
B. ServletContext
21
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
C. ServletConfig
D. HttpServletRequest
64. Forward cannot go outside context ________.
A. False B. True

65. addCookie() method belongs to ______.


A. config
B. context
C. request
D. response

66. getCookies() method belongs to ________.


A. A.ContexT
B. request
C. response
D. config

67. Forward is slow as compare to redirect


A. False B. True

68. Init method has argument:


A. InitConfig
B. ServletConfig
C. ServletContext
D. None of these

69. In order to read config parameters which method is used _______.


A. getParameter
B. getInitParameter
C. getServletParameter
D. getConfigParameter

70. If u want to ensure servlet loading even before first request u need to use
A. <start-on-load>
B. <load-on-startup>
C. <load-on-start>
D. none of these

71. HttpServletRequest and HttpServletResponse are thread-safe


A. False B. True

72. HttpSession gets migrated to another JVM if required


A. True B. False

73. Cookies can store java objects


A. True B. False

74. In order to get existing session only we need to use _______.


22
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
A. getSession()
B. getSession(true)
C. getExistingSession()
D. getSession(false)

75. What is the difference between doing an include or a forward with a RequestDispatcher?
A. The forward method transfers control to the designated resource, while the include method invokes the
designated resource, substitutes its output dynamically in the display, and returns control to the calling
page.
B. The two methods provide the same functionality, but with different levels of persistence
C. The forward method is deprecated as of JSP 1.1 and the include method should be used in order to
substitute portions of a dynamic display at runtime.
D. The include method transfers control to a dynamic resource, while the forward method allows for
dynamic substitution of another JPS pages output, returning control to the calling resource.

STRUTS
1. Following is the main controller in struts2 framework
A: StutsPrepreAndExcuteFilter
B: ActionServlet
C: FilterServlet
D: FilterController

2. One of the following is not a result type


A: dispatcher
B: chain
C: response
D: redirect

3. Action objects are stored in


A: value stack B: heap C: file D: none of these

4. In action tag, when method is not specified, which method is by default considered?
A: run
B: actionexecute
C: execute
D: perform

5. One of the following is the map in OGNL to retrieve any type of attribute
A: request
B: application
C: page
D: attr

6. Which is the interface used if you want to access “request” object in your action class?
A: ServletRequest
B: HttpServletRequest
C: ServletRequestAware
23
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
D: RequestAware

7. Action methods must return


A: String
B: int
C: boolean
D: it can return any type

8. One of the following is a result type


A: dispatcher
B: error
C: response
D: request

9. struts uses _____ for multiple language support


a) resource b) resource bundle c) language bundle d) all of the above

10. EL maps
pageScope Scoped variables from page scope

requestScope Scoped variables from request scope

sessionScope Scoped variables from session scope

applicationScope Scoped variables from application scope

param Request parameters as strings

paramValues Request parameters as collections of strings

header HTTP request headers as strings

headerValues HTTP request headers as collections of strings

initParam Context-initialization parameters

cookie Cookie values

pageContext The JSP PageContext object for the current page

11. Controller component in struts 2 is


A: filter B: servlet C: jsp D: None of the above.

12. To read value from the value stack we need to use


A: SQL B: PU/SQL C: OGNL D: None of the above.

13. Interceptor does __________&________processing of request and invokes the action classes.
A: pre, post B: before, after C: get, post D: None of the above

24
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
14.Which interceptor is used for internationalization in struts?
A: struts.custom.i17n.resources
B: struts.custom.i18n
C: struts.custom.i18n.resources
D: struts.i18n.custom.resources

15. Default Interceptors of struts 2 are


A: ConversionError, ModelDriven, jsonValidationparams
B: ModelDriven, jsonvalidation, ParameterDriven
C: ConversionError, ParameterDriven, roleDriven
D: ConversionError, roleDriven, jsonValidation, params

16. Struts2 application flow is defined in a configuration file called ____________


a) web.xml b) struts.xml c) struts-config.xml

17. The controller in struts2 is ____________


a) ActionServlet b) HttpServlet c) FilterDispatcher

18. OGNL stands for __Object Graph Navigation Language________________

19. _____________ is the interceptor stack available by default to every sturts application.
A) execAndWait b) validateStack c) defaultStack
20. By default result name is _____________
a) success b) fail c) retry d) abort

21. In action tag, when method is not specified ___________ is the by default method considered.
A) run b) execute c) actionExecute d) perform

22. We can forward the request from one action class to another. True

23. Tiles definitions are mentioned inside ________________ file.


A) Struts.xml b) tiles.xml c) web.xml d) tiles-def.xml

24. Interceptors are similar to ____________ in concept.


A) Filters b) servlets c) jsps d) pojos

25. Action method has to return


a) String b) int c) Boolean d) it can return any type

26. Which method is necessary for Action class?


a) Valuator () b) reset() c) findForward() d) execute()

27. What is the return type of validate() method in struts?


a) String b) void c) int d) Object

28. Can I add user defined data in valueStack in struts?


a. Depends
b. Yes always
25
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
c. Not possible
d. None of the above

29. __________ is the interface used if you want to access “request” object in your action class.
A) ServletRequest b) HttpServletRequest c) ServletRequestAware d) RequestAware

30. If the action name is “AddAction”, the validation file name should be ______________
a) AddAction-validation.xml
b) AddAction-validator.xml
c) AddAction_validation.xml

SPRING
1. Spring controller can be defined using annotation
a) @Bean
b) @Component
c) @Controller
d) none of the above

2. Mapping of request in Spring MVC can be defined using annotation


a) @RequestMapping
b) @Action
c) @RequestProcessing
d) @Request

3. The advice functionality takes place after the advised method completes, regardless of the outcome:
a) after-returning
b) After
c) after-throwing
d) None of the above

4. In Spring framework by default the scope of bean is


A. Prototype
B. Request
C. Session
D. Singleton

5. Which class is used to check spring lifecycle?


a. BeanFactory
b. ClassPathApplicationContext
c. AbstractApplicationContext
d. All of the above

6. Front Controller in Spring MVC is


a) DispatcherServlet
b) ActionServlet
c) FacesServlet
d) none of the above

26
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
7. Join points can be method calls, constructor invocations, exception handlers, or other points in the
execution of a program.
a) true
b) false

8. When a lazy-initialized bean is a dependency of a singleton bean that is not lazy-initialized, the
ApplicationContext creates the lazy-initialized bean at startup
a) True
b) False

9. Spring DAO framework converts checked exception into unchecked exception. The name of unchecked
exception is________
a) RuntimeException
b) SQLException
c) DataAccessException
d) none of the above

10. The class which encapsulates traditional jdbc code is


a) DataTemplate
b) JdbcTemplate
c) SqlTemplate
d) none of the above
11. One of the following helps controller in resolving a particular view component.
a) ModelAndView
b) HandlerMapping
c) ViewResolver
d) DispatcherServlet

12. What are the types of Dependency Injection Spring supports?


a) Setter injection
b) Constructor injection
c) Both a and b
d) none of the above

13. The process of applying aspects to a target object to create a new proxy object is called as_____
a) Coupling
b) Weaving
c) Injecting
d) None of the above

14. Annotation to force dependency injection is____


a) @Injection
b) @Autowired
c) @Wired
d) None of the above

15. In order to use @Component annotation for a bean u need to add following tag in Spring bean
configuration file.
a) <context:component-scan>
27
Shriram Mantri Vidyanidhi Info Tech Academy
PG DAC JAVA Technoligies-2 Question Bank
b) <auto:component-scan>
c) <context:bean-scan>
d) None of the above

16. What is the Key strategy of spring framework?


A: Application development in POJO style.
B: Loose coupling through Dl.
C: Declarative programming using AOP
D: All of the above.
SWING
1. Select correct statement from the following
A: Invisible components are required in BoxLayout
B: flowlayout is the default layout for JApplet
C: the default lookandfeel for swing components is MotifLookAndFeel.
D: swing does not have DelegationEvent model.

2. How will you create Dual Application in Swing?


A: extend JFrame, inside main instantiate JApplet
B: extend JApplet, inside main instantiate JFame
C: extend JFrame as well as JApplet
D: none of these

28

You might also like