wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Java Concepts Challenge

Total questions: 87

Worksheet time: 1hrs 24mins

Name
Class
Date
1.

What is the primary purpose of the StringBuilder class?

a)

To efficiently create and manipulate strings.

b)

To store immutable strings.

c)

To convert strings to integers.

d)

To manage string formatting only.

2.

What is the difference between an interface and an abstract class?

a)

An interface can have implemented methods and supports single inheritance.

b)

An abstract class cannot have any methods and supports multiple inheritance.

c)

An interface can only be used in a single class and cannot extend other interfaces.

d)

An interface cannot have any implementation and supports multiple inheritance, while an abstract class can have some implemented methods and supports single inheritance.

3.

Which of the following is a valid way to declare a package in Java?

a)

import com.example;

b)

package:com.example;

c)

com.example.package;

d)

package com.example;

4.

What exception is thrown when an array is accessed with an illegal index?

a)

IllegalArgumentException

b)

NullPointerException

c)

ArrayIndexOutOfBoundsException

d)

IndexOutOfRangeException

5.

Which collection class allows duplicate elements?

a)

LinkedList

b)

TreeMap

c)

HashSet

d)

ArrayList

6.

What is the purpose of the Wrapper classes in Java?

a)

To provide additional methods for mathematical operations.

b)

To store multiple values in a single object.

c)

The purpose of Wrapper classes in Java is to convert primitive data types into objects.

d)

To enhance the performance of primitive data types.

7.

Which of the following is true about Java I/O streams?

a)

Java I/O streams only handle binary data.

b)

Java I/O streams cannot be used for text files.

c)

Java I/O streams are limited to network communication.

d)

Java I/O streams can be categorized into byte streams and character streams.

8.

Predict the output:

a)

[PJP, Java]

[Python, PJP, Java]

[PJP, Java]

b)

Compile time error

c)

Run time error

d)

None of the above

9.

Predict the output:

a)

Prints nothing

b)

Compile Time Error: variable x is already defined

c)

9

d)

8

10.

Predict the output:

a)

Prints nothing

b)

0

c)

null

d)

OutOfBoundsException

11.

Predict the output:

a)

Child display..

b)

Child display..Parent display..

c)

Parent display..Child display..

d)

Compile Time Error

12.

Predict the output:

a)

true false

b)

true true

c)

false true

d)

false false

13.

Predict the output:

a)

a = 0

Divide by zero error

b)

a = 0

inside the finally block

c)

a = 0

Divide by zero error

inside the finally block

d)

Divide by zero error

inside the finally block

14.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

15.

Predict the value of k,

int k =10;

k=k+k++;

a)

11

b)

20

c)

21

d)

22

16.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

17.

class increment {

public static void main(String args[]) {

double var1 = 1 + 5;

double var2 = var1 / 4;

int var3 = 1 + 5;

int var4 = var3 / 4;

System.out.print(var2 + " " + var4); } }

a)

1 1

b)

0 1.5

c)

1.5 1

d)

1 1.5

18.

class increment {

public static void main(String args[]) {

int g = 3;

System.out.print(++g * 8); } }

a)

24

b)

32

c)

25

d)

34

19.

class Output {

public static void main(String args[]) {

int a = 1; int b = 2; int c; int d;

c = ++b;

d = a++;

c++;

b++;

++a;

System.out.println(a + " " + b + " " + c); } }

a)

4 4 3

b)

3 3 4

c)

3 4 4

d)

4 3 3

20.

class bitwise_operator {

public static void main(String args[]) {

int var1 = 42;

int var2 = ~var1;

System.out.print(var1 + " " + var2); } }

a)

42 42

b)

42 -43

c)

43 42

d)

43 -42

21.

class bitwise_operator {

public static void main(String args[]) {

int a = 3;

int b = 6;

int c = a | b;

int d = a & b;

System.out.println(c + " " + d); } }

a)

7 2

b)

7 5

c)

5 7

d)

7 7

22.

