CDCDAC Prep
PGCP-BDACMCE (CCE Modules Exam)•20 Questions

Java Programming Practice MCQs

Topic Covered in this Question Set

Java Platform, JVM, JDK, Types, Operators and Control Flow

Click on an option to check your answer immediately. Full solution & explanation provided for every question.

Interactive Practice Mode

Java Programming Free MCQs

Select an option to test your knowledge with real exam questions and instant explanations.

Total20
Correct0
Wrong0
Progress: 0 of 20 answered0% Accuracy
Q1 of 20

A training lab's PCs only need to run a packaged Java application, while each developer must also compile and debug code. What should be installed?

Open topic in App →
Q2 of 20

Which statement correctly describes Java's "write once, run anywhere" portability?

Open topic in App →
Q3 of 20

Which main method declaration allows the command java App to start class App on Java 17?

Open topic in App →
Q4 of 20

A program prints a wrong total. You want to stop at the start of main, step line by line and print local variables using a JDK command-line tool. Which tool is designed for this?

Open topic in App →
Q5 of 20

Which declaration compiles without adding a cast or a literal suffix?

Open topic in App →
Q6 of 20

What happens when this class is compiled and run with no command-line arguments? ```java public class Total { public static void main(String[] args) { int total; if (args.length > 0) { total = 1; } System.out.println(total); } } ```

Open topic in App →
Q7 of 20

What does this code print? ```java int value = 130; byte b = (byte) value; System.out.println(b); ```

Open topic in App →
Q8 of 20

What does this code print? ```java int max = Integer.MAX_VALUE; max++; System.out.println(max); ```

Open topic in App →
Q9 of 20

A student computes the average of two marks. What is printed? ```java int m1 = 7, m2 = 8; double avg = (m1 + m2) / 2; System.out.println(avg); ```

Open topic in App →
Q10 of 20

In the calculator lab, calculate takes double operands. If the division-by-zero check is removed, what does left / right produce for left = 10 and right = 0?

Open topic in App →
Q11 of 20

What does this code print? ```java int x = 5; int y = x++ + ++x; System.out.println(x + " " + y); ```

Open topic in App →
Q12 of 20

What do the two println statements print? ```java char c = 'A'; System.out.println(c + 1); System.out.println((char) (c + 1)); ```

Open topic in App →
Q13 of 20

What does this statement print? System.out.println(1 + 2 + "3" + 4 + 5);

Open topic in App →
Q14 of 20

Given byte b = 10; which statement compiles?

Open topic in App →
Q15 of 20

A method must print name only if it is not null and not empty. Which condition never throws NullPointerException when name is null?

Open topic in App →
Q16 of 20

What does this code print? ```java int day = 2; switch (day) { case 1: System.out.print("Mon "); case 2: System.out.print("Tue "); case 3: System.out.print("Wed "); break; default: System.out.print("Other"); } ```

Open topic in App →
Q17 of 20

What does this Java 17 code print? ```java int code = 3; String size = switch (code) { case 1, 2 -> "small"; case 3, 4 -> { String s = "medium"; yield s.toUpperCase(); } default -> "large"; }; System.out.println(size); ```

Open topic in App →
Q18 of 20

A calculator must show its menu and perform one calculation, then repeat only while the user types y. Which loop expresses this most directly?

Open topic in App →
Q19 of 20

What does this code print (java.util.Arrays is imported)? ```java int[] values = {1, 2, 3}; for (int v : values) { v = v * 10; } System.out.println(Arrays.toString(values)); ```

Open topic in App →
Q20 of 20

What does this code print? ```java outer: for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { if (j == 2) continue outer; if (i == 3) break outer; System.out.print(i + "" + j + " "); } } ```

Open topic in App →
Need to review the concepts?

Read Java Programming Study Notes

Review complete topic notes, syntax guides, code examples, and summary tables.

Read Free Study Notes →