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!

Q1

Q1 Which of these is not a feature of Java?

A

Object-oriented

B

Platform-independent

C

Compiled

D

Interpreted language

Q2

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

A

JDK

B

JVM

C

JRE

D

JIT

Q3

Q3 What is the purpose of the PATH environment variable in Java?

A

To locate Java libraries

B

To store Java bytecode

C

To locate the Java compiler

D

To optimize Java code

Q4

Q4 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

Q5

Q5 In Java, how should class names be written?

A

camelCase

B

snake_case

C

PascalCase

D

kebab-case

Q6

Q6 Which of these is a single-line comment in Java?

A

/* comment */

B

// comment

C

<!-- comment -->

D

% comment

Q7

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

A

int

B

double

C

long

D

byte

Q8

Q8 What is the default value of a boolean variable in Java?

A

true

B

false

C

0

D

null

Q9

Q9 What is the result of this operation in Java:
(int)(7.9)?

A

7

B

7.9

C

8

D

Syntax Error

Q10

Q10 Which keyword is used to define a constant variable in Java?

A

final

B

static

C

const

D

immutable

Q11

Q11 What is the range of the short data type in Java?

A

-32768 to 32767

B

-128 to 127

C

-2147483648 to 2147483647

D

0 to 65535

Q12

Q12 What will be the output of the following code snippet:
int a = 10;
int b = 20;
System.out.println(a + b);

A

10

B

20

C

30

D

Error

Q13

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

A

true

B

false

C

Error

D

null

Q14

Q14 What does the following Java code print?
int x = 5;
int y = x++;
System.out.println(y);

A

5

B

6

C

Syntax Error

D

None of the above

Q15

Q15 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

Q16

Q16 Evaluate this pseudocode:

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

A

7

B

12

C

Error

D

None of the above

Q17

Q17 Determine the output:
SET num = 8
IF num MOD 2 = 0
THEN PRINT "Even"
ELSE
PRINT "Odd"

A

Even

B

Odd

C

Error

D

No output

Q18

Q18 Identify the error in this code:
int[] nums = new int[2]; nums[0] = 1; nums[1] = 2; nums[2] = 3;

A

Array index out of bounds

B

Incorrect array declaration

C

No error

D

Syntax error

Q19

Q19 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

Q20

Q20 Which control structure is used to execute a block of code multiple times?

A

if

B

switch-case

C

for

D

try-catch

Q21

Q21 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

Q22

Q22 In a 'switch-case' statement, what is the role of the 'break' keyword?

A

To pause the execution

B

To terminate the case block

C

To skip to the next case

D

To repeat the case block

Q23

Q23 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

Q24

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

A

break

B

continue

C

exit

D

stop

Q25

Q25 What will the following loop print?
for(int i = 0;
i < 3;
i++){
System.out.println(i);
}

A

0 1 2

B

1 2 3

C

0 1 2 3

D

None

Q26

Q26 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

Q27

Q27 What will this pseudocode output?

SET count = 5 DO PRINT count COUNTDOWN count

A

5 4 3 2 1

B

5

C

1 2 3 4 5

D

None

Q28

Q28 Analyze this pseudocode:

SET num = 0 WHILE num <= 5 IF num MOD 2 = 0 THEN PRINT num END IF INCREMENT num

A

0 2 4

B

0 1 2 3 4 5

C

2 4

D

0 2 4 6

Q29

Q29 Identify the error in this code:
for(int i=0;
i<=5;
i++) {
System.out.println(i);
}
System.out.println(i);

A

Syntax error outside loop

B

No error

C

Variable i not accessible outside loop

D

Infinite loop

Q30

Q30 Spot the mistake:
int counter = 0;
while(counter < 5){
counter++;
}
System.out.println("Count: " + counter);

A

Loop never terminates

B

Counter not incremented

C

No error

D

Print statement incorrect

ad verticalad vertical
ad