Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Test 2

Total questions: 36

Worksheet time: 42mins

Name
Class
Date
1.

Enter your Register number

(not a question but required xD)

4 lines
2.
a)

{1=C, 2=JavaEE, 4=Python, 3=PHP}

b)

{1=C, 2=JavaSE, 3=Python, 4=PHP}

c)

{1=C, 2=JavaEE, 3=Python, 4=PHP}

d)

{1=C, 2=JavaSE,2=JavaEE, 3=Python, 4=PHP}

e)

NullPointerException

3.

-Entries are not organized as key/value pairs.

-Duplicate entries are rejected.

Which interface of the java.util package offers the specified behavior?

a)

List

b)

Map

c)

Set

d)

None of the above

4.

List listNames = new ArrayList();

listNames.add("Tom");

listNames.add("Mary");

listNames.add("Peter");


String name2 = (String) listNames.get(1);

System.out.println(name2);

What is the output of the above code

a)

Tom

b)

Mary

c)

Peter

d)

raises Exception

5.

Which of these interface is not part of Java’s collection framework?

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

6.

Which of these return type of hasNext() method of an iterator?

a)

Integer

b)

Double

c)

Boolean

d)

Collections Object

7.

Which of these methods deletes all the elements from invoking collection?

a)

clear();

b)

reset();

c)

delete();

d)

remove();

8.

String s1 = "hello";

String s2 = new String("hello");

if (s1 == s2) System.out.print("Hey");

else System.out.print("Yo");


What is the output?

a)

Hey

b)

Yo

c)

There is no output.

d)

This code will not compile.

9.

String s = "whatever".substring(1,4);


What is the value of s?

a)

"hate"

b)

"hat"

c)

"whate"

d)

"what"

e)

StringIndexOutOfBoundsException

10.

int x = "bob".compareTo("Bob");

if (x>=0) System.out.print("Good");

else System.out.print("Bad");


What is the output?

a)

Good

b)

Bad

c)

There is no output.

d)

This code will not compile.

11.

String s = "cool cat".substring(6);


What is the value of s?

a)

"cat"

b)

"at"

c)

"cool c"

d)

This code does not compile.

e)

StringIndexOutOfBoundsException

12.

Which of the following is FALSE about arrays on Java

a)

A java array is always an object

b)

Length of array can be changed after creation of array

c)

Arrays in Java are always allocated on heap

13.

Find the output

class Test {

public static void main(String args[]) {

int arr[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

Compile error

b)

Exception

c)

Garbage Value

Garbage Value

d)

0

0

14.

Find the output

class Test {

public static void main(String args[]) {

int arr [ ] = new int[2];

System.out.println(arr[0]);

System.out.println(arr[1]);

}

}

a)

Compile error

b)

Exception

c)

Garbage Value

Garbage Value

d)

0

0

15.

What is the length of the following array: byte[] data = { 12, 34, 9, 0, -62, 88 };

a)

1

b)

5

c)

6

d)

12

16.

class Demo1

{

public static void main(String args[])

{

int i[] = new int[10];

System.out.println(i[10]);

}

}

a)

0

b)

Garbage Value

c)

Out-of-bounds exception

d)

Error

17.

Output of following Java program?

class Test{

public static void main (String[] args) {

int arr1[] = {1, 2, 3};

int arr2[] = {1, 2, 3};

if (arr1 == arr2)

System.out.println("Same");

else

System.out.println("Not same");

}}

a)

Same

b)

Not same

c)

Error

18.

Output of following Java Program?

a)

Derived::show() called

b)

Base::show() called

c)

Run time Error

d)

Compilation Error

19.

Which inheritance in java programming is not supported

a)

Multiple inheritance using classes

b)

Multiple inheritance using interfaces

c)

Multilevel inheritance

d)

Single inheritance

20.

What will be the output of the following Java program?

a)

None of the mentioned

b)

0

c)

120

d)

1

21.

Output of following Java program?

a)

Base

Derived

Derived

b)

Base

Base

Derived

c)

Base

Derived

Base

d)

Compiler Error

22.

What is subclass in java?

a)

A subclass is a class that extends another class

b)

A subclass is a class declared inside a class

c)

Both above.

d)

None of the above.

23.
Which of these class is not a member class of java.io package?
a)
String
b)
StringReader
c)
Writer
d)
File
24.
 Which exception is thrown by read() method?
a)
SystemInputException
b)
IOException
c)
SystemException
d)
InterruptedException
25.
Which of these class contains the methods print() & println()?
a)
PrintStream
b)
BUfferedOutputStream
c)
System.out
d)
System
26.
Which method is used to close the Stream?
a)
close();
b)
flush();
c)
null();
d)
final();
27.
Which of these class is not related to input and output stream in terms of functioning?
a)
File
b)
Write
c)
InputStream
d)
Reader
28.

What will be the output?

a)

An Exception is caught in method1.

b)

An Exception is caught in method2.

c)

An Exception is caught in method3.

d)

The program crashes.

29.

Which of these is caused by integer division by zero?

a)

ArithmeticException

b)

ArrayIndexOutOfBoundsException

c)

MathException

d)

DivisionByZeroException

30.

If sc = new Scanner(System.in) and x = sc.nextInt(), which of these is thrown if the user inputs the String "x"?

a)

NullPointerException

b)

StringIndexOutOfBoundsException

c)

InputMismatchException

d)

IllegalArgumentException

31.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

32.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

33.

It is a Java specification that provides certain functionality and standard to ORM tools.

a)

Hibernate

b)

JPA

c)

Dev Tools

d)

Spring Data

34.

it contains information of configuration for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin etc.

a)

maven wrapper configuration

b)

application.properties

c)

pom.xml file

d)

application.xml

35.

Which of the following protocol is used by RESTful web services as a medium of communication between client and server?

a)

HTTP

b)

FTP

c)

Gopher

d)

None of the Above

36.

if I want to fetch some data from the Database which http method should be used?

a)

Get

b)

Put

c)

Post

d)

Delete