Question Bank
Question Bank
Answer: a
Explanation:
Answer: d
Explanation: JDBC API is divided into two packages i.e. java.sql and javax.sql. We have
to import these packages to use classes and interfaces in our application.
3) Thin driver is also known as?
a. Type 3 Driver
b. Type-2 Driver
c. Type-4 Driver
d. Type-1 Driver
Answer: c
Explanation: The JDBC thin driver is a pure Java driver. It is also known as Type-4 Driver.
It is platform-independent so it does not require any additional Oracle software on the
client-side. It communicates with the server using SQL *Net to access Oracle Database.
Answer: b
Explanation: To create a database connection in Java, we must follow the sequence
given below:
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.
6) How many transaction isolation levels provide the JDBC through the Connection
interface?
a. 3
b. 4
c. 7
d. 2
Answer: b
a. getConnection()
b. prepareCall()
c. executeUpdate()
d. executeQuery()
Answer: A
a. getConnection()
b. registerDriver()
c. forName()
d. Both b and c
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:
Unit-6
Answer : A
Explanation: Correct answer is the Initialization and Constructor function as
we cannot declare constructors for interface in Java. This means we cannot
enforce this requirement to any class which implements the Servlet interface
and also, Servlet requires ServletConfig object for initialization which is
created by the container.
13. Which of the following is/are steps for the servlet life cycle?
A. True
B. False
Answer : A
Explanation: Yes it is correct that a servlet is a Java program that is invoked
via HTTP on the webserver.
A. session.alterAttribute(String name)
B. session.updateAttribute(String name)
C. session.getAttribute(String name)
D. session.setAttribute(String name)
Answer : C
Explanation: session.getAttribute(String name) is used to get an attribute in a
HTTP Session object in servlets.
16. How can a servlet call a JSP error page?
Answer : C
Explanation: 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” and so option C is correct.
A. ServletResponse
B. ServletRequest
C. Servlet
D. ServletConfig
Answer : B
Explanation: ServletRequest is used to read data from a client request.
A. JIT
B. JDK
C. JVM
D. JRE
Answer : B
Explanation: JDK is a core component of Java Environment and provides all
the tools, executables, and binaries required to compile, debug and execute a
Java Program so option B is correct.
A. Configuration
B. Criteria
C. SessionManagement
D. Session
Answer : C
Explanation: SessionManagement is not a core interface of Hibernate but
Configuration, Criteria, SessionFactory, Session, Query and Transaction are
the core interfaces of Hibernate. So option C is correct.
A. Second Level
B. Third Level
C. First Level
D. Fourth Level
Answer : A
Explanation: Hibernate SessionFactory represent Second level of cache. So
option A is correct.
A. Prototype
B. Singleton
Answer : B
Explanation: SessionFactory is built at the time of application startup and it
follows the singleton design pattern. So option B is correct.
Unit -3
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.
Answer: c
Explanation: None.
Answer: c
Explanation: None.
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
Explanation: getID() can be used to determine the type of an event.
8. Which of these class is super class of all the events?
a) EventObject
b) EventClass
c) ActionEvent
d) ItemEvent
Answer: c
Explanation: AdjustmentEvent is generated when a scroll bar is manipulated.
Answer: d
Explanation: WindowEvent is generated when a window is activated, closed, deactivated,
deiconfied, iconfied, opened or quit.
Unit-4
1. Which of these package contains classes and interfaces for networking?
a) java.io
b) java.util
c) java.net
d) java.network
Answer: c
Explanation: None.
2. 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
Explanation: TCP/IP – Transfer control protocol/Internet Protocol is used to break data into
small packets an send them to an address across a network.
3. How many ports of TCP/IP are reserved for specific protocols?
a) 10
b) 1024
c) 2048
d) 512
Answer: b
Explanation: None.
Answer: c
Explanation: None.
Answer: d
Explanation: None.
Answer: c
Explanation: InetAddress class encapsulate both IP address and DNS, we can interact with
this class by using name of an IP host.
1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
UnknownHostException
5. {
6. InetAddress obj1 =
InetAddress.getByName("sanfoundry.com");
7. InetAddress obj2 =
InetAddress.getByName("sanfoundry.com");
8. boolean x = obj1.equals(obj2);
9. System.out.print(x);
10. }
11. }
a) 0
b) 1
c) true
d) false
Answer: c
Explanation: None.
Output:
$ javac networking.java
$ java networking
true
1. import java.net.*;
2. public class networking
3. {
4. public static void main(String[] args) throws
UnknownHostException
5. {
6. InetAddress obj1 = InetAddress.getByName("cisco.com");
7. InetAddress obj2 =
InetAddress.getByName("sanfoundry.com");
8. boolean x = obj1.equals(obj2);
9. System.out.print(x);
10. }
11. }
a) 0
b) 1
c) true
d) false
Answer: d
Explanation: InetAddress obj1 = InetAddress.getByName(“cisco.com”); creates object obj1
having DNS and IP address of cisco.com, InetAddress obj2 =
InetAddress.getByName(“sanfoundry.com”); creates obj2 having DNS and IP address of
sanfoundry.com, since both these address point to two different locations false is returned
by obj1.equals(obj2);.
Output:
$ javac networking.java
$ java networking
false
1.import java.io.*;
2.import java.net.*;
3.public class URLDemo
4.{
5. public static void main(String[] args)
6. {
7. try
8. {
9. URL url=new URL("https://www.sanfoundry.com/java-mcq");
10. System.out.println("Protocol:
"+url.getProtocol());
11. System.out.println("Host Name: "+url.getHost());
12. System.out.println("Port Number: "+url.getPort());
13. } catch(Exception e){System.out.println(e);}
14. }
15. }
a) Protocol: http
b) Host Name: www.sanfoundry.com
c) Port Number: -1
d) All of the mentioned
1. import java.net.*;
2. class networking
3. {
4. public static void main(String[] args) throws
UnknownHostException
5. {
6. InetAddress obj1 = InetAddress.getByName("cisco.com");
7. System.out.print(obj1.getHostName());
8. }
9. }
a) cisco
b) cisco.com
c) www.cisco.com
d) none of the mentioned
Answer: b
Explanation: None.
Output:
$ javac networking.java
$ java networking
cisco.com