class rightshift_operator {

public static void main(String args[]) {

int x; x = 10;

x = x >> 1;

System.out.println(x); } }

a)

2

b)

7

c)

5

d)

10

23.
What are the primary goals of the collection framework in Java?
a)
To replace arrays completely
b)
To provide a way to organize files
c)
To manage and manipulate collections of objects
d)
To optimize CPU usage
24.
Which Java collection framework classes are commonly used?
a)
Vector and Stack
b)
Array and List
c)
ArrayList and LinkedList
d)
Set and Map
25.
What are the advantages of using the collection framework?
a)
Faster execution of programs
b)
Increased memory usage
c)
Code reusability and reliability
d)
Removal of null references
26.
What are the main differences between a collection framework and a data structure?
a)
They are the same
b)
Data structures store data, while collection framework doesn't
c)
Collection framework provides interfaces and classes to work with data structures
d)
Collection framework doesn't provide any classes
27.
What is the role and importance of the Collection framework?
a)
It doesn't have any role or importance
b)
To complicate the programming process
c)
To make Java slower
d)
To provide reusable data structures and algorithms
28.
Which interfaces are commonly used from the Collection framework?
a)
List and Array
b)
Vector and Map
c)
Set and List
d)
Set and Map
29.
What is the difference between HashSet and HashMap in Java?
a)
HashSet is used for sorting, while HashMap is for searching
b)
HashSet stores unique elements, while HashMap stores key-value pairs
c)
HashSet is a synchronized collection, while HashMap is not
d)
HashSet has better performance than HashMap
30.
What is the difference between a collection and a Map interface?
a)
There is no difference, they are the same
b)
Collection stores key-value pairs, while Map stores elements
c)
Collection stores elements, while Map stores key-value pairs
d)
Collection has better performance than Map
31.
Why is a String immutable in Java?
a)
To make programming harder
b)
To improve memory usage
c)
To prevent modification after creation
d)
To make it thread-safe
32.

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

a)

List

b)

Sorted List

c)

Set

d)

Sorted Map

33.

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

a)

clear();

b)

reset();

c)

delete();

d)

remove();

34.

Which of these interface declares core method that all collections will have?

a)

Collection

b)

EventListner

c)

Comparator

d)

Set

e)

List

35.

What implementation of Iterator can traverse a collection in both directions?

a)

Iterator

b)

ListIterator

c)

SetIterator

d)

MapIterator

36.

Which interface does java.util.Hashtable implement?

a)

Java.util.Map

b)

Java.util.List

c)

Java.util.HashTable

d)

Java.util.Collection

37.

The default capacity of a Vector is:

a)

10

b)

12

c)

8

d)

0

38.

Which of these is synchronized?

a)

TreeMap

b)

HashMap

c)

Hashtable

d)

All of the above

39.

How can you sort given HashMap on basis of values

a)

Implement Comparator interface and override its compare method

b)

It is not possible

c)

Implement Comparator interface and override its compareTo method

d)

Implement Comparator interface and override its comparable method

40.

-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

41.
a)

[Computer, Network, Networks, Programming, Security]

b)

[Computer, Programming, Network, Networks, Programming, Security]

c)

[Computer, Programming, Computer, Networks, Network, Security]

d)

[Computer, Networks, Network, Programming, Security]

42.

Which of the following is/are correct statements?

a)

HashSet class implements the Set interface

b)

HashSet does not allow duplicate elements that means you can not store duplicate values in HashSet.

c)

HashSet permits to have a single null value.

d)

HashMap does not allow duplicate keys however it allows to have duplicate values.

e)

HashMap and HashSet are threadsafe

43.

Which of the following statement(s) is/are TRUE?

a)

Both HashMap and HashSet are not synchronized.

b)

HashMap does not allow duplicate keys however it allows to have duplicate values.

c)

HashMap permits single null key and any number of null values.

d)

Both HashMap and HashSet are synchronized.

44.
a)

{"Computer", "Programming","Networks","null"}

b)

{"Computer", "Programming","Networks",null,"null"}

c)

