0% found this document useful (0 votes)
54 views33 pages

AJP Practice Mcqs

The document contains multiple choice questions about servlets in Java. It tests knowledge of key servlet concepts like what interface a servlet class must implement, which HTTP methods servlets support, the purpose of initialization parameters and lifecycle methods, and how servlets communicate with clients and other resources. The questions are accompanied by explanations of the correct answers.

Uploaded by

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

AJP Practice Mcqs

The document contains multiple choice questions about servlets in Java. It tests knowledge of key servlet concepts like what interface a servlet class must implement, which HTTP methods servlets support, the purpose of initialization parameters and lifecycle methods, and how servlets communicate with clients and other resources. The questions are accompanied by explanations of the correct answers.

Uploaded by

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

Advanced java-MCQS

What is a servlet in Java?

a) A programming language

b) A scripting language

c) A server-side technology for Java web applications

d) A database management system

Which interface must a Java class implement to create a servlet?

a) Servlet

b) HttpServlet

c) ServletConfig

d) ServletRequest

Which HTTP method is used to retrieve data from a server using a servlet?

a) GET

b) POST

c) PUT

d) DELETE

Which of the following is true about servlet containers?

a) They are used to compile servlets into bytecode

b) They are responsible for managing the lifecycle of servlets

c) They are part of the Java Development Kit (JDK)


Advanced java-MCQS

d) They are used for storing servlet-related data

Which method in the HttpServlet class is used to handle HTTP GET requests?

a) doGet()

b) doPost()

c) service()

d) init()

Which object provides information about the client's request to a servlet?

a) ServletConfig

b) HttpServletRequest

c) HttpServletResponse

d) ServletContext

What is the purpose of the web.xml file in a servlet-based web application?

a) To define the HTML structure of web pages

b) To configure the servlet container and servlet mappings

c) To store client-side JavaScript code

d) To define the database schema

Which of the following is true about servlet threading?

a) Each servlet instance runs in a separate thread

b) All servlet instances run in the same thread

c) Servlets do not support multithreading


Advanced java-MCQS

d) Servlets always run in parallel threads

How can a servlet send data back to the client?

a) By calling the forward() method

b) By using the println() method of the PrintWriter class

c) By invoking the getRequestDispatcher() method

d) By setting response headers

Which of the following is NOT a valid method to initialize a servlet?

a) Using the init() method

b) Using the @WebServlet annotation

c) Using the web.xml deployment descriptor

d) Using the doGet() method

Which object is used to obtain initialization parameters in a servlet?

a) ServletConfig

b) HttpServletRequest

c) HttpServletResponse

d) ServletContext

What is the purpose of the doPost() method in a servlet?

a) To handle HTTP POST requests

b) To initialize the servlet

c) To handle HTTP GET requests


Advanced java-MCQS

d) To forward the request to another resource

Which method is used to include the content of another resource during

servlet processing?

a) include()

b) import()

c) use()

d) forward()

Which servlet API method is called before a servlet instance is destroyed?

a) init()

b) destroy()

c) service()

d) doGet()

What is the purpose of the ServletContext object?

a) To hold client session information

b) To process client requests

c) To manage the lifecycle of servlet instances

d) To provide a shared context for servlets within a web application

What is the purpose of the RequestDispatcher interface in a servlet?

a) To handle HTTP request headers

b) To retrieve client cookies

c) To forward or include requests to other resources


Advanced java-MCQS

d) To manage servlet configuration settings

Which of the following is NOT a valid method of session tracking in servlets?

a) Cookies

b) URL rewriting

c) Hidden form fields

d) Query parameters

What is the purpose of the ServletResponse object in a servlet?

a) To handle client requests

b) To obtain initialization parameters

c) To store session data

d) To send data back to the client

Which Java package provides the classes and interfaces for servlets?

a) java.net

b) java.io

c) javax.servlet

d) java.lang

Answers and Explanations


Question 1

Answer:

c) A server-side technology for Java web applications.

Explanation:
Advanced java-MCQS

