Web-Based Java Programming Question Bank - Sept 21
Web-Based Java Programming Question Bank - Sept 21
Web-Based Java Programming Question Bank - 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.
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
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
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
A: SessionFactory.get(); B: (session)SessionFactory.getObject();
C: SessionFactory.getSession(); D: SessionFactory.openSession();
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.
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
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();
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
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()
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
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
JSP
1. Which of the attribute of JSP mentioned below is not available in servlet?
A: request B: session C: page D: context
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”)%>
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
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().
24. The attribute which informs container about a particular error jsp page is
A: isExceptionPage B: exceptionPage C: isErrorPage D: errorPage
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”
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" %>
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.
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
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
55. One of the following cannot be overridden while writing JSP page
A: jspService B: JspDestroy C: jspInit D: _jspService
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
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
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
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
12. Which of the following method is not used to retrieve request parameters?
A: getParameterNames() B:
getParameter()
C: getParameterVaIue()
D: None of the Above
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
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
21. Following methods are the part of servlet lifecycle. [Choose 3 correct answers] A: Start B:
init C: stop D: service E: destroy
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
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.
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
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
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
45. Lifecycle methods of filters are [ select 3 correct answers ] A: init B: service C:
destroy D: doFilter E: intercept
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
53. DD is _______.
A: Config.xml B: None of these C: Webconfig.xml D: Web.xml
56. Request Dispatcher reference can be used for forward as well as include
A: False B: True
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
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
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
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
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
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
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
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
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
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
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
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.
24