wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Test-2

Total questions: 100

Worksheet time: 2hrs 33mins

Name
Class
Date
1.

Java is a

a)

Procedure Oriented Language

b)

Structure Oriented Language

c)

Object_Oriented Language

d)

Machine Language

2.

The name of the following should be the file name in Java

a)

Object Name

b)

Variable Nam

c)

Class Name

d)

Array Name

3.

Java program is

a)

Interpreted

b)

Compiled

4.

A ___________ file is created after successful compilation of a Java program.

a)

Object file

b)

Array file

c)

Class file

d)

String file

5.

Command to compile Java program

a)

javax

b)

javay

c)

javac

d)

Java

6.

Command to run a Java program

a)

javaa

b)

java

c)

jaava

d)

jaavaa

7.

JDK stands for

a)

Java Developer Kit

b)

Java Development Kit

c)

Java Design Kit

d)

Java Debugging Kit

8.

JRE stands for

a)

Java Run Environment

b)

Java Run Execution

c)

Java Runtime Environment

d)

Java Ready Execution

9.

Java is

a)

Machine dependent language

b)

Machine independent language

10.

Java was originally named:

a)

Coffee

b)

Oak

c)

New C++

d)

Duke

11.
When we want to print in Java, we use the code ......
a)
system.out.print();
b)
System.out.println();
c)
System.Out.Printf();
d)
System.out.show();
12.

In Java WORA stands for

a)

Write Once Recall Anywhere

b)

Write Once Return Anywhere

c)

Write Once Read Anywhere

d)

Write Once Run Anywhere

13.

JVM stands for

a)

Java Vital Machine

b)

Java Virtual Machine

c)

Java Vendor machine

14.

Java programs ________________

a)

are only compiled

b)

are only compiled not interpreted

c)

are only interpreted

d)

are both compiled and interpreted

15.

Main() method is not mandatory for a Java program

a)

True

b)

False

16.

Java Programming was designed by ______

a)

Sun MicroSystems

b)

Mozilla Corporation

c)

Microsoft

d)

Amazon Inc.

17.

Earlier name of Java Programming language was –

a)

Eclipse

b)

D

c)

Oak

d)

Netbean

18.

Which of the following personality is called as father of Java Programming language –

a)

Guido vom Russom

b)

Larry Page

c)

Bjarne Stroustrup

d)

James Gosling

19.

Which of the following is not OOPS concept in Java?

a)

Inheritance

b)

Encapsulation

c)

Polymorphism

d)

Compilation

20.

Which concept of Java is a way of converting real world objects in terms of class?

a)

Polymorphism

b)

Encapsulation

c)

Abstraction

d)

Inheritance

21.

Which concept of Java is achieved by combining methods and attribute into a class?

a)

Encapsulation

b)

Inheritance

c)

Polymorphism

d)

Abstraction

22.

Java was developed in which year

a)

1992

b)

1993

c)

1994

d)

1995

23.

Which component is used to compile, debug and execute java program?

a)

JDK

b)

JRE

c)

JVM

d)

JIT

24.

The icon of Java program is taken from ___.

a)

a cup of coffee

b)

a tornado that spits fire

c)

a volcano under water

d)

a candle with a flame

25.

In Java EE, EE stands for ___.

a)

Entertainment Edition

b)

Entrepreneur Edition

c)

Enterprise Emperor

d)

Enterprise Edition

26.

What are the four main principles of Object-Oriented Programming?

a)

Encapsulation, Abstraction, Inheritance, Polymorphism

b)

Polymorphism, Data Abstraction, Class, Object

c)

Composition, Aggregation, Delegation, Interface

d)

Inheritance, Composition, Encapsulation, Data Hiding

27.

Explain the concept of inheritance in Java.

a)

Inheritance is a method of data encryption in Java.

b)

Inheritance allows a class to create multiple instances of itself.

c)

Inheritance in Java is used to define interfaces only.

d)

Inheritance in Java allows a class to inherit properties and behaviors (methods) from another class, promoting code reuse and establishing a parent-child relationship between classes.

28.

What is polymorphism and how is it implemented in Java?

a)

Polymorphism is only achieved through inheritance in Java.

b)

Polymorphism is a feature exclusive to C++ and not applicable in Java.

c)

Polymorphism can only be implemented using abstract classes in Java.

d)

Polymorphism in Java is implemented through method overriding and interfaces.

29.