A servlet is a Java class that extends the functionality of a web server and handles
client requests and generates dynamic responses.

Question 2

Answer:

a) Servlet.

Explanation:

To create a servlet, a Java class must implement the Servlet interface. However, it is
more common to extend the HttpServlet class, which provides additional
functionality for handling HTTP requests.

Question 3

Answer:

a) GET.

Explanation:

The GET method is used to retrieve data from a server using a servlet. It is commonly
used for fetching data or rendering web pages.

Question 4

Answer:

b) They are responsible for managing the lifecycle of servlets.

Explanation:

Servlet containers, also known as servlet engines or web containers, are responsible
for managing the lifecycle of servlets, handling requests, and providing various
services to servlets.

Question 5

Answer:

a) doGet().

Explanation:
Advanced java-MCQS

The doGet() method in the HttpServlet class is used to handle HTTP GET requests. It
is where you can write the code to process and respond to GET requests.

Question 6

Answer:

b) HttpServletRequest.

Explanation:

The HttpServletRequest object provides information about the client's request to a


servlet, including parameters, headers, cookies, and more.

Question 7

Answer:

b) To configure the servlet container and servlet mappings.

Explanation:

The web.xml file is an XML-based configuration file used to configure the servlet
container and define servlet mappings, initialization parameters, security constraints,
and more in a servlet-based web application.

Question 8

Answer:

a) Each servlet instance runs in a separate thread.

Explanation:

Servlets are multithreaded, meaning that each request to a servlet typically runs in a
separate thread. This allows concurrent handling of multiple client requests.

Question 9

Answer:

b) By using the println() method of the PrintWriter class.

Explanation:
Advanced java-MCQS

A servlet can send data back to the client by writing the response content using
the PrintWriter object obtained from the HttpServletResponse object and
its println() method.

Question 10

Answer:

d) Using the doGet() method.

Explanation:

The doGet() method is used to handle HTTP GET requests, not for initializing a
servlet. Servlet initialization can be done using the init() method, @WebServlet
annotation, or web.xml deployment descriptor.

Question 11

Answer:

a) ServletConfig.

Explanation:

The ServletConfig object provides access to the initialization parameters configured


for a servlet. These parameters are specified in the web.xml file or through
annotations.

Question 12

Answer:

a) To handle HTTP POST requests.

Explanation:

The doPost() method is used to handle HTTP POST requests. It is where you can
write the code to process and respond to POST requests.

Question 13

Answer:

a) include().
Advanced java-MCQS

Explanation:

The include() method is used to include the content of another resource, such as
another servlet or JSP page, during servlet processing. It allows the content of the
included resource to be merged with the current servlet response.

Question 14

Answer:

b) destroy().

Explanation:

The destroy() method is called before a servlet instance is destroyed. It allows for
performing cleanup tasks and releasing any resources held by the servlet.

Question 15

Answer:

d) To provide a shared context for servlets within a web application.

Explanation:

The ServletContext object represents the servlet context, which provides a shared
context for servlets within a web application. It allows servlets to share data and
communicate with each other.

Question 16

Answer:

c) To forward or include requests to other resources.

Explanation:

The RequestDispatcher interface is used to forward or include requests to other


resources, such as servlets, JSP pages, or static files.

Question 17

Answer:

d) Query parameters.
Advanced java-MCQS

Explanation:

Query parameters are not a valid method of session tracking in servlets. Session
tracking is typically achieved through mechanisms such as cookies, URL rewriting, or
hidden form fields.

Question 18

Answer:

d) To send data back to the client.

Explanation:

The ServletResponse object represents the response that a servlet sends back to the
client. It provides methods to set response headers, write content for the response,
and manage cookies.

JDBC
1) What are the major components of the JDBC?

a. DriverManager, Driver, Connection, Statement, and ResultSet


b. DriverManager, Driver, Connection, and Statement
c. DriverManager, Statement, and ResultSet
d. DriverManager, Connection, Statement, and ResultSet

Hide Answer Workspace

Answer: a

Explanation:

o DriverManager: Manages a list of database drivers.


