an HCL GUVI product

java programming banner

Java Programming Multiple Choice Questions (MCQs) and Answers

Master Java Programming with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of Java Programming. Begin your placement preparation journey now!

Q61

Q61 What is the String Constant Pool in Java?

A

A collection of all String literals

B

A memory area for constant String storage

C

A pool for reusable String objects

D

All of the above

Q62

Q62 What is the result of concatenating strings using the '+' operator in Java?

A

A new String object is created every time

B

The original string is modified

C

No new objects are created

D

A StringBuilder object is used internally

Q63

Q63 Analyze the output of this code snippet:
StringBuffer buffer = new StringBuffer("Java");
buffer.reverse();
System.out.println(buffer);

A

avaJ

B

Java

C

A runtime error occurs

D

None of the above

Q64

Q64 What will this pseudocode output?
SET str = "Java" SET builder = StringBuilder(str) builder.append("Script") PRINT builder

A

JavaScript

B

Java

C

JavaScriptJava

D

Error

Q65

Q65 Analyze this pseudocode:

CREATE buffer = StringBuffer("Java") CALL buffer.reverse() PRINT buffer

A

avaJ

B

Java

C

A runtime error occurs

D

None of the above

Q66

Q66 What will be the result of this pseudocode?

SET str1 = "Java" SET str2 = "Java" IF str1 EQUALS str2 PRINT "Equal" ELSE PRINT "Not Equal"

A

Equal

B

Not Equal

C

Error

D

None

Q67

Q67 Identify the issue in this code snippet:
StringBuilder sb = "Java"; sb.append("Script");

A

Incorrect initialization of StringBuilder

B

No issue

C

append method used incorrectly

D

Syntax error

Q68

Q68 Spot the mistake:
StringBuffer buffer = new StringBuffer("Java");
buffer.setLength(2);
System.out.println(buffer);

A

It will print "Ja"

B

The setLength method is used incorrectly

C

No error

D

Syntax error

Q69

Q69 Find the error in this Java code:
String s1 = new String("Java");
String s2 = new String("Java");
System.out.println(s1 == s2);

A

s1 and s2 refer to the same object

B

No error

C

s1 and s2 refer to different objects

D

Syntax error

Q70

Q70 What will this pseudocode output?

CREATE thread START thread PRINT "Thread started" END

A

Thread started

B

An error

C

Nothing

D

Thread started and then an error

Q71

Q71 Analyze this pseudocode:

CREATE thread1, thread2 START thread1 CALL thread1.wait() START thread2 CALL thread2.notify()

A

thread2 starts after thread1 waits

B

thread1 and thread2 run concurrently

C

thread1 waits indefinitely

D

An error occurs

Q72

Q72 Identify the issue in this code snippet:
class MyThread extends Thread {
public void run() {
wait(); }
}

A

Incorrect use of wait()

B

Syntax error

C

No issue

D

Incorrect thread initialization

Q73

Q73 What is a lambda expression in Java?

A

A type of exception

B

A new collection type

C

A concise way to represent an anonymous function

D

A data storage format

Q74

Q74 What is the purpose of the Streams API in Java 8?

A

To handle I/O streams

B

To create a new type of collection

C

To enable functional-style operations on collections

D

To manage threads

Q75

Q75 What are functional interfaces in Java?

A

Interfaces with only static methods

B

Interfaces with multiple abstract methods

C

Interfaces with a single abstract method

D

Interfaces that support lambda expressions only

Q76

Q76 How does the Optional class help in Java?

A

It replaces all null values in a program

B

It is used to avoid NullPointerExceptions

C

It provides a better way of handling multithreading

D

It optimizes memory usage

Q77

Q77 What is the advantage of using method references in Java 8?

A

They make the code run faster

B

They make the code more readable when referring to methods or constructors

C

They replace all lambda expressions

D

They are necessary for functional programming

Q78

Q78 What will this pseudocode output?

CREATE list = [1, 2, 3, 4] CREATE stream = list.stream() FILTER stream WITH (n -> n > 2) PRINT stream

A

[1, 2, 3, 4]

B

[3, 4]

C

[1, 2]

D

Empty list

Q79

Q79 What is the primary purpose of the Locale class in Java?

A

To handle currency conversions

B

To manage different time zones

C

To represent a specific geographical, political, or cultural region

D

To change the layout of graphical components

Q80

Q80 Which component of Java is responsible for running the compiled Java bytecode?

A

JDK

B

JVM

C

JRE

D

JIT

Q81

Q81 Which feature of Java makes it possible to run a Java program on different platforms?

A

Object-Oriented

B

Platform-Independent

C

Syntax

D

Memory Management

Q82

Q82 Which data type would be best for storing a person's age in Java?

A

int

B

double

C

long

D

byte

Q83

Q83 Identify the output of this code:
boolean isJavaFun = true;
System.out.println(!isJavaFun);

A

true

B

false

C

Error

D

null

Q84

Q84 What is the output of this pseudocode?
SET x = 10
IF x > 5
THEN PRINT "Greater"
ELSE PRINT "Lesser"

A

Greater

B

Lesser

C

Error

D

No output

Q85

Q85 Evaluate this pseudocode:

SET a = 3 SET b = 4 PRINT a * b

A

7

B

12

C

Error

D

None of the above

Q86

Q86 Spot the mistake in this code snippet:
int i = 0;
while(i < 10) {
i++;
}
System.out.println(i);

A

Infinite loop

B

Syntax error

C

No error

D

Prints 0

Q87

Q87 What will be the output of the following code snippet:
if(false){
System.out.println("True");
}
else{
System.out.println("False");
}

A

True

B

False

C

Error

D

No Output

Q88

Q88 What is the difference between 'while' and 'do-while' loops in Java?

A

Syntax only

B

The 'do-while' loop executes at least once

C

Execution speed

D

No difference

Q89

Q89 Which keyword is used to exit a loop prematurely in Java?

A

break

B

continue

C

exit

D

stop

Q90

Q90 What is the output of this code?
int x = 1;
while(x < 4){
System.out.println(x); x++;
}

A

1 2 3

B

2 3 4

C

1 2 3 4

D

1