wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA QUIZZ-3

Total questions: 60

Worksheet time: 37mins

Name
Class
Date
1.

Which of these keywords is not a part of exception handling?

a)

try

b)

finally

c)

thrown

d)

catch

2.

public class Foo

{

public static void main(String[] args)

{

try

{

return;

}

finally

{

System.out.println( "Finally" );

}

}

}

a)

Finally

b)

Compilation fails.

c)

The code runs with no output

d)

An exception is thrown at runtime.

3.

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");

a)

finished

b)

runtime error.

c)

Compilation fails

d)

Exception.

4.

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

}

}

a)

ABCD

b)

Compilation fails.

c)

C is printed before exiting with an error message.

d)

BC is printed before exiting with an error message

5.

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();

}

}

a)

BD

b)

BDE

c)

BD

d)

DE

6.

java.lang.NullPointerException is a

a)

Error

b)

runtime exception

c)

Compile time exception

d)

None

7.

FileNotFoundException

a)

Is a subclass/extends IOException

b)

Is a Compile time exception

c)

Found in java.io package

d)

All

8.

Exception and Error are direct subclasses of?

a)

.BaseException

b)

Throwable

c)

Object

d)

RuntimeException

9.

What block is always executed, independently of a exception being raised?

a)

throws

b)

finally

c)

catch

d)

throw

10.

What keyword is used to explicitly raise a exception?

a)

catch

b)

throw

c)

throws

d)

raise

11.

Which of these class is highest in hierarchy in java

a)

java.lang.Exception

b)

java.lang.Error

c)

java.lang.Throwable

d)

java.lang.Object

12.

Exception is found in which package in java

a)

java.lang

b)

java.util

c)

java.io

d)

.java

13.

Exception is a class/interface/abstract class/other?

a)

Class

b)

Interface

c)

Abstract class

d)

Other

14.

class Main {

public static void main(String args[]) {

try {

throw 10;

}

catch(int e) {

System.out.println("Got the Exception " + e);

}

}

}

a)

Got the Exception 10

b)

Got the Exception 0

c)

Compiler Error

d)

none

15.

Both class Error and class Exception are children of this parent:

A.

B.

C.

D.

a)

Throwable

b)

Catchable

c)

Runable

d)

Problem

16.

What type of exception is thrown by parseInt() if it gets illegal data?

a)

ArithmeticException

b)

RunTimeException

c)

NumberFormatException

d)

NumberErro

17.

The code within the ----------- block will always be executed whether or not an exception is thrown.

a)

try

b)

catch

c)

finally

d)

throw

18.

Which exception is thrown by read() method?

a)

IOException

b)

InterruptedException

c)

SystemException

d)

SystemInputException

19.

rom which problems is it possible for a program to recover?

a)

Errors

b)

Exceptions

c)

Both errors and exceptions

d)

Neither.

20.

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)

A

b)

B

c)

AC

d)

BC

21.

1. The capability to control the access of multiple threads to any shared resource is called_____________

a)

Synchronization

b)

Multitasking

c)

multithreading

d)

None

22.

Why to use synchronization?

a)

Avoiding thread interference

b)

Avoiding consistency problem

c)

Both

d)

None

23.

_______________ and __________________ are the types of synchronization.

a)

Process synchronization and thread synchronization

b)

multitasking and multithreading

c)

Interthread communication and mutual exclusion

d)

None

24.

How many Types of synchronization approaches are there under mutual exclusion?

a)

3

b)

4

c)

2

d)

0

25.

What are the approaches under mutual exclusion?

a)

Synchronized method

b)

Synchronized block

c)

Static synchronization

d)

All the above

26.

Choose the correct syntax for synchronized method.

a)

a. synchronized returntype methodname(.....)

b)

a. returntype methodname(.....)

c)

c. synchronized methodname(.....)

d)

d. None

27.

Identify the correct mutual exclusion approach:

synchronized(this)

{

….

….

}

a)

Synchronized method