o Driver: The database communications link, handling all communication with
the database.
o Connection: Interface with all methods for contacting a database.
o Statement: Encapsulates an SQL statement which is passed to the database to
be parsed, compiled, planned, and executed.
Advanced java-MCQS

o ResultSet: The ResultSet represents a set of rows retrieved due to query


execution.

What is the correct sequence to create a database connection?

i. Import JDBC packages.

ii. Open a connection to the database.

iii. Load and register the JDBC driver.

iv. Execute the statement object and return a query resultset.

v. Create a statement object to perform a query.

vi. Close the resultset and statement objects.

vii. Process the resultset.

viii. Close the connection.

a. i, ii, iii, v, iv, vii, viii, vi


b. i, iii, ii, v, iv, vii, vi, viii
c. ii, i, iii, iv, viii, vii, v, vi
d. i, iii, ii, iv, v, vi, vii, viii

Answer: b

Explanation: To create a database connection in Java, we must follow the sequence


given below:

1. Import JDBC packages.


2. Load and register the JDBC driver.
3. Open a connection to the database.
4. Create a statement object to perform a query.
5. Execute the statement object and return a query resultset.
6. Process the resultset.
Advanced java-MCQS

7. Close the resultset and statement objects.


8. Close the connection.

Which of the following method is used to perform DML statements in JDBC?

a. executeResult()
b. executeQuery()
c. executeUpdate()
d. execute()

Hide Answer Workspace

Answer: c

Explanation: We use the executeUpdate() method for DML SQL queries that change
data in the database, such as INSERT, UPDATE, and DELETE which do not return a
resultset.

Which of the following method is static and synchronized in JDBC API?

a. getConnection()
b. prepareCall()
c. executeUpdate()
d. executeQuery()

Hide Answer Workspace

Answer: A

Explanation: A Java application using the JDBC API establishes a connection to a


database by obtaining a Connection object. The standard way to obtain a Connection
object is to call the method DriverManager.getConnection() method that accepts a
String contains the database connection URL. It is a static and synchronized method.

Which methods are required to load a database driver in JDBC?

a. getConnection()
b. registerDriver()
c. forName()
d. Both b and c
Advanced java-MCQS

Hide Answer Workspace

Answer: d

Explanation: There are two ways to load a database driver in JDBC:

o By using the registerDriver() Method: To access the database through a Java


application, we must register the installed driver in our program. We can do this
with the registerDriver() method that belongs to the DriverManager class. The
registerDriver() method takes as input a driver class, that is, a class that
implements the java.sql.Driver interface, as is the case with OracleDriver.
o By using the Class.forName() Method: Alternatively, we can also use the
forName() method of the java.lang.Class to load the JDBC drivers directly.
However, this method is valid only for JDK-compliant Java virtual machines. It is
invalid for Microsoft JVMs.

Parameterized queries can be executed by?

a. ParameterizedStatement
b. PreparedStatement
c. CallableStatement and Parameterized Statement
d. All kinds of Statements

Answer: b

Explanation: The PreparedStatement interface extends the Statement interface. It


represents a precompiled SQL statement that can be executed multiple times. It
accepts parameterized SQL quires. We can pass 0 or more parameters to this query.

Which of the following is not a valid statement in JDBC?

a. Statement
b. PreparedStatement
c. QueryStatement
d. CallableStatement

Answer: c

Explanation:
Advanced java-MCQS

o Statement: Use this for general-purpose access to your database. It is useful


when we are using static SQL statements at runtime. The Statement interface
cannot accept parameters.
o PreparedStatement: It represents the pre-compiled SQL statements that can
be executed multiple times.
o CallableStatement: It is used to execute SQL stored procedures.
o QueryStatement: It is not supported by JDBC.

JDBC-ODBC driver is also known as?

a. Type 4
b. Type 3
c. Type 1
d. Type 2

Answer: c

Explanation: Type 1 driver is also known as the JDBC-ODBC bridge driver. It is a


database driver implementation that employs the ODBC driver to connect to the
database. The driver converts JDBC method calls into ODBC function calls.

