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?
Q2 of 20
Which statement correctly describes Java's "write once, run anywhere" portability?
Q3 of 20
Which main method declaration allows the command java App to start class App on Java 17?
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?
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); } } ```
Q7 of 20
What does this code print? ```java int value = 130; byte b = (byte) value; System.out.println(b); ```
Q8 of 20
What does this code print? ```java int max = Integer.MAX_VALUE; max++; System.out.println(max); ```
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); ```
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?
Q11 of 20
What does this code print? ```java int x = 5; int y = x++ + ++x; System.out.println(x + " " + y); ```
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)); ```
Q13 of 20
What does this statement print? System.out.println(1 + 2 + "3" + 4 + 5);
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?
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"); } ```
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); ```
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?
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)); ```
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 + " "); } } ```
Need to review the concepts?
Read Free Study Notes →Read Java Programming Study Notes
Review complete topic notes, syntax guides, code examples, and summary tables.