JDBC
Networking
Servlet and JSP
Multithreading
Java Beans and RMI
Which of the following contains both date and time?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: d
Explanation: [Link] contains both date and time. Whereas,
[Link] contains only date.
Which of the following is an 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.
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.
Which one of the following contains date information?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: a
Explanation: [Link] contains only time. Whereas,
[Link] contains both time and date.
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
Answer: c
Explanation: setAutoCommit(false) does not commit transaction
automatically after each query. That saves a lot of time of the execution and
hence improves performance.
Which of the following is used to call stored procedure?
a) Statement
b) PreparedStatement
c) CallableStatment
d) CalledStatement
Answer: c
Explanation: CallableStatement is used in JDBC to call stored procedure
from Java program.
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.
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.
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.
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.
Which of these package contains classes and interfaces for networking?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: c
Explanation: None.
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.
How many ports of TCP/IP are reserved for specific protocols?
a) 10
b) 1024
c) 2048
d) 512
Answer: b
Explanation: None.
How many bits are in a single IP address?
a) 8
b) 16
c) 32
d) 64
Answer: c
Explanation: None.
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.
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.
What will be the output of the following Java program?
1. import [Link].*;
2. class networking
3. {
4. public static void main(String[] args) throws UnknownHostException
5. {
6. InetAddress obj1 = [Link]("[Link]");
7. InetAddress obj2 = [Link]("[Link]");
8. boolean x = [Link](obj2);
9. [Link](x);
10. }
11. }
a) 0 b) 1 c) true d) false
Answer: c Explanation: None. Output: $ javac [Link]
$ java networking
true
What will be the output of the following Java program?
1. import [Link].*;
2. public class networking
3. {
4. public static void main(String[] args) throws UnknownHostException
5. {
6. InetAddress obj1 = [Link]("[Link]");
7. InetAddress obj2 = [Link]("[Link]");
8. boolean x = [Link](obj2);
9. [Link](x);
10. }
11. }
a) 0 b) 1 c) true d) false
Answer: d
Explanation: InetAddress obj1 = [Link](“[Link]”); creates object obj1 having DNS and IP address
of [Link], InetAddress obj2 = [Link](“[Link]”); creates obj2 having DNS and IP address
of [Link], since both these address point to two different locations false is returned by [Link](obj2);.
Output: $ javac [Link] $ java networking false
What will be the output of the following Java program?
1. import [Link].*;
2. import [Link].*;
3. public class URLDemo
4. {
5. public static void main(String[] args)
6. {
7. try
8. {
9. URL url=new URL("[Link]
10. [Link]("Protocol: "+[Link]());
11. [Link]("Host Name: "+[Link]());
12. [Link]("Port Number: "+[Link]());
13. } catch(Exception e){[Link](e);}
14. }
15. }
a) Protocol: http b) Host Name: [Link] c) Port Number: -1 d) All of the mentioned
Answer: d Explanation: getProtocol() give protocol which is http
getUrl() give name domain name
getPort() Since we have not explicitly set the port, default value that is -1 is printed.
What will be the output of the following Java program?
1. import [Link].*;
2. class networking
3. {
4. public static void main(String[] args) throws UnknownHostException
5. {
6. InetAddress obj1 = [Link]("[Link]");
7. [Link]([Link]());
8. }
9. }
a) cisco b) [Link] c) [Link] d) none of the mentioned
Answer: b
Explanation: None. Output: $ javac [Link]
$ java networking
[Link]
Which of these interface abstractes the output of messages from httpd?
a) LogMessage
b) LogResponse
c) Httpdserver
d) httpdResponse
Answer: a
Explanation: LogMessage is a simple interface that is used to abstract the
output of messages from the httpd.
Which of these class is used to create servers that listen for either local or
remote client programs?
a) httpServer
b) ServerSockets
c) MimeHeader
d) HttpResponse
Answer: b
Explanation: None.
Which of these is a standard for communicating multimedia content over
email?
a) http
b) https
c) Mime
d) httpd
Answer: c
Explanation: MIME is an internet standard for communicating multimedia
content over email. The HTTP protocol uses and extends the notion of
MIME headers to pass attribute pairs between HTTP client and server.
Which of these methods is used to make raw MIME formatted string?
a) parse()
b) toString()
c) getString()
d) parseString()
Answer: a. Explanation: None.
Which of these class is used for operating on request from the client to the
server?
a) http
b) httpDecoder
c) httpConnection
d) httpd
Answer: d. Explanation: None.
Which of these method of MimeHeader is used to return the string
equivalent of the values stores on MimeHeader?
a) string()
b) toString()
c) convertString()
d) getString()
Answer: b. Explanation: toString() does the reverse of parse()
method, it is used to return the string equivalent of the values stores on
MimeHeader.
Which of these is an instance variable of class httpd?
a) port
b) cache
c) log
d) All of the mentioned
Answer: d. Explanation: There are 5 instance variables: port, docRoot,
log, cache and stopFlag. All of them are private.
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.
Can servlet class declare constructor with ServletConfig object as an
argument?
a) True
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.
Which of the following code is used to get an attribute in a HTTP Session
object in servlets?
a) [Link](String name)
b) [Link](String name)
c) [Link](String name)
d) [Link](String name)
Answer: a. Explanation: session has various methods for use.
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.
Which of the following code retrieves the body of the request as binary
data?
a) DataInputStream data = new InputStream()
b) DataInputStream data = [Link]()
c) DataInputStream data = [Link]()
d) DataInputStream data = [Link]()
Answer: c. Explanation: InputStream is an abstract class.
getInputStream() retrieves the request in binary data.
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
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.
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.
Which page directive should be used in JSP to generate a PDF page?
a) contentType
b) generatePdf
c) typePDF
d) contentPDF
Answer: a. Explanation: <%page contentType=”application/pdf”> tag
is used in JSP to generate PDF.
Which tag should be used to pass information from JSP to included JSP?
a) Using <%jsp:page> tag
b) Using <%jsp:param> tag
c) Using <%jsp:import> tag
d) Using <%jsp:useBean> tag
Answer: a. Explanation: <%jsp:param> tag is used to pass information
from JSP to included JSP.
Application is instance of which class?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: d. Explanation: Application object is wrapper around the
ServletContext object and it is an instance of a [Link]
object.
_jspService() method of HttpJspPage class should not be overridden.
a) True
b) False
Answer: a
Explanation: _jspService() method is created by JSP container. Hence, it
should not be overridden.
Which option is true about session scope?
a) Objects are accessible only from the page in which they are created
b) Objects are accessible only from the pages which are in same session
c) Objects are accessible only from the pages which are processing the same
request
d) Objects are accessible only from the pages which reside in same application
Answer: b. Explanation: Object data is available till session is alive.
Default value of autoFlush attribute is?
a) true
b) false
Answer: a
Explanation: Default value “true” depicts automatic buffer flushing.
Which one is the correct order of phases in JSP life cycle?
a) Initialization, Cleanup, Compilation, Execution
b) Initialization, Compilation, Cleanup, Execution
c) Compilation, Initialization, Execution, Cleanup
d) Cleanup, Compilation, Initialization, Execution
Answer: c
Explanation: The correct order is Compilation, Initialization, Execution,
Cleanup.
“request” is instance of which one of the following classes?
a) Request
b) HttpRequest
c) HttpServletRequest
d) ServletRequest
Answer: c
Explanation: request is object of HttpServletRequest.
Which is not a directive?
a) include
b) page
c) export
d) useBean
Answer: c
Explanation: Export is not a directive.
Which is mandatory in <jsp:useBean /> tag?
a) id, class
b) id, type
c) type, property
d) type,id
Answer: a
Explanation: The useBean searches existing object and if not found creates
an object using class.
Which one of the following is correct for directive in JSP?
a) <%@directive%>
b) <%!directive%>
c) <%directive%>
d) <%=directive%>
Answer: a
Explanation: Directive is declared as <%@directive%>.
Which of the following action variable is used to include a file in JSP?
a) jsp:setProperty
b) jsp:getProperty
c) jsp:include
d) jsp:plugin
Answer: c. Explanation: jsp:include action variable is used to include a
file in JSP.
Which attribute uniquely identification element?
a) ID
b) Class
c) Name
d) Scope
Answer: a
Explanation: ID attribute is used to uniquely identify action element.
“out” is implicit object of which class?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: d. Explanation: JspWriter object is referenced by the implicit
variable out which is initialized automatically using methods in the
PageContext object.
Which object stores references to the request and response objects?
a) sessionContext
b) pageContext
c) HttpSession
d) sessionAttribute
Answer: b. Explanation: pageContext object contains information
about directives issued to JSP page.
What temporarily redirects response to the browser?
a) <jsp:forward>
b) <%@directive%>
c) [Link](URL)
d) [Link](URL)
Answer: c
Explanation: [Link](URL) directs response to the browser
and creates a new request.
Which tag is used to set a value of a JavaBean?
a) <c:set>
b) <c:param>
c) <c:choose>
d) <c:forward>
Answer: a
Explanation: <c:set> is used to set a value of a [Link] object.
Can <!–comment–> and <%–comment–%> be used alternatively in JSP?
a) True
b) False
Answer: b
Explanation: <!–comment–> is an HTML comment. <%–comment–%> is
JSP comment.
Java code is embedded under which tag in JSP?
a) Declaration
b) Scriptlet
c) Expression
d) Comment
Answer: b
Explanation: Scriptlet is used to embed java code in JSP.
Which of the following is not a directive in JSP?
a) page directive
b) include directive
c) taglib directive
d) command directive
Answer: d
Explanation: command directive is not a directive in JSP.
What is multithreaded programming?
a) It’s a process in which two different processes run simultaneously
b) It’s a process in which two or more parts of same process run simultaneously
c) It’s a process in which many different process are able to access same
information
d) It’s a process in which a single process can access information from many
sources
Answer: b. Explanation: Multithreaded programming a process in which two or
more parts of the same process run simultaneously.
Which of these are types of multitasking?
a) Process based
b) Thread based
c) Process and Thread based
d) None of the mentioned
Answer: c
Explanation: There are two types of multitasking: Process based
multitasking and Thread based multitasking.
Thread priority in Java is?
a) Integer
b) Float
c) double
d) long
Answer: a Explanation: Java assigns to each thread a priority that
determines hoe that thread should be treated with respect to others. Thread
priority is integers that specify relative priority of one thread to another.
What will happen if two thread of the same priority are called to be processed
simultaneously?
a) Anyone will be executed first lexographically
b) Both of them will be executed simultaneously
c) None of them will be executed
d) It is dependent on the operating system
Answer: d. Explanation: In cases where two or more thread with same priority
are competing for CPU cycles, different operating system handle this situation
differently. Some execute them in time sliced manner some depending on the
thread they call.
Which of these statements is incorrect?
a) By multithreading CPU idle time is minimized, and we can take maximum use
of it
b) By multitasking CPU idle time is minimized, and we can take maximum use
of it
c) Two thread in Java can have the same priority
d) A thread can exist only in two states, running and blocked
Answer: d. Explanation: Thread exist in several states, a thread can be running,
suspended, blocked, terminated & ready to run.
What requires less resources?
a) Thread
b) Process
c) Thread and Process
d) Neither Thread nor Process
Answer: a. Explanation: Thread is a lightweight and requires less
resources to create and exist in the process. Thread shares the process
resources.
What does not prevent JVM from terminating?
a) Process
b) Daemon Thread
c) User Thread
d) JVM Thread
Answer: b Explanation: Daemon thread runs in the background
and does not prevent JVM from terminating. Child of daemon thread is
also daemon thread.
What decides thread priority?
a) Process
b) Process scheduler
c) Thread
d) Thread scheduler
Answer: d Explanation: Thread scheduler decides the priority of the
thread execution. This cannot guarantee that higher priority thread will be
executed first, it depends on thread scheduler implementation that is OS
dependent.
What is true about time slicing?
a) Time slicing is OS service that allocates CPU time to available runnable
thread
b) Time slicing is the process to divide the available CPU time to available
runnable thread
c) Time slicing depends on its implementation in OS
d) Time slicing allocates more resources to thread
Answer: b. Explanation: Time slicing is the process to divide the available
CPU time to available runnable thread.
Deadlock is a situation when thread is waiting for other thread to release
acquired object.
a) True
b) False
Answer: a
Explanation: Deadlock is java programming situation where one thread
waits for an object lock that is acquired by other thread and vice-versa.
What should not be done to avoid deadlock?
a) Avoid using multiple threads
b) Avoid hold several locks at once
c) Execute foreign code while holding a lock
d) Use interruptible locks
Answer: c
Explanation: To avoid deadlock situation in Java programming do not
execute foreign code while holding a lock.
What is true about threading?
a) run() method calls start() method and runs the code
b) run() method creates new thread
c) run() method can be called directly without start() method being called
d) start() method creates new thread and calls code written in run() method
Answer: d. Explanation: start() eventually calls run() method. Start() method
creates thread and calls the code written inside run method
Which of the following is a correct constructor for thread?
a) Thread(Runnable a, String str)
b) Thread(int priority)
c) Thread(Runnable a, int priority)
d) Thread(Runnable a, ThreadGroup t)
Answer: a
Explanation: Thread(Runnable a, String str) is a valid constructor for
thread. Thread() is also a valid constructor.
Which of the following stops execution of a thread?
a) Calling SetPriority() method on a Thread object
b) Calling notify() method on an object
c) Calling wait() method on an object
d) Calling read() method on an InputStream object
Answer: b
Explanation: notify() wakes up a single thread which is waiting for this
object.
Which of the following will ensure the thread will be in running state?
a) yield()
b) notify()
c) wait()
d) [Link]()
Answer: c. Explanation: wait() always causes the current thread to go
into the object’s wait pool. Hence, using this in a thread will keep it in
running state.
Which of these keywords are used to implement synchronization?
a) synchronize
b) syn
c) synch
d) synchronized
Answer: d
Explanation: None
Which of this method is used to avoid polling in Java?
a) wait(). b) notify(). c) notifyAll(). d) all of the mentioned
Answer: d
Explanation: Polling is a usually implemented by looping in CPU is wastes
CPU time, one thread being executed depends on other thread output and
the other thread depends on the response on the data given to the first
thread. In such situation CPU time is wasted, in Java this is avoided by
using methods wait(), notify() and notifyAll().
Which of these method is used to tell the calling thread to give up a
monitor and go to sleep until some other thread enters the same monitor?
a) wait(). b) notify(). c) notifyAll(). d) sleep()
Answer: a
Explanation: wait() method is used to tell the calling thread to give up a
monitor and go to sleep until some other thread enters the same monitor.
This helps in avoiding polling and minimizes CPU idle time.
Which of these method wakes up the first thread that called wait()?
a) wake()
b) notify()
c) start()
d) notifyAll()
Answer: b
Explanation: None.
Which of these method wakes up all the threads?
a) wakeAll()
b) notify()
c) start()
d) notifyAll()
Answer: d. Explanation: notifyAll() wakes up all the threads that
called wait() on the same object. The highest priority thread will run first.
What is synchronization in reference to a thread?
a) It’s a process of handling situations when two or more threads need
access to a shared resource
b) It’s a process by which many thread are able to access same shared
resource simultaneously
c) It’s a process by which a method is able to access many different threads
simultaneously
d) It’s a method that allow too many threads to access any information the
require
Answer: a
Which of these is a bundle of information passed between machines?
a) Mime
b) Cache
c) Datagrams
d) DatagramSocket
Answer: c. Explanation: The Datagrams are the bundle of information
passed between machines
Which of these class is necessary to implement datagrams?
a) DatagramPacket
b) DatagramSocket
c) All of the mentioned
d) None of the mentioned
Answer: c
Explanation: None.
Which of these method of DatagramPacket is used to find the port number?
a) port()
b) getPort()
c) findPort()
d) recievePort()
Answer: b
Explanation: None.
Which of these method of DatagramPacket is used to obtain the byte array
of data contained in a datagram?
a) getData()
b) getBytes()
c) getArray()
d) recieveBytes()
Answer: a
Explanation: None.
Which of these methods of DatagramPacket is used to find the length of
byte array?
a) getnumber(). b) length()
c) Length(). d) getLength()
Answer: d
Explanation: getLength returns the length of the valid data contained in the
byte array that would be returned from the getData () method. This
typically is not equal to length of whole byte array.
Which of these class must be used to send a datagram packets over a
connection?
a) InetAdress. b) DatagramPacket
c) DatagramSocket. d) All of the mentioned
Answer: d
Explanation: By using 5 classes we can send and receive data between
client and server, these are InetAddress, Socket, ServerSocket,
DatagramSocket, and DatagramPacket.
Which of these method of DatagramPacket class is used to find the
destination address?
a) findAddress()
b) getAddress()
c) Address()
d) whois()
Answer: b
Explanation: None.
Which of these is a return type of getAddress() method of DatagramPacket
class?
a) DatagramPacket
b) DatagramSocket
c) InetAddress
d) ServerSocket
Answer: c
Explanation: None.
Which API gets the SocketAddress (usually IP address + port number) of
the remote host that this packet is being sent to or is coming from.
a) getSocketAddress() b) getAddress()
c) address(). d) none of the mentioned
Answer: a
Explanation: getSocketAddress() is used to get the socket address.
Which of the following is not an Enterprise Beans type?
a) Doubleton
b) Singleton
c) Stateful
d) Stateless
Answer: a
Explanation: Stateful, Stateless and Singleton are session beans.
Which of the following is not true about Java beans?
a) Implements [Link] interface
b) Extends [Link] class
c) Provides no argument constructor
d) Provides setter and getter methods for its properties
Answer: b
Explanation: [Link] is not a class. Instead it is an interface.
Hence it cannot be extended.
Which file separator should be used by MANIFEST file?
a) /
b) \
c) –
d) //
Answer: a
Explanation: MANIFEST file uses classes using / file separator.
Which of the following is correct error when loading JAR file with duplicate
name?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: c. Explanation: [Link]: Duplicate Name error is
thrown when .class file in the JAR contains a class whose class name is
different from the expected name.
Java Beans are extremely secured?
a) True
b) False
Answer: b
Explanation: JavaBeans do not add any security features to the Java
platform.
Which of the following is not a feature of Beans?
a) Introspection
b) Events
c) Persistence
d) Serialization
Answer: d. Explanation: Serialization is not the feature of Java Beans.
Introspection, Customization, Events, Properties and Persistence are the
features.
What is the attribute of java bean to specify scope of bean to have single
instance per Spring IOC?
a) prototype. b) singleton
c) request. d) session
Answer: b
Explanation: Singleton scope of bean specifies only one instance per spring
IOC container. This is the default scope.
Which attribute is used to specify initialization method?
a) init. b) init-method
c) initialization. d) initialization-method
Answer: b
Explanation: init-method is used to specify the initialization method.
<bean id = "helloWorld" class = "[Link]" init-method =
"init" />
Which attribute is used to specify destroy method?
a) destroy. b) destroy-method
c) destruction. d) destruction-method
Answer: b
Explanation: destroy-method is used to specify the destruction method.
<bean id = "helloWorld" class = "[Link]"
destroy-method = "destroy" />
How to specify autowiring by name?
a) @Qualifier. b) @Type
c) @Constructor d) @Name
Answer: a. Explanation: Different beans of the same class are
identified by name.
@Qualifier("student1")
@Autowired
Student student1;
What is Remote method invocation (RMI)?
a) RMI allows us to invoke a method of java object that executes on another
machine
b) RMI allows us to invoke a method of java object that executes on another
Thread in multithreaded programming
c) RMI allows us to invoke a method of java object that executes parallely in
same machine
d) None of the mentioned
Answer: a Explanation: Remote method invocation RMI allows us to invoke a
method of java object that executes on another machine
Which of these package is used for remote method invocation?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: b
Explanation: None.
Which of these methods are member of Remote class?
a) checkIP()
b) addLocation()
c) AddServer()
d) None of the mentioned
Answer: d. Explanation: Remote class does not define any methods, its
purpose is simply to indicate that an interface uses remote methods.
Which of these Exceptions is thrown by remote method?
a) RemoteException
b) InputOutputException
c) RemoteAccessException
d) RemoteInputOutputException
Answer: a
Explanation: All remote methods throw RemoteException.
Which of these class is used for creating a client for a server-client
operations?
a) serverClientjava
b) [Link]
c) [Link]
d) [Link]
Answer: c
Explanation: None.
Which of these package is used for all the text related modifications?
a) [Link]
b) [Link]
c) [Link]
d) [Link]
Answer: a. Explanation: [Link] provides capabilities for formatting,
searching and manipulating text.