Define encapsulation and its importance in Java.

a)

Encapsulation is the practice of bundling the data (attributes) and methods (functions) that operate on the data into a single unit or class, while restricting access to some of the object's components.

b)

Encapsulation is only relevant for primitive data types in Java.

c)

Encapsulation allows unrestricted access to all class components.

d)

Encapsulation is the process of separating data from methods in Java.

30.

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

a)

An abstract class can have implemented methods and state, while an interface cannot.

b)

An abstract class is always public, while an interface is always private.

c)

An interface can have state and implemented methods.

d)

An abstract class cannot have any methods.

31.

How does Java handle exceptions?

a)

Java uses try-catch-finally blocks to handle exceptions.

b)

Java does not support exception handling.

c)

Java requires all exceptions to be handled at compile time.

d)

Java uses only if-else statements for error handling.

32.

What is the purpose of the try-catch block in Java?

a)

To improve code readability.

b)

To define variables in a method.

c)

To handle exceptions and prevent program crashes.

d)

To optimize memory usage.

33.

Explain the difference between checked and unchecked exceptions.

a)

Both checked and unchecked exceptions require handling.

b)

Checked exceptions require handling or declaration, while unchecked exceptions do not.

c)

Checked exceptions are always runtime errors.

d)

Unchecked exceptions must be declared in the method signature.

34.

What is the finally block used for in exception handling?

a)

The finally block is only executed if an exception occurs.

b)

The finally block ensures that specific code runs after try and catch blocks, regardless of exceptions.

c)

The finally block is used to define a new exception type.

d)

The finally block is used to catch exceptions before they are thrown.

35.

What is the Java Collections Framework?

a)

A library for network programming in Java.

b)

A unified architecture for representing and manipulating collections of objects in Java.

c)

A set of tools for database management in Java.

d)

A framework for building graphical user interfaces in Java.

36.

List the main interfaces of the Java Collections Framework.

a)

List, Set, Queue, Map

b)

Stack

c)

HashTable

d)

ArrayList

37.

What is the difference between List and Set in Java?

a)

The main difference is that List allows duplicates and maintains order, while Set does not allow duplicates and does not maintain order.

b)

List and Set are the same in terms of functionality and performance.

c)

List does not allow duplicates and maintains order, while Set allows duplicates and does not maintain order.

d)

Both List and Set allow duplicates but List maintains order while Set does not.

38.

How does the HashMap work in Java?

a)

A HashMap stores data in a linear array format.

b)

A HashMap automatically sorts the keys in ascending order.

c)

A HashMap requires keys to be unique but allows duplicate values.

d)

A HashMap in Java uses a hash table to store key-value pairs, allowing for efficient data retrieval.

39.

What is the purpose of the Iterator interface?

a)

To define a method for sorting collections

b)

To create new collection types

c)

The purpose of the Iterator interface is to provide a standard way to traverse and manipulate collections of objects.

d)

To enforce data encapsulation in collections

40.

Explain the concept of multithreading in Java.

a)

Multithreading in Java refers to the use of multiple processes instead of threads.

b)

Multithreading in Java is the execution of a single thread to enhance performance.

c)

Multithreading in Java is a method to run applications sequentially without any concurrency.

d)

Multithreading in Java is the concurrent execution of two or more threads to maximize CPU utilization and improve application performance.

41.

What is the difference between a thread and a process?

a)

A thread is a standalone execution unit with its own memory, while a process shares memory with other threads.

b)

A process is an independent execution unit with its own memory, while a thread is a lightweight execution unit that shares memory with other threads in the same process.

c)

Threads and processes are identical in terms of memory usage and execution.

d)

A process is a lightweight execution unit that shares memory, while a thread is a heavy execution unit with its own memory.

42.

How do you create a thread in Java?

a)

You can create a thread by extending the Thread class or implementing the Runnable interface.

b)

Threads can only be created using the synchronized keyword.

c)

You must use the ExecutorService interface to create a thread.

d)

You can create a thread by using the ThreadPoolExecutor class.

43.

What is the purpose of the synchronized keyword?

a)

To ensure that only one thread can access a block of code or an object at a time.

b)

To automatically manage memory allocation for threads.

c)

To improve the performance of multithreaded applications.

d)

To allow multiple threads to access a block of code simultaneously.

44.

What are the potential issues with multithreading?

a)

Increased memory efficiency

b)

Faster execution time

c)