Which of the following is not a type of ResultSet object?

a. TYPE_FORWARD_ONLY
b. CONCUR_WRITE_ONLY
c. TYPE_SCROLL_INSENSITIVE
d. TYPE_SCROLL_SENSITIVE

Answer: b

Explanation: There are three types of ResultSet object:

o TYPE_FORWARD_ONLY: This is the default type and the cursor can only move
forward in the result set.
o TYPE_SCROLL_INSENSITIVE: The cursor can move forward and backward, and
the result set is not sensitive to changes made by others to the database after
the result set was created.
Advanced java-MCQS

o TYPE_SCROLL_SENSITIVE: The cursor can move forward and backward, and


the result set is sensitive to changes made by others to the database after the
result set was created.

Based on the concurrency there are two types of ResultSet object.

o CONCUR_READ_ONLY: The ResultSet is read-only, this is the default


concurrency type.
o CONCUR_UPDATABLE: We can use the ResultSet update method to update
the rows data.

o Which data type is used to store files in the database table?

a. BLOB
b. CLOB
c. File
d. Both a and b

Answer: b

Explanation: To store a large volume of data such as text file into a table, we use CLOB
(Character Large OBject) data type of SQL.

DatabaseMetaData interface is used to get?

a. Comprehensive information about the database as a whole.


b. Comprehensive information about the table as a whole.
c. Comprehensive information about the column as a whole.
d. Both b and c

Answer: a

Explanation: DatabaseMetaData is an interface that is used to get Comprehensive


information about the database as a whole. It is implemented by driver vendors to let
users know the capabilities of a DBMS in combination with the JDBC driver that is used
with it.

Which of the following driver converts the JDBC calls into database-specific calls?
Advanced java-MCQS

a. JDBC-ODBC Bridge Driver (Type 1)


b. Native API-partly Java Driver (Type 2)
c. Net Protocol-pure Java Driver (Type 3)
d. Native Protocol-pure Java Driver (Type 4)

Answer: b

Explanation: Type 2 driver converts JDBC calls into database-specific calls with the
help of vendor database library. It directly communicates with the database server.

Are ResultSets updateable?

a. Yes, but only if we call the method openCursor() on the ResultSet and if the
driver and database support this option.
b. Yes, but only if we indicate a concurrency strategy when executing the
statement, and if the driver and database support this option.
c. Yes, but only if the ResultSet is an object of class UpdateableResultSet and if
the driver and database support this option.
d. No, ResultSets are never updateable. We must explicitly execute a DML
statement to change the data in the underlying database.

Answer: b

Explanation: By default, a ResultSet object is not updatable and its cursor moves only
in the forward direction. If we want to create an updateable ResultSet object, either we
can use ResultSet.TYPE_SCROLL_INSENSITIVE or the
ResultSet.TYPE_SCROLL_SENSITIVE type, which moves the cursor forward and
backward relative to the current position.

How many statement objects can be created using a Connection?

a. 2
b. 1
c. 3
d. Multiple

Answer: d
Advanced java-MCQS

Explanation: Multiple statements can be created and used on the same connection,
but only one resultset at once can be created and used on the same statement

Networking MCQS
1. Which class creates a TCP server socket, bound to the specified port?
(a) Socket
(b) InetAddress
(c) ServerSocket
(d) DatagramSocket
Answer:
Option (c)
2. Which class implements a connectionless packet delivery service.
(a) ServerSocket
(b) DatagramSocket
(c) InetAddress
(d) DatagramPacket
Answer:
Option (d)
3. Which method of URL class returns the object of URLConnection class?
(a) getLocalHost()
(b) openConnection()
(c) getByName(String host)
(d) getHostAddress()
Answer:
Option (b)
4. A Socket Consists Of?
(a) Port+IP address
(b) Only IP address
(c) only Port address
(d) None of these
Answer:
Option (a)
5. Which method is establish a connection between server and client?
(a) accept()
(b) open()
(c) getLocalHost()
(d) openConnection()
Advanced java-MCQS

