Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Web-Based Java Programming Question Bank - Sept 21

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

USM’s Shriram Mantri Vidyanidhi Info Tech Academy

Web-based Java Programming eDAC Sept 21

Contents
HIBERNATE ............................................................................................................................................................ 1
JDBC ...................................................................................................................................................................... 4
JSF ......................................................................................................................................................................... 6
JSP ......................................................................................................................................................................... 6
MVC .................................................................................................................................................................... 11
SERVLET .............................................................................................................................................................. 12
STRUTS ................................................................................................................................................................ 18
SPRING ................................................................................................................................................................ 20
SWING ................................................................................................................................................................. 22

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

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

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


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

4. Session interface does


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

5. One of the following persist element index


A: <bag> B: <list> C: <set> D: <map>

6. Which statement is wrong?


A: HQL is case insensitive for class names and properties
B: SQL operates on relations, HQL operates on objects.

1
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
C: HQL is ultimately generated into underlying SQL.
D: HQL supports polymorphic queries.
7. 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

8. Which class is used to create EntityManagerFactory ?


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

9. One of the following is ORM implementation

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

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


A: dead B: detached C: managed D: persistent

11. What is the root tag element in the hibernate configuration file?
A: <hibernate-cfg> B: <hibernate-conf>
C: <hibemate-configuration> D: <hibemate>

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

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


A: <hibernate-mapping> B: <session-mapping> C:
<sessionfactory-mapping> D: None of the above

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.

2
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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

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?

3
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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

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 B: Type II C: 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
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21

4. Which character is used to represent an input parameter in a PreparedStatement?


A: % B: * C: ? D: #

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: xecuteDynamicQuery()

15. in the following code sample


Class.forName("Oracle.jdbc.OracleDriver");
5
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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);
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 B: JDBC-ODBC bridge
C: 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 B: CallableStatement
C: Statement D: PreparedStatement

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


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

23. Type1 driver makes use of


A: None of these B: Odbc C: 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 B: Statement C: ResultSet D: none of the above

27. Every driver class has ________ which registers itself with the DriverManager
6
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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 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”)%>
7
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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.
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 B: context C: 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" %>
8
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
<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

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 cannot 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
lifecycle 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");
9
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
%>
</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

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: =

10
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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.
B: 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.
C: 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?
A: A JSP page B: JavaBean C: servlet. D: 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
11
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
A: context B: config C: session D: pageContext

46. One of the following is an additional attribute in Jsp as compare to servlet attributes .
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 B: HttpJspBase
C: 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.
A: model B: view C: controller D: none of them

2. In MVC architecture model is _____________


A: jsp B: javabean C: servlet

12
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21

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

9. Technique for maintaining anonymous user transaction on web


A: cookies B: URL Rewriting C: session D: all of the above

13
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
10. One of the following is not a servlet attribute

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

11. what is recommended for servlet Thread safety


A: Your servlet service() method should not access any member variables, unless these member
variables are thread safe themselves.
B: 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.
C: Rule 1 and 2 also counts for static variables.
D: 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

14
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
B: encodeRedirectURL
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. 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.

15
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
28. Following interface is used to either forward or include other web resource. A:
Servlet B: RequestDispatcher C: ServletConfig D: HttpResponse

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.

16
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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.

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

17
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
A: getParameterNames() 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

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


18
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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 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: .., m,A.ContexT B: request C: response D: config

67. Forward is slow as compare to redirect


A: False C: 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

19
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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 _______.


A: getSession(true) B: getExistingSession() C: 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 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

20
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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

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________________

21
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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 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

22
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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

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> B: <auto:component-scan>

23
USM’s Shriram Mantri Vidyanidhi Info Tech Academy
Web-based Java Programming eDAC Sept 21
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

24

You might also like