0% found this document useful (0 votes)
32 views6 pages

MCQ S On 5th Unit ST-3

The document is a Java Surprise Test consisting of multiple-choice questions covering topics such as servlets, JDBC, and JSP. It includes questions about servlet lifecycle methods, JDBC driver types, session tracking techniques, and the use of PreparedStatement. The test assesses knowledge on Java web technologies and their functionalities.

Uploaded by

B NAGALAKSHMI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views6 pages

MCQ S On 5th Unit ST-3

The document is a Java Surprise Test consisting of multiple-choice questions covering topics such as servlets, JDBC, and JSP. It includes questions about servlet lifecycle methods, JDBC driver types, session tracking techniques, and the use of PreparedStatement. The test assesses knowledge on Java web technologies and their functionalities.

Uploaded by

B NAGALAKSHMI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

JAVA Surprise Test-3 Date: -6-25

-----------------------------------------------------------------------------------------------------

Roll NO: Section: Branch:


1. What is the primary function of a servlet?
o a) To create dynamic web pages
o b) To handle client requests and responses
o c) To manage database connections
o d) To define the structure of a web page
2. Which method is called only once during the servlet lifecycle?
o a) service()
o b) doGet()
o c) init()
o d) destroy()
3. Which of the following is NOT a session tracking technique in servlets?
o a) Cookies
o b) URL rewriting
o c) Hidden form fields
o d) Server-side scripting
4. What does JSP stand for?
o a) Java Server Protocol
o b) Java System Pages
o c) Java Server Pages
o d) Java Standard Protocol
5. Which implicit object in JSP allows access to the servlet configuration?
o a) request
o b) response
o c) session
o d) config
6. What is the purpose of the <jsp:useBean> tag in JSP?
o a) To include another JSP page
o b) To declare a Java bean and make it available in the JSP
o c) To execute Java code
o d) To forward the request to another resource
7. Which Java package contains the JDBC classes?
o a) java.net
o b) java.io
o c) java.sql
o d) java.util
8. Which interface represents a connection to a database in JDBC?
o a) Statement
o b) ResultSet
o c) Connection
o d) DriverManager
9. What is the purpose of PreparedStatement in JDBC?
o a) To execute static SQL queries
o b) To execute stored procedures
o c) To execute parameterized SQL queries efficiently
o d) To retrieve data from a database
10. Which method is used to retrieve a session object in a servlet?
o a) getSession()
o b) createSession()
o c) accessSession()
JAVA Surprise Test-3 Date: -6-25
-----------------------------------------------------------------------------------------------------

o d) fetchSession()
11. The Java __________ specification defines an application programming interface for
communication between the Web server and the application program.
a) Servlet
b) Server
c) Program
d) Randomize
12. The doGet() method in the example extracts values of the parameter’s type and
number by using __________
a) request.getParameter()
b) request.setParameter()
c) responce.getParameter()
d) responce.getAttribute()
13. How many JDBC driver types does Sun define?
a) One
b) Two
c) Three
d) Four
14. Which JDBC driver Type(s) can be used in either applet or servlet code?
a) Both Type 1 and Type 2
b) Both Type 1 and Type 3
c) Both Type 3 and Type 4
d) Type 4 only
15. What MySQL property is used to create a surrogate key in MySQL?
a) UNIQUE
b) SEQUENCE
c) AUTO_INCREMENT
d) None of the mentioned
16. A JSP is transformed into a(n):
a) Java applet
b) Java servlet
c) Either 1 or 2 above
d) Neither 1 nor 2 above
17. Which JDBC driver Type(s) is(are) the JDBC-ODBC bridge?
a) Type 1
b) Type 2
c) Type 3
d) Type 4
18. What programming language(s) or scripting language(s) does Java Server Pages (JSP)
support?
a) VBScript only
b) Jscript only
c) Java only
d) All of the mentioned
19. What is bytecode?
a) Machine-specific code
b) Java code
c) Machine-independent code
d) None of the mentioned
Where is metadata stored in MySQL?
a) In the MySQL database metadata
b) In the MySQL database metasql
JAVA Surprise Test-3 Date: -6-25
-----------------------------------------------------------------------------------------------------

c) In the MySQL database mysql d) None of the mentioned

Roll NO: Section: Branch:

1. Which of the following contains both date and time?


a) java.io.date
b) java.sql.date
c) java.util.date
d) java.util.dateTime

Answer: d
Explanation: java.util.date contains both date and time. Whereas, java.sql.date contains only
date.
2. Which of the following is advantage of using JDBC connection pool?
a) Slow performance
b) Using more memory
c) Using less memory
d) Better performance

Answer: d
Explanation: Since the JDBC connection takes time to establish. Creating connection at the
application start-up and reusing at the time of requirement, helps performance of the
application.
3. Which of the following is advantage of using PreparedStatement in Java?
a) Slow performance
b) Encourages SQL injection
c) Prevents SQL injection
d) More memory usage

Answer: c
Explanation: PreparedStatement in Java improves performance and also prevents from SQL
injection.
advertisement
4. Which one of the following contains date information?
a) java.sql.TimeStamp
b) java.sql.Time
c) java.io.Time
d) java.io.TimeStamp

Answer: a
Explanation: java.sql.Time contains only time. Whereas, java.sql.TimeStamp contains both
time and date.
5. What does setAutoCommit(false) do?
a) commits transaction after each query
b) explicitly commits transaction
c) does not commit transaction automatically after each query
d) never commits transaction