Potential issues with multithreading include race conditions, deadlocks, thread contention, and increased debugging complexity.

d)

Simplified code structure

45.

Explain the concept of deadlock in Java.

a)

Deadlock occurs when a thread completes its execution without releasing resources.

b)

Deadlock is a method for synchronizing threads in Java.

c)

Deadlock happens when threads run in parallel without any resource contention.

d)

Deadlock is a situation in Java where two or more threads are unable to proceed because each is waiting for the other to release a resource.

46.

What is the mechanism to read/write data (bytes or characters)?

a)

I/O Streams

b)

File handling

c)

Network communication

d)

Data storage

47.

What is the purpose of capturing user input via console?

a)

File handling

b)

Interactive CLI applications

c)

Logging

d)

Data storage

48.

What is the definition of displaying output to the console?

a)

Logging

b)

User feedback

c)

File handling

d)

Data storage

49.

What is the character-based output stream used for writing formatted text to files?

a)

PrintWriter Class

b)

BufferedReader

c)

FileInputStream

d)

Scanner

50.

What is the definition of file I/O using Reader/Writer classes?

a)

Reading and Writing Files

b)

File handling

c)

Data storage

d)

Logging

51.

What are Java programs embedded in browsers called?

a)

Applets

b)

Classes

c)

Methods

d)

Interfaces

52.

What is the type-checking operator in Java?

a)

instanceof Keyword

b)

stricƞp Keyword

c)

native Methods

d)

String Operations

53.

What enforces IEEE 754 floating-point standard?

a)

stricƞp Keyword

b)

instanceof Keyword

c)

native Methods

d)

String Construction

54.

What are methods implemented in non-Java languages called?

a)

native Methods

b)

Java Methods

c)

String Operations

d)

Applet Methods

55.

What is the process of creating string objects?

a)

String Construction

b)

String Operations

c)

String Comparison

d)

String Buffer

56.

What are built-in string methods used for?

a)

Formatting, parsing, transformation

b)

Data storage

c)

String comparison

d)

String construction

57.

What is the process of accessing characters by index?

a)

Character Extraction

b)

String Comparison

c)

String Operations

d)

String Construction

58.

What is the method for comparing string values?

a)

String Comparison

b)

String Extraction

c)

String Operations

d)

String Construction

59.

What is the process of finding substrings or characters?

a)

Searching a String

b)

String Comparison

c)

String Operations

d)

String Construction

60.

What is the process of creating transformed strings?

a)

Modifying a String

b)

String Comparison

c)

String Operations

d)

String Construction

61.

What is the mutable string class that is thread-safe?

a)

StringBuffer

b)

StringBuilder

c)

String

d)

String Operations

62.

What is the root interface for data structures?

a)

Collection Interface

b)

List Interface

c)

Map Interface

d)

Set Interface

63.

What are implementations like ArrayList and HashSet used for?

a)

Collection Classes

b)

Data Structures

c)

Interfaces

d)

Abstract Classes

64.

What are fixed-size containers of same-type elements called?

a)

Arrays

b)

Collections

c)

Lists

d)

Sets

65.

What is the interface for custom sorting logic?

a)

Comparators

b)

Collections

c)

Arrays

d)

Lists

66.

Which of these cannot be used for a variable name in Java?

a)

identifier & keyword

b)

identifier

c)

keyword

d)

none of the mentioned

67.

Which component is used to compile, debug and execute the java programs?

a)

JRE

b)

JIT

c)

JDK

d)

JVM

68.

Which of the following is not an OOPS concept in Java?

a)

Polymorphism

b)

Compilation

c)

Inheritance

d)

Encapsulation

69.

Which of these are selection statements in Java?

a)

break

b)

continue

c)

for()

d)

if()

70.

What is the value stored in x in following lines of code?

int x, y, z;

 x = 0;

 y = 1;

 x = y = z = 8;

a)

1

b)

9

c)

8

d)

0

71.

Evaluate the following Java expression, if x=3, y=5, and z=10:

++z + y - y + z + x++

a)

24

b)

23

c)

20

d)

25

72.

Which of the following for loop declaration is not valid?

a)

for ( int i = 99; i >= 0; i / 9 )

b)

for ( int i = 7; i <= 77; i += 7 )

c)

for ( int i = 20; i >= 2; - -i )

d)

for ( int i = 2; i <= 20; i = 2* i )

73.

What does JVM stands for?

a)

Java Variable Machine