Answer:
Option (a)
6. Which constructor of DatagramSocket is used to creates a datagram socket and binds it with the
(a) DatagramSocket()
(b) DatagramSocket(int port, InetAddress address)
(c) DatagramSocket(int port)
(d) None of the above
Answer:
Option (b)
7. Which classes are used for connection-less socket programming?
(a) DatagramSocket
(b) DatagramPacket
(c) Both A & B
(d) None of the above
Answer:
Option (c)
8. How do you implement reliable transmission in UDP protocol?
(a) by sequencing packages
(b) by using Middleware
(c) A & B both
(d) None of the above
Answer:
Option (a)
9. Which Protocol is generally used for multicast? TCP or UDP?
(a) TCP
(b) UDP
(c) A & B both
(d) None of these
Answer:
Option (b)
10. How to get list of IP address that are assigned to a network interface?
(a) getInetAddresses()
(b) getInterfaceAddresses()
(c) A & B both
(d) None of these
Answer:
Option (c)
11. Which is not true for socket.
(a) Socket connection means the two machines have information about each other’s network location
(b) Socket supports only TCP protocol due to its reliability feature.
Advanced java-MCQS

(c) To connect to other machine we need a socket connection.


(d) Socket programming is used for communication between the applications running on different JRE
Answer:
Option (b)
12. If one want to implement Socket at client side then which is the correct way to implement it?
(a) ServerSocket ss=new ServerSocket(port);
(b) Socket s=ss.accept();
(c) Socket s=new Socket("localhost",port);
(d) Socket s=ss.accept(port);
Answer:
Option (c)
13. URL contains…?
(a) Protocol
(b) IP Address
(c) Port Number
(d) All of these
Answer:
Option (d)
14. InetAddress has a cache to store successful and unsuccessful host name resolutions.
(a) True
(b) False
Answer:
Option (a)
15. Datagram is basically an information but there is no guarantee of its
(a) content
(b) arrival & arrival time
(c) A & B both
(d) None of these
Answer:
Option (c)
16. DatagramSocket() throws
(a) IOException
(b) UnknownHostException
(c) ClassNotFoundException
(d) SocketException
Answer:
Option (d)
7. UnknownHostException is immediate child class of_______?
(a) java.lang.Exception
(b) java.lang.IOException
(c) java.lang.Throwable
Advanced java-MCQS

(d) java.lang.Object
Answer:
Option (b)
18. Port numbers range from _____ to ______.
(a) 0 to 65535
(b) 1 to 65536
(c) -65535 to 65536
(d) 0 to 1024
Answer:
Option (a)
19. _________ Protocol is more efficient in terms of both latency and bandwidth.
(a) TCP
(b) UDP
(c) SMTP
(d) FTP
Answer:
Option (b)
20. Which of the following is NOT true about User Datagram Protocol in transport layer?
(a) Works well in unidirectional communication, suitable for broadcast information.
(b) It does three way handshake before sending datagrams.
(c) It provides datagrams, suitable for modeling other protocols such as in IP tunneling or Remote Pro
(d) The lack of retransmission delays makes it suitable for real-time applications.
Answer:
Option (b)
21. The transport layer protocols used for real time multimedia, file transfer, DNS and email, respectively are:
(a) TCP, UDP, UDP and TCP
(b) UDP, TCP, TCP and UDP
(c) UDP, TCP, UDP and TCP
(d) TCP, UDP, TCP and UDP
Answer:
Option (c)

1) URL is an acronym for?

a. Uniform Resource Locator


b. Unified Resource Locator
c. Uniform Restore Locator
d. Unified Restore Locator

ANSWER: Uniform Resource Locator


Advanced java-MCQS

4) Which constructor of DatagramSocket class is used to creates a datagram socket


and binds it with the given Port Number?

a. DatagramSocket(int port)
b. DatagramSocket(int port, InetAddress address)
c. DatagramSocket()
d. None of the above

ANSWER: DatagramSocket(int port, InetAddress address)

