AJP Practice Mcqs
AJP Practice Mcqs
a) A programming language
b) A scripting language
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 method in the HttpServlet class is used to handle HTTP GET requests?
a) doGet()
b) doPost()
c) service()
d) init()
a) ServletConfig
b) HttpServletRequest
c) HttpServletResponse
d) ServletContext
a) ServletConfig
b) HttpServletRequest
c) HttpServletResponse
d) ServletContext
servlet processing?
a) include()
b) import()
c) use()
d) forward()
a) init()
b) destroy()
c) service()
d) doGet()
a) Cookies
b) URL rewriting
d) Query parameters
Which Java package provides the classes and interfaces for servlets?
a) java.net
b) java.io
c) javax.servlet
d) java.lang
Answer:
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:
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:
Question 7
Answer:
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:
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:
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:
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:
Question 12
Answer:
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:
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:
Explanation:
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:
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?
Answer: a
Explanation:
Answer: b
a. executeResult()
b. executeQuery()
c. executeUpdate()
d. execute()
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.
a. getConnection()
b. prepareCall()
c. executeUpdate()
d. executeQuery()
Answer: A
a. getConnection()
b. registerDriver()
c. forName()
d. Both b and c
Advanced java-MCQS
Answer: d
a. ParameterizedStatement
b. PreparedStatement
c. CallableStatement and Parameterized Statement
d. All kinds of Statements
Answer: b
a. Statement
b. PreparedStatement
c. QueryStatement
d. CallableStatement
Answer: c
Explanation:
Advanced java-MCQS
a. Type 4
b. Type 3
c. Type 1
d. Type 2
Answer: c
a. TYPE_FORWARD_ONLY
b. CONCUR_WRITE_ONLY
c. TYPE_SCROLL_INSENSITIVE
d. TYPE_SCROLL_SENSITIVE
Answer: b
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
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.
Answer: a
Which of the following driver converts the JDBC calls into database-specific calls?
Advanced java-MCQS
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.
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.
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
(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)
a. DatagramSocket(int port)
b. DatagramSocket(int port, InetAddress address)
c. DatagramSocket()
d. None of the above
a. DatagramSocket
b. DatagramPacket
c. Both A & B
d. None of the above
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
19) In InetAddress class which method returns the host name of the IP
Address?
B. java.util
C. java.net
D. javax.swing
Answer» C. java.net
B. gtu.ac.in
C. //mcqmate.com:80/course.php
D. 8080
Answer» A. http
B. TCP/IP
C. UDP
D. HTTP
Answer» C. UDP
Advanced java-MCQS
File Transfer Protocol (FTP) is a standard Internet protocol for transmitting files between computers on
C.
the Internet over TCP/IP connections.
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()
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();
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. InputStream in = s.getInputStream();
C. InputStream in = s.obtainInputStream();
D. InputStream in = s.getStream();
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
B. URL
C. InetAddress
D. ContentHandler
Advanced java-MCQS
15. Which of the following type of JDBC driver, is also called Type 2 JDBC driver?
A. JDBC-ODBC Bridge plus ODBC driver
16. Which of the following type of JDBC driver, is also called Type 1 JDBC driver?
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
B. ResultSet.TYPE_SCROLL_INSENSITIVE
Advanced java-MCQS
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
JDBC is a standard Java API for database-independent connectivity between the Java programming
B.
language and a wide range of databases.
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
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.
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.
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.
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
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
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.
Answer: d
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.
Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
Advanced java-MCQS
Answer: d
Explanation: WindowEvent is generated when a window is activated, closed,
deactivated, deiconfied, iconfied, opened or quit.
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()