0% found this document useful (0 votes)
26 views15 pages

Question Bank

Uploaded by

ddemo5805
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)
26 views15 pages

Question Bank

Uploaded by

ddemo5805
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/ 15

Unit- 5

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

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.
o ResultSet: The ResultSet represents a set of rows retrieved due to query
execution.

2) Select the packages in which JDBC classes are defined?

a. jdbc and javax.jdbc


b. rdb and javax.rdb
c. jdbc and java.jdbc.sql
d. sql and javax.sql

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.

4) 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.
7. Close the resultset and statement objects.
8. Close the connection.

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

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

Explanation: The following table defines transaction isolation levels.

Transaction Isolation Level Description

TRANSACTION_READ_UNCOMMITTE Dirty reads, non-repeatable reads,


D and phantom reads can occur.

TRANSACTION_READ_COMMITTED Dirty reads are prevented; non-


repeatable reads and phantom
reads can occur.

TRANSACTION_REPEATABLE_READ Dirty reads and non-repeatable


reads are prevented; phantom
reads can occur.

TRANSACTION_SERIALIZABLE Dirty reads, non-repeatable reads,


and phantom reads are prevented.

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

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

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.

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

a. getConnection()
b. registerDriver()
c. forName()
d. Both b and c

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.

9) 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.

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

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

Answer: c

Explanation:

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.

Unit-6

11. How constructor can be used for a servlet?

A. Initialization and Constructor function


B. Constructor function
C. Setup() method
D. Initialization

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.

12. Which package is used for importing swing components?


A. javax.swing
B. java.swing
C. java.awt.
D. All of the mentioned

13. Which of the following is/are steps for the servlet life cycle?

A. Servlet class is loaded


B. Servlet instance is created
C. init,Service,destroy method is invoked
D. All of the mentioned
Answer : D
Explanation: All of the above are steps for servlet life cycle.

14. A servlet is a Java program that is invoked via HTTP on the


webserver.

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.

15. Which of the following code is used to get an attribute in a HTTP


Session object in servlets?

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?

A. When the servlet throws the exception, it will automatically be caught by


the calling JSP page
B. This capability is not supported
C. 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”
D. The servlet needs to redirect the response to the specific error page, saving
the exception off in a cookie

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.

18. __________ is used to read data from a client request.

A. ServletResponse
B. ServletRequest
C. Servlet
D. ServletConfig

Answer : B
Explanation: ServletRequest is used to read data from a client request.

19. Which of the following ways to create a servlet?

A. Using Servlet Interface


B. Using GenericServlet class
C. Using HttpServlet class
D. All of given
Answer : D
Explanation: Different ways to create a servlet are: using Servlet Interface,
using GenericServlet class, using HttpServlet class.
20. Which component is used to compile, debug and execute the java
program?

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.

03. Which of the following is not a core interface of Hibernate?

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.

04. Hibernate SessionFactory represent which level of cache?

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.

05. While creating SessionFactory in hibernate, which design pattern


should be adopted?

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.

06. What is ORM?

A. ORM is the automated persistence of objects in a Java application to the


tables in a relational database
B. ORM stands for object-relational mapping
C. Both A & B
D. None of the mentioned
07. What does the Session object hold?
A. Second Level Cache
B. First Level Cache
C. Both A & B
D. None of the mentioned
Answer : B
Explanation: The Session object holds first level cache. So answer 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.

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
Explanation: None.

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.

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
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

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.

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.

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.

4. How many bits are in a single IP address?


a) 8
b) 16
c) 32
d) 64

Answer: c
Explanation: None.

5. Which of these is a full form of DNS?


a) Data Network Service
b) Data Name Service
c) Domain Network Service
d) Domain Name Service

Answer: d
Explanation: None.

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


a) DatagramPacket
b) URL
c) InetAddress
d) ContentHandler

Answer: c
Explanation: InetAddress class encapsulate both IP address and DNS, we can interact with
this class by using name of an IP host.

7. What will be the output of the following Java program?

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

8. What will be the output of the following Java program?

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

9. What will be the output of the following Java program?

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

10. What will be the output of the following Java program?

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

You might also like