5) Which methods are commonly used in ServerSocket class?

a. public OutputStream getOutputStream()


b. public Socket accept()
c. public synchronized void close()
d. None of the above

ANSWER: public Socket accept()

6) Which classes are used for connection-less socket programming?

a. DatagramSocket
b. DatagramPacket
c. Both A & B
d. None of the above

ANSWER: Both A & B

10) The DatagramSocket and DatagramPacket classes are not used for connection-
less socket programming.

a. True
b. False

ANSWER: False
Advanced java-MCQS

13) The URLConnection class can be used to read and write data to the specified resource
referred by the URL

a. True
b. False

ANSWER: True
Explanation:

14) Datagram is basically an information but there is no guarantee of its content, arrival or
arrival time.

a. True
b. False

ANSWER: True
17) TCP,FTP,Telnet,SMTP,POP etc. are examples of ?

a. Socket
b. IP Address
c. Protocol
d. MAC Address

ANSWER: Protocol

8) Which steps occur when establishing a TCP connection between two


computers using sockets?

a. The server instantiates a ServerSocket object, denoting which port number


communication is to occur on
b. The server invokes the accept() method of the ServerSocket class. This method
waits until a client connects to the server on the given port
c. After the server is waiting, a client instantiates a Socket object, specifying the
server name and port number to connect to
d. All of the above

ANSWER: All of the above


Advanced java-MCQS

19) In InetAddress class which method returns the host name of the IP
Address?

a. public String getHostName()


b. public String getHostAddress()
c. public static InetAddress getLocalHost()
d. None of the above

ANSWER: public String getHostName()


Chapter: JAVA Networking
1. Which of these package contains classes and interfaces for networking?
A. java.io

B. java.util

C. java.net

D. javax.swing

Answer» C. java.net

2. In the following URL, identify the protocol identifier?


https://mcqmate.com:8080/course.php
A. http

B. gtu.ac.in

C. //mcqmate.com:80/course.php

D. 8080

Answer» A. http

3. Which of the following protocol follows connection less service?


A. TCP

B. TCP/IP

C. UDP

D. HTTP

Answer» C. UDP
Advanced java-MCQS

4. Which of the following statement is NOT true?


A. TCP is a reliable but slow.

B. UDP is not reliable but fast.

File Transfer Protocol (FTP) is a standard Internet protocol for transmitting files between computers on
C.
the Internet over TCP/IP connections.

D. In HTTP, all communication between two computers are encrypted

Answer» D. In HTTP, all communication between two computers are encrypted

5. Which of the following statement is TRUE?


With stream sockets there is no need to establish any connection and data flows between the processes
A.
are as continuous streams.

B. Stream sockets are said to provide a connection-less service and UDP protocol is used

C. Datagram sockets are said to provide a connection-oriented service and TCP protocol is used

With datagram sockets there is no need to establish any connection and data flows between the
D.
processes are as packets.

Answer» D. With datagram sockets there is no need to establish any connection and data flows between the
processes are as packets.

6. Which of the following method call is valid to obtain the server's hostname by invoking an
applet?
A. getCodeBase().host()

B. getCodeBase().getHost()

C. getCodeBase().hostName()

D. getCodeBase().getHostName()

Answer» B. getCodeBase().getHost()

7. The server listens for a connection request from a client using which of the following
statement?
A. Socket s = new Socket(ServerName, port);
Advanced java-MCQS

7. The server listens for a connection request from a client using which of the following
statement?
B. Socket s = serverSocket.accept()

C. Socket s = serverSocket.getSocket()

D. Socket s = new Socket(ServerName);

Answer» B. Socket s = serverSocket.accept()

8. The client requests a connection to a server using which of the following statement?
A. Socket s = new Socket(ServerName, port);

B. Socket s = serverSocket.accept();

C. Socket s = serverSocket.getSocket();

D. Socket s = new Socket(ServerName);

Answer» A. Socket s = new Socket(ServerName, port);

9. To connect to a server running on the same machine with the client, which of the
following cannotbe used for the hostname?
A. “localhost”