6. Which of the following is used to call stored procedure?


a) Statement
b) PreparedStatement
c) CallableStatment
JAVA Surprise Test-3 Date: -6-25
-----------------------------------------------------------------------------------------------------

d) CalledStatement

Answer: c
Explanation: CallableStatement is used in JDBC to call stored procedure from Java program.
7. Which of the following is used to limit the number of rows returned?
a) setMaxRows(int i)
b) setMinRows(int i)
c) getMaxrows(int i)
d) getMinRows(int i)

Answer: a
Explanation: setMaxRows(int i) method is used to limit the number of rows that the database
returns from the query.
8. Which of the following is method of JDBC batch process?
a) setBatch()
b) deleteBatch()
c) removeBatch()
d) addBatch()

Answer: d
Explanation: addBatch() is a method of JDBC batch process. It is faster in processing than
executing one statement at a time.
9. Which of the following is used to rollback a JDBC transaction?
a) rollback()
b) rollforward()
c) deleteTransaction()
d) RemoveTransaction()

Answer: a
Explanation: rollback() method is used to rollback the transaction. It will rollback all the
changes made by the transaction.
10. Which of the following is not a JDBC connection isolation levels?
a) TRANSACTION_NONE
b) TRANSACTION_READ_COMMITTED
c) TRANSACTION_REPEATABLE_READ
d) TRANSACTION_NONREPEATABLE_READ

Answer: d
Explanation: TRANSACTION_NONREPEATABLE_READ is not a JDBC connection
isolation level.
1. How constructor can be used for a servlet?
a) Initialization
b) Constructor function
c) Initialization and Constructor function
d) Setup() method

Answer: c
Explanation: We cannot declare constructors for interface in Java. This means we cannot
enforce this requirement to any class which implements Servlet interface.
Also, Servlet requires ServletConfig object for initialization which is created by container.
2. Can servlet class declare constructor with ServletConfig object as an argument?
a) True
JAVA Surprise Test-3 Date: -6-25
-----------------------------------------------------------------------------------------------------

b) False

Answer: b
Explanation: ServletConfig object is created after the constructor is called and before init() is
called. So, servlet init parameters cannot be accessed in the constructor.
3. What is the difference between servlets and applets?
i. Servlets execute on Server; Applets execute on browser
ii. Servlets have no GUI; Applet has GUI
iii. Servlets creates static web pages; Applets creates dynamic web pages
iv. Servlets can handle only a single request; Applet can handle multiple requests
a) i, ii, iii are correct
b) i, ii are correct
c) i, iii are correct
d) i, ii, iii, iv are correct

Answer: b
Explanation: Servlets execute on Server and doesn’t have GUI. Applets execute on browser
and has GUI.
advertisement
4. Which of the following code is used to get an attribute in a HTTP Session object in
servlets?
a) session.getAttribute(String name)
b) session.alterAttribute(String name)
c) session.updateAttribute(String name)
d) session.setAttribute(String name)

Answer: a
Explanation: session has various methods for use.
5. Which method is used to get three-letter abbreviation for locale’s country in servlets?
a) Request.getISO3Country()
b) Locale.getISO3Country()
c) Response.getISO3Country()
d) Local.retrieveISO3Country()

Answer: a
Explanation: Each country is usually denoted by a 3 digit code.ISO3 is the 3 digit country
code.
Free 30-Day Java Certification Bootcamp is Live. Join Now!
6. Which of the following code retrieves the body of the request as binary data?
a) DataInputStream data = new InputStream()
b) DataInputStream data = response.getInputStream()
c) DataInputStream data = request.getInputStream()
d) DataInputStream data = request.fetchInputStream()

Answer: c
Explanation: InputStream is an abstract class. getInputStream() retrieves the request in binary
data.
7. When destroy() method of a filter is called?
a) The destroy() method is called only once at the end of the life cycle of a filter
b) The destroy() method is called after the filter has executed doFilter method
c) The destroy() method is called only once at the begining of the life cycle of a filter
JAVA Surprise Test-3 Date: -6-25
-----------------------------------------------------------------------------------------------------

d) The destroyer() method is called after the filter has executed

Answer: a
Explanation: destroy() is an end of life cycle method so it is called at the end of life cycle.
8. Which of the following is true about servlets?
a) Servlets execute within the address space of web server
b) Servlets are platform-independent because they are written in java
c) Servlets can use the full functionality of the Java class libraries
d) Servlets execute within the address space of web server, platform independent and uses the
functionality of java class libraries

Answer: d
Explanation: Servlets execute within the address space of a web server. Since it is written in
java it is platform independent. The full functionality is available through libraries.
9. How is the dynamic interception of requests and responses to transform the information
done?
a) servlet container
b) servlet config
c) servlet context
d) servlet filter

Answer: d
Explanation: Servlet has various components like container, config, context, filter. Servlet
filter provides the dynamic interception of requests and responses to transform the
information.
10. Which are the session tracking techniques?
i. URL rewriting
ii. Using session object
iii.Using response object
iv. Using hidden fields
v. Using cookies
vi. Using servlet object
a) i, ii, iii, vi
b) i, ii, iv, v
c) i, vi, iii, v
d) i, ii, iii, v

Answer: b
Explanation: URL rewriting, using session object, using cookies, using hidden fields are
session tracking techniques.

You might also like