Line 11 : Genetates NullPointer Exception

d)

Line12: Generates NullPointerException

45.

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

46.

int x = 5;

int y = 6

int z = 50;

System.out.println(x + y + z);


What will be the output?

a)

61

b)

5650

c)

66

d)

x + y + z

47.

Which of the following is the right way of defining char variable?

a)

char myGrade = 'B';

b)

char myGrade = "B";

c)

char myGrade 'B';

d)

char myGrade = "B"

48.

Base on the code block below what will be the output to the console?


int n=5;

int c=0;

while(n>=0&&c<=5) {

System.out.println(c+":"+n);

c++;

n--;

}

a)

1:1

2:2

3:3

4:4

5:5

b)

1:4

2:3

3:2

4:1

c)

0:5

1:4

2:3

3:2

4:1

5:0

d)

0:0

1:1

2:2

3:3

4:4

5:5

49.

What is the output of the below Java program?


int hours = 10;

String message=null;


switch(hours)

{

case 10: message ="TEN";

case 11: message ="TEN AGAIN";

default: message ="TEN AS USUAL";

}

System.out.println(message);

a)

TEN

TEN AGAIN

TEN AS USUAL

b)

TEN

c)

TEN AS USUAL

50.

Which of the following use the correct syntax for a traditional for loop?

a)

for(x=0; x<10; x++) {System.out.println(x);}

b)

for(int x=0; x<10; x++) {System.out.println(x);}

c)

for(x=0, x<10, x++){System.out.println(x);}

d)

for(int x=0: x<10: x++){System.out.println(x);}

51.

Which of the following use the correct syntax for an enhanced for loop?

a)

for(int x=0; x<10; x++) {System.out.println(x);}

b)

for(int x : numbers) {System.out.println(x);}

c)

for(x=0, x<10, x++){System.out.println(x);}

d)

for(int x=0: int numbers=10){System.out.println(x);}

52.

Base on the code block below what will print to the console?


String Days[]= {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};


for(int i=6;i>=0;i--) {

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

}

a)

Sunday Monday Tuesday Wednesday Thursday Friday Saturday

b)

Sunday

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday

c)

"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"

d)

Saturday

Friday

Thursday

Wednesday

Tuesday

Monday

Sunday

53.

What would be outputted if you inputted "B"?

a)

1

b)

2

c)

3

54.

What would print if the following code was inserted on line 9.


System.out.print(num1);

a)

5

b)

10

c)

15

d)

nothing, this will trigger a error.

55.

What will be outputted from this code?

a)

5

b)

6

c)

nothing, this will trigger an error.

d)

10

56.

What is the output of this program?

a)

0

2

6

8

10

b)

0

2

4

c)

2

4

d)

Nothing, this program will not compile.

57.

What is the output of the following code:


System.out.prinltn(Integer.SIZE);

a)

2

b)

16

c)

4

d)

32

58.

What is type coercion

a)

is an implicit type casting

b)

It is explicit type casting

c)

It is related to boxing

d)

It is not related to type casting

59.

How many wrapper classes are available in Java

a)

8

b)

7

c)

6

d)

9

60.

How to find out whether the given character is alphabet or not in java

a)

By using Character.isAlpha()

b)

By using Character.isLetter()

c)

By using Character.isAlphabet()

d)

By using isletter()

61.

How to convert character into string in java

a)

using String.valueOf()

b)

using "" with conatenation

c)

using toString() method

d)

using charAt() function

62.

Which of these class is used to read characters and strings in Java from console?

a)

StringReader

b)

BufferedReader

c)

InputStreamReader

d)

BufferedStreamReader

63.

Which of these stream contains the classes which can work on character stream?

a)

InputStream

b)

OutputStream

c)

Character Stream

d)

All of the mentioned

64.

Which of these is a type of stream in Java?

a)

Integer stream

b)

Byte Stream

c)

Short Stream

d)

Long Stream

65.

Which of these classes are used by character streams for input and output operations?

a)

InputStream

b)

InputOutputStream