b)

Java Virtual Machine

c)

Java Virtual Mechanism

d)

None of the above

74.

What are the main Distribution types of Java Software?

a)

Java SE (Java Standard Edition)

b)

Java EE (Java Enterprise Edition)

c)

Java ME (Java Micro Edition)

d)

All the above

75.

What is JVM ?

a)

JVM is the confined memory area

b)

All java programs run inside JVM memory

c)

JVM provides security to the computer by giving controlled access to Files and Memory on a computer

d)

All the above

76.

What are the values of var1 and var2 when the code finishes executing?

a)

var1 = 1, var2 = 1

b)

var1 = 2 , var2 = 0

c)

var1 = 3, var2 = -1

d)

var1 = 0, var2 = 2

e)

The loop will cause a run-time error for division by zero

77.

What are the values of x and y when the code finishes executing?

a)

x = 5, y = 2

b)

x = 2, y = 5

c)

x = 3, y = 4

d)

x = 4, y = 3

e)

Infinite Loop

78.

How many stars are printed?

a)

7

b)

3

c)

4

d)

5

e)

Infinite Loop

79.

In total, how many times is the inner loop executed?

a)

5

b)

10

c)

15

d)

50

e)

Infinite Loop

80.

How many times does the loop print a *

a)

40

b)

20

c)

24

d)

30

e)

Infinite Loop

81.

What does the following code print?

a)

A rectangle of 8 rows with 5 stars per row

b)

A rectangle of 8 rows with 4 stars per row

c)

A rectangle of 6 rows with 5 stars per row

d)

A rectangle of 6 rows with 4 stars per row

e)

Infinite Looo

82.

What does the following code print?

a)

A rectangle of 9 rows with 5 stars per row

b)

A rectangle of 6 rows with 6 stars per row

c)

A rectangle of 7 rows with 5 stars per row

d)

A rectangle of 7 rows with 6 stars per row

e)

Infinite Loop

83.

How many times is "HI!" printed?

a)

15

b)

12

c)

10

d)

8

e)

Infinite Loop

84.

What does the following code print?

a)

5 6 7 8 9

b)

4 5 6 7 8 9 10 11 12

c)

3 5 7 9 11

d)

3 4 5 6 7 8 9 10 11 12

85.

How many times does the following method print a *?

a)

9

b)

6

c)

7

d)

10

86.

What does the following code segment print?

a)

5 4 3 2 1

b)

-5 -4 -3 -2 -1

c)

-4 -3 -2 -1 0

87.

How many times does the code print a * ?

a)

7

b)

8

c)

12

d)

13

88.

How many times does this print a * ?

a)

4

b)

5

c)

6

d)

7

89.

How many times does this code print at * ?

a)

5

b)

6

c)

7

d)

8

90.

What does the code print?

a)

1 2 3 4

b)

1 2 3 4 5

c)

0 1 2 3 4

d)

0 1 2 3 4 5

91.

How many stars are printed?

a)

10

b)

5

c)

25

d)

50

92.

What is printed when the code segment is executed?

a)

0 2 4 6 8 10 12 14 16 18

b)

0 6 12 18

c)

1 4 7 10 13 16 19

d)

4 10 16

93.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
94.

What is the first index of an array?

a)

1

b)

0

c)

2

d)

3

95.

For the array:

int stats[3];

What is the range of the index?

a)

0 to 3

b)

0 to 2

c)

1 to 3

d)

0 to 4

96.

int [] nums = {2, 3, 5, 8, 9, 11};

How would you access the fourth element in nums?

a)

nums[4]

b)

nums[3]

c)

nums(4)

d)

nums(3)

97.
Which of the following statements outputs the fifth value in the quizzes array?
a)
System.out.println(quizzes[5]);
b)
quizzes[4];
c)
quizzes[5];
d)
System.out.println(quizzes[4]);
98.
Index values of an array range from ______________.
a)
0 to length – 1
b)
1 to length
c)
0 to length
d)
0 to length + 1
99.
Create an array of 12 strings called months.
a)
String[] months = new String[12];
b)
String months = new String[12];
c)
String[] months = new String[];
d)
String[12] months = new String[];
100.
What is the correct way to create an array with these three numbers: 12  8  15
a)
int[] = {12, 8, 15};
b)
int[] nums = {12  8  15};
c)
int[] nums = {12, 8, 15}
d)
int[] nums = {12, 8, 15};