Font size
WorksheetsJAVA QUIZZ-3
Total questions: 60
Worksheet time: 37mins
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
public class Foo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
Finally
Compilation fails.
The code runs with no output
An exception is thrown at runtime.
What will be the output of the program?
try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
finished
runtime error.
Compilation fails
Exception.
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
ABCD
Compilation fails.
C is printed before exiting with an error message.
BC is printed before exiting with an error message
public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (RuntimeException ex) /* Line 10 */
{
System.out.print("B");
}
catch (Exception ex1)
{
System.out.print("C");
}
finally
{
System.out.print("D");
}
System.out.print("E");
}
public static void badMethod()
{
throw new RuntimeException();
}
}
BD
BDE
BD
DE
java.lang.NullPointerException is a
Error
runtime exception
Compile time exception
None
FileNotFoundException
Is a subclass/extends IOException
Is a Compile time exception
Found in java.io package
All
Exception and Error are direct subclasses of?
.BaseException
Throwable
Object
RuntimeException
What block is always executed, independently of a exception being raised?
throws
finally
catch
throw
What keyword is used to explicitly raise a exception?
catch
throw
throws
raise
Which of these class is highest in hierarchy in java
java.lang.Exception
java.lang.Error
java.lang.Throwable
java.lang.Object
Exception is found in which package in java
java.lang
java.util
java.io
.java
Exception is a class/interface/abstract class/other?
Class
Interface
Abstract class
Other
class Main {
public static void main(String args[]) {
try {
throw 10;
}
catch(int e) {
System.out.println("Got the Exception " + e);
}
}
}
Got the Exception 10
Got the Exception 0
Compiler Error
none
Both class Error and class Exception are children of this parent:
A.
B.
C.
D.
Throwable
Catchable
Runable
Problem
What type of exception is thrown by parseInt() if it gets illegal data?
ArithmeticException
RunTimeException
NumberFormatException
NumberErro
The code within the ----------- block will always be executed whether or not an exception is thrown.
try
catch
finally
throw
Which exception is thrown by read() method?
IOException
InterruptedException
SystemException
SystemInputException
rom which problems is it possible for a program to recover?
Errors
Exceptions
Both errors and exceptions
Neither.
class exception_handling
{ public static void main(String args[])
{ try
{ int a, b;
b = 0;
a = 5 / b;
System.out.print("A");
} catch(ArithmeticException e)
{ System.out.print("B");
}
finally
{ System.out.print("C");
}
}
}
A
B
AC
BC
1. The capability to control the access of multiple threads to any shared resource is called_____________
Synchronization
Multitasking
multithreading
None
Why to use synchronization?
Avoiding thread interference
Avoiding consistency problem
Both
None
_______________ and __________________ are the types of synchronization.
Process synchronization and thread synchronization
multitasking and multithreading
Interthread communication and mutual exclusion
None
How many Types of synchronization approaches are there under mutual exclusion?
3
4
2
0
What are the approaches under mutual exclusion?
Synchronized method
Synchronized block
Static synchronization
All the above
Choose the correct syntax for synchronized method.
a. synchronized returntype methodname(.....)
a. returntype methodname(.....)
c. synchronized methodname(.....)
d. None
Identify the correct mutual exclusion approach:
synchronized(this)
{
….
….
}
Synchronized method
Synchronized block
Static Synchronization
None
Identify the correct mutual exclusion approach:
synchronized static returntype method(parameters)
{
}
synchronized method
synchronized block
static synchronization
None
__________________________ is a mechanism in which a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed.It
Inter thread communication
Co-operation
option 1 or option 2
None
_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.
wait()
notify()
notifyAll()
start()
______________wakes up a thread that called wait() on same object.
start()
run()
notify()
sleep()
_________wakes up all the threads that called wait() on same object.
notify()
notifyAll()
wait()
sleep()
Which is the static method?
wait()
sleep()
Both
None
wait(), notify() and notifyAll() belongs to which class?
Thread
Object
FileInputStream
Exception
_________thread in java is a service provider thread that provides services to the user thread.
Producer thread
Consumer thread
Daemon thread
None
Daemon thread is a _________priority thread.
low
high
Normal
None
wait() releases the lock on the shared resource.
True
False
_______________is the return type of isDaemon()
String
int
boolean
float
sleep() method belongs to which class?
Object
Thread
Exception
InputStream
We should notify the sleep() method to wake up.
True
False
Which of the following tasks are associated with JDBC library?
Making a connection to a database.
Creating SQL or MySQL statements.
Executing SQL or MySQL queries in the database.
All of these
Expand JDBC
(a)
_____________ interface handles the communications with the database server
DriverManager
Driver
Statement
None of these
___________ interface with all methods for contacting a database.
ResultSet
Statement
Connection
Driver
The third step involved in JDBC application is ____________
Execute Query
Establish Connection
importing packages
Register the Driver
In Type 2 Driver, JDBC API calls are converted into native _____________ API calls, which are unique to the database
C/C++
Java
JavaScript
Visual Programming
Type 4 Driver is also called as (a)
_____________ driver talks with server-side middleware which then talks to the database
Type 1
Type 2
Type 3
Type 4
(a) should be imported to use SQL statements
The most common approach to register a driver is to use Java's (a) method.
To open a connection, DriverManager. (a) () is to be used.
Which method returns an integer as its result?
execute()
executeUpdate()
executeQuery()
extract()
Which interface will NOT accept input parameters
Statement
PreparedStatement
CallableStatement
PrepareStatement
All parameters in JDBC are represented by the ? symbol, which is known as the (a) .
in a ResultSet object, the ___________ methods to retrieve the value of a given column.
POST()
GET()
setXXX()
getXXX()
We bind values to _________ parameters with the setXXX methods
OUT
IN
INPUT
OUTPUT
The corresponding SQL type for the boolean JAVA type is_____
BOOLEAN
BIT
BOOL
BYTE
(a) method returns the total number of columns in the ResultSet object.
_____________interface is used to execute stored procedures.
Statement
PreparedStatement
CallableStatement
execute
(a) method is used to create an object of the class ResultSetMetaData.