c)

ReadStream

d)

Writer

66.

To find the corect declaration of long data type in java?

a)

long num=09876654;

b)

long num=-1223733L;

c)

long num=1223333l;

d)

int num=099987;

67.
Which of these class is not a member class of java.io package?
a)
String
b)
StringReader
c)
Writer
d)
File
68.
Which is used for writing data to a file in file handling?
a)
FileInputStream
b)
FileOutputStream
c)
Both A & B
d)
None of the above
69.
 Which exception is thrown by read() method?
a)
SystemInputException
b)
IOException
c)
SystemException
d)
InterruptedException
70.
Which of these class contains the methods print() & println()?
a)
PrintStream
b)
BUfferedOutputStream
c)
System.out
d)
System
71.

2. Class at the top of exception class hierarchy?

a)

ArithmeticException

b)

Throwable

c)

Object

d)

Exception

72.

3. In which of the following package, Exception class exist?

a)

java.util

b)

java.io

c)

java.lang

d)

java.file

73.

Why is data abstraction important in Java?

a)

Data abstraction helps in hiding the implementation details and showing only the necessary features of an object.

b)

Data abstraction is not important in Java

c)

Data abstraction makes the code more complex

d)

Data abstraction slows down the program

74.

How can we achieve multiple inheritance in Java using interfaces?

a)

Implementing multiple interfaces in a single class

b)

Implementing multiple classes in a single interface

c)

Using abstract classes instead of interfaces

d)

Extending multiple classes in a single class

75.

Which one of the following are essential features of an object-oriented programming language?

a)

Abstraction and encapsulation

b)

Strictly-typedness

c)

Polymorphism in the presence of inheritance

d)

Type-safe property coupled with sub-type rule

76.

What is serialization in Java?

a)

It is a process of converting Object data into sequence of bytes

b)

It is the process of converting Sequence of bytes into Objects

c)

Used to transform data in serial form

d)

No serialization in java

77.

what is the purpose of 'transient' keyword in serialization

a)

used to provide security to the data

b)

It is not used with serialization

c)

These transient members prints primitive type default values at the time of de-serialization

d)

These transient members prints garbage values at the time of de-serialization

78.

The following class(es) is/are used in serialization and deserialization process

a)

ObjectOutputStream

b)

ObjectInputStream()

c)

DataOuptutStream

d)

BufferedReader

79.

Serialization throws an error

a)

when two classes combined with HAS-A relationship

b)

when two classes combined with IS-A relationship

c)

Both HAS-A and IS-A gives error

d)

either HAS-A or IS-A gives error

80.

What is/are the possible exception(s) in De-serialization

a)

IOException

b)

ClassNotFoundException

c)

ClassCastException

d)

SerializationNotSupportedException

81.

What is the name of marker interface used in Serialization

a)

Serializable

b)

Serial

c)

Cloneable

d)

Serialization

82.

What is the Syntax of DeSerialization

a)

Class_name Obj=(Class_name)objinputStream_obj.readObject();

b)

Class_name Obj=(Class_name)objinputStream_obj.read();

c)

Class_name Obj=(Class_name)objinputStream_obj.readObject(file);

d)

Objinputstream =(Class_name)obj.readObject();

83.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

84.

What will be the output of below code?


String statement = "Outfit of the day";

System.out.println(statement.Substring(3,6));

a)

it of

b)

tfit

c)

fit

d)

FIT

85.

Select correct code to create an array of "double" datatype of length 5.

a)

double arr = double[5];

b)

double{} arr = new double{5};

c)

double[5] arr = new double[];

d)

double[] arr = new double[5];

86.

How many objects will be created?

String a = new String("Examveda");

String b = new String("Examveda");

String c = "Examveda";

String d = "Examveda";

a)

4

b)

3

c)

2

d)

none of these

87.

What is the most appropriate way to check if two Strings are identical?

a)

string1 == string2

b)

string1.equals(string2)

c)

string1.same(string2)

d)

string1.equalsIgnorecase(string2)