b)

Synchronized block

c)

Static Synchronization

d)

None

28.

Identify the correct mutual exclusion approach:

synchronized static returntype method(parameters)

{

}

a)

synchronized method

b)

synchronized block

c)

static synchronization

d)

None

29.

__________________________ 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

a)

Inter thread communication

b)

Co-operation

c)

option 1 or option 2

d)

None

30.

_____________tells calling thread to give up monitor and go to sleep until some other thread enters the same monitor and call notify.

a)

wait()

b)

notify()

c)

notifyAll()

d)

start()

31.

______________wakes up a thread that called wait() on same object.

a)

start()

b)

run()

c)

notify()

d)

sleep()

32.

_________wakes up all the threads that called wait() on same object.

a)

notify()

b)

notifyAll()

c)

wait()

d)

sleep()

33.

Which is the static method?

a)

wait()

b)

sleep()

c)

Both

d)

None

34.

wait(), notify() and notifyAll() belongs to which class?

a)

Thread

b)

Object

c)

FileInputStream

d)

Exception

35.

_________thread in java is a service provider thread that provides services to the user thread.

a)

Producer thread

b)

Consumer thread

c)

Daemon thread

d)

None

36.

Daemon thread is a _________priority thread.

a)

low

b)

high

c)

Normal

d)

None

37.

wait() releases the lock on the shared resource.

a)

True

b)

False

38.

_______________is the return type of isDaemon()

a)

String

b)

int

c)

boolean

d)

float

39.

sleep() method belongs to which class?

a)

Object

b)

Thread

c)

Exception

d)

InputStream

40.

We should notify the sleep() method to wake up.

a)

True

b)

False

41.

Which of the following tasks are associated with JDBC library?

a)

Making a connection to a database.

b)

Creating SQL or MySQL statements.

c)

Executing SQL or MySQL queries in the database.

d)

All of these

42.

Expand JDBC

(a)  

43.

_____________ interface handles the communications with the database server

a)

DriverManager

b)

Driver

c)

Statement

d)

None of these

44.

___________ interface with all methods for contacting a database.

a)

ResultSet

b)

Statement

c)

Connection

d)

Driver

45.

The third step involved in JDBC application is ____________

a)

Execute Query

b)

Establish Connection

c)

importing packages

d)

Register the Driver

46.

In Type 2 Driver, JDBC API calls are converted into native _____________ API calls, which are unique to the database

a)

C/C++

b)

Java

c)

JavaScript

d)

Visual Programming

47.

Type 4 Driver is also called as (a)  

48.

_____________ driver talks with server-side middleware which then talks to the database

a)

Type 1

b)

Type 2

c)

Type 3

d)

Type 4

49.

(a)   should be imported to use SQL statements

50.

The most common approach to register a driver is to use Java's (a)   method.

51.

To open a connection, DriverManager. (a)   () is to be used.

52.

Which method returns an integer as its result?

a)

execute()

b)

executeUpdate()

c)

executeQuery()

d)

extract()

53.

Which interface will NOT accept input parameters

a)

Statement

b)

PreparedStatement

c)

CallableStatement

d)

PrepareStatement

54.

All parameters in JDBC are represented by the ? symbol, which is known as the (a)   .

55.

in a ResultSet object, the ___________ methods to retrieve the value of a given column.

a)

POST()

b)

GET()

c)

setXXX()

d)

getXXX()

56.

We bind values to _________ parameters with the setXXX methods

a)

OUT

b)

IN

c)

INPUT

d)

OUTPUT

57.

The corresponding SQL type for the boolean JAVA type is_____

a)

BOOLEAN

b)

BIT

c)

BOOL

d)

BYTE

58.

(a)   method returns the total number of columns in the ResultSet object.

59.

_____________interface is used to execute stored procedures.

a)

Statement

b)

PreparedStatement

c)

CallableStatement

d)

execute

60.

(a)   method is used to create an object of the class ResultSetMetaData.