B. "127.0.0.1"

C. InetAddress.getLocalHost(),

D. "127.0.0.0"

Answer» D. "127.0.0.0"

10. In the socket programming, for an IP address, which can be used to find the host name
and IP address of a client/ server?
A. The ServerSocket class

B. The Socket class

C. The InetAddress class

D. The Connection interface

Answer» C. The InetAddress class


Advanced java-MCQS

11. To create an InputStream on a socket, say s, which of the following statement is


necessary?
A. InputStream in = new InputStream(s);

B. InputStream in = s.getInputStream();

C. InputStream in = s.obtainInputStream();

D. InputStream in = s.getStream();

Answer» B. InputStream in = s.getInputStream();

12. Which of the following protocols is/are for splitting and sending packets to an address
across a network?
A. TCP/IP

B. FTP

C. SMTP

D. UDP

Answer» A. TCP/IP

13. Which of these is a protocol for breaking and sending packets to an address across a
network?
A. TCP/IP

B. DNS

C. Socket

D. Proxy Server

Answer» A. TCP/IP

14. Which of these class is used to encapsulate IP address and DNS?


A. DatagramPacket

B. URL

C. InetAddress

D. ContentHandler
Advanced java-MCQS

14. Which of these class is used to encapsulate IP address and DNS?


Answer» C. InetAddress

15. Which of the following type of JDBC driver, is also called Type 2 JDBC driver?
A. JDBC-ODBC Bridge plus ODBC driver

B. Native-API, partly Java driver

C. JDBC-Net, pure Java driver

D. Native-protocol, pure Java driver

Answer» B. Native-API, partly Java driver

16. Which of the following type of JDBC driver, is also called Type 1 JDBC driver?
A. JDBC-ODBC Bridge plus ODBC driver

B. Native-API, partly Java driver

C. JDBC-Net, pure Java driver

D. Native-protocol, pure Java driver

Answer» A. JDBC-ODBC Bridge plus ODBC driver

17. Which of the following holds data retrieved from a database after you execute an SQL
query using Statement objects?
A. ResultSet

B. JDBC driver

C. Connection

D. Statement

Answer» A. ResultSet

18. Which of the following is not a valid type of ResultSet?


A. ResultSet.TYPE_FORWARD_ONLY

B. ResultSet.TYPE_SCROLL_INSENSITIVE
Advanced java-MCQS

18. Which of the following is not a valid type of ResultSet?


C. ResultSet.TYPE_SCROLL_SENSITIVE

D. ResultSet.TYPE_BACKWARD_ONLY

Answer» D. ResultSet.TYPE_BACKWARD_ONLY

19. Which of the following type of JDBC driver, uses database native protocol?
A. JDBC-ODBC Bridge plus ODBC driver

B. Native-API, partly Java driver

C. JDBC-Net, pure Java driver

D. Native-protocol, pure Java driver

Answer» D. Native-protocol, pure Java driver

20. What is JDBC?


A. JDBC is a java based protocol.

JDBC is a standard Java API for database-independent connectivity between the Java programming
B.
language and a wide range of databases.

C. JDBC is a specification to tell how to connect to a database.

D. Joint Driver for Basic Connection

Answer» B. JDBC is a standard Java API for database-independent connectivity between the Java programming
language and a wide range of databases.
Advanced java-MCQS

21. Which of the following manages a list of database drivers in JDB


A. DriverManager

B. JDBC driver

C. Connection

D. Statement

Answer» A. DriverManager

discuss
22. Which of the following type of JDBC driver should be used if your Java application is
accessing multiple types of databases at the same time?
A. Type 1

B. Type 2

C. Type 3

D. Type 4

Answer» C. Type 3

discuss
23. Which of the following is correct about JDBC?
A. JDBC architecture decouples an abstraction from its implementation.

B. JDBC follows a bridge design pattern.

C. Both of the above.

D. None of the above.

Answer» C. Both of the above.

discuss
24. Which of the following step establishes a connection with a database?
A. Import packages containing the JDBC classes needed for database programming.

B. Register the JDBC driver, so that you can open a communications channel with the database.

C. Open a connection using the DriverManager.getConnection () method.

D. Execute a query using an object of type Statement.

Answer» C. Open a connection using the DriverManager.getConnection () method.


Advanced java-MCQS

discuss
25. Which of the following is true about JDBC?
A. The JDBC API is an API to access different relational databases.

You use it to access relational databases without embedding a dependency on a specific database type in
B.
your code.

C. JDBC stands for Java DataBase Connectivity.

D. All of the above.

Answer» D. All of the above.

Java MCQ – Event Handling


1. Which of these packages contains all the classes and methods required for even
handling in Java?
a) java.applet
b) java.awt
c) java.event
d) java.awt.event

Answer: d
Explanation: Most of the event to which an applet response is generated by a user.
Hence they are in Abstract Window Kit package, java.awt.event.
2. What is an event in delegation event model used by Java programming language?
a) An event is an object that describes a state change in a source
b) An event is an object that describes a state change in processing
c) An event is an object that describes any change by the user and system
d) An event is a class used for defining object, to create events

Answer: a
Explanation: An event is an object that describes a state change in a source

3. Which of these methods are used to register a keyboard event listener?


a) KeyListener()
b) addKistener()
c) addKeyListener()
d) eventKeyboardListener()

Answer: c
4. Which of these methods are used to register a mouse motion listener?
a) addMouse()
b) addMouseListener()
c) addMouseMotionListner()
d) eventMouseMotionListener()

Answer: c
Explanation: None.
Advanced java-MCQS

5. What is a listener in context to event handling?


a) A listener is a variable that is notified when an event occurs
b) A listener is a object that is notified when an event occurs
c) A listener is a method that is notified when an event occurs
d) None of the mentioned

Answer: b
Explanation: A listener is a object that is notified when an event occurs. It has two major
requirements first, it must have been registered with one or more sources to receive
notification about specific event types, and secondly it must implement methods to
receive and process these notifications.

6. Event class is defined in which of these libraries?


a) java.io
b) java.lang
c) java.net
d) java.util

Answer: d

7. Which of these methods can be used to determine the type of event?


a) getID()
b) getSource()
c) getEvent()
d) getEventObject()

Answer: a
8. Which of these class is super class of all the events?
a) EventObject
b) EventClass
c) ActionEvent
d) ItemEvent

Answer: a
Explanation: EventObject class is a super class of all the events and is defined in
java.util package.

9. Which of these events will be notified if scroll bar is manipulated?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
Advanced java-MCQS

10. Which of these events will be generated if we close an applet’s window?


a) ActionEvent
b) ComponentEvent
c) AdjustmentEvent
d) WindowEvent

Answer: d
Explanation: WindowEvent is generated when a window is activated, closed,
deactivated, deiconfied, iconfied, opened or quit.

11. Which of these events is generated when a button is pressed?


a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent

Answer: a
Explanation: Action event is generated when a button is pressed, a list item is double-
clicked or a menu item is selected.

12. Which of these methods can be used to obtain the command name for invoking
ActionEvent object?
a) getCommand()
b) getActionCommand()
c) getActionEvent()
d) getActionEventCommand()

Answer: b

13. Which of these methods can be used to know which key is pressed?
a) getKey()
b) getModifier()
c) getActionKey()
d) getActionEvent()

Answer: b
Explanation: The getModifiers() methods returns a value that indicates which modifiers
keys (ALT, CTRL, META, SHIFT) were pressed when the event was generated.
14. Which of these events is generated by scroll bar?
a) ActionEvent
b) KeyEvent
c) WindowEvent
d) AdjustmentEvent

Answer: d
Advanced java-MCQS

15. Which of these methods can be used to determine the type of adjustment event?
a) getType()
b) getEventType()
c) getAdjustmentType()
d) getEventObjectType()

Answer: c

Which method in the HttpServlet class is used to handle HTTP GET requests?

a) doGet()

b) doPost()

c) service()

d) init()

You might also like