Courseiva
Knowledge + Practice
CertificationsVendorsCareer RoadmapsLabs & ToolsStudy GuidesGlossaryPractice Questions
C
Courseiva

Free IT certification practice questions with explained answers for CCNA, CompTIA, AWS, Azure, Google Cloud, and more.

Certification Practice Questions

CCNA practice questionsSecurity+ SY0-701 practice questionsAWS SAA-C03 practice questionsAZ-104 practice questionsAZ-900 practice questionsCLF-C02 practice questionsA+ Core 1 practice questionsGoogle Cloud ACE practice questionsCySA+ CS0-003 practice questionsNetwork+ N10-009 practice questions
View all certifications →

Product

CertificationsCertification PathsExam TopicsPractice TestsExam Dumps vs Practice TestsStudy HubComparisons

Company

AboutContactEditorial PolicyQuestion Writing PolicyTrust Center

Legal

Privacy PolicyTerms of Service

Courseiva is a free IT certification practice platform offering original exam-style practice questions, detailed explanations, topic-based practice, mock exams, readiness tracking, and study analytics for Cisco, CompTIA, Microsoft, AWS, and other technology certifications.

© 2026 Courseiva. Courseiva is operated by JTNetSolutions Ltd. All rights reserved.

Courseiva is an independent certification practice platform and is not affiliated with, endorsed by, or sponsored by Cisco, Microsoft, AWS, CompTIA, Google, ISC2, ISACA, or any other certification vendor. Vendor names and certification marks are used only to identify the exams learners are preparing for.

← Controlling Program Flow practice sets

1Z0-829 Controlling Program Flow • Complete Question Bank

1Z0-829 Controlling Program Flow — All Questions With Answers

Complete 1Z0-829 Controlling Program Flow question bank — all 0 questions with answers and detailed explanations.

70
Questions
Free
No signup
Certifications/1Z0-829/Practice Test/Controlling Program Flow/All Questions
Question 1mediummultiple choice
Read the full Controlling Program Flow explanation →

A developer writes code to iterate over a list of strings and print each element. The code uses an enhanced for loop. Which statement is true about the enhanced for loop?

Question 2easymultiple choice
Read the full Controlling Program Flow explanation →

Given the code snippet:

int x = 10;
if (x > 5) {

System.out.print("A");

} else if (x > 7) {

System.out.print("B");

} else {

System.out.print("C");

}

What is the output?

Question 3hardmultiple choice
Read the full Controlling Program Flow explanation →

A method contains a try-with-resources statement that uses two resources: a FileInputStream and a BufferedInputStream. The FileInputStream constructor throws a FileNotFoundException. Which statement about resource closing is true?

Question 4mediummulti select
Read the full Controlling Program Flow explanation →

Which TWO statements are true about the switch statement in Java?

Question 5hardmulti select
Read the full Controlling Program Flow explanation →

Which THREE statements are true about loops in Java?

Question 6hardmultiple choice
Read the full Controlling Program Flow explanation →

You are developing a high-frequency trading application that processes a stream of market data ticks. Each tick is represented by a Tick object with fields: long timestamp, String symbol, double price, int volume. Ticks arrive in real-time and must be processed in order. A bug is reported: the application occasionally processes a tick out of order, causing incorrect trade decisions. The processing logic uses a while loop to read from a blocking queue and process each tick. The code is:

BlockingQueue<Tick> queue = new LinkedBlockingQueue<>();

while (true) {

Tick tick = queue.take(); process(tick);

}

After investigation, you find that the queue is fed by multiple producer threads that sometimes reorder ticks due to network delays. Which course of action best ensures ticks are processed in the correct chronological order without sacrificing throughput?

Question 7easymultiple choice
Read the full Controlling Program Flow explanation →

Which loop construct guarantees that the body executes at least once?

Question 8hardmultiple choice
Read the full Controlling Program Flow explanation →

What is the output of the program?

Exhibit

Refer to the exhibit.

public class LoopTest {
    public static void main(String[] args) {
        outer:
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i + j > 3) {
                    break outer;
                }
                System.out.print(i + j + " ");
            }
        }
    }
}
Question 9mediummulti select
Read the full Controlling Program Flow explanation →

Which TWO statements about the switch statement in Java are correct?

Question 10easymultiple choice
Read the full Controlling Program Flow explanation →

A Java application processes a list of orders. Each order has a status: NEW, PROCESSING, SHIPPED, or DELIVERED. The code must print a message based on the status: - If NEW: "Order received" - If PROCESSING: "Order in progress" - If SHIPPED: "Order shipped" - If DELIVERED: "Order delivered" - For any other status: "Unknown status"

The developer writes the following code using a switch expression:

String message = switch (status) { case NEW -> "Order received"; case PROCESSING -> "Order in progress"; case SHIPPED -> "Order shipped"; case DELIVERED -> "Order delivered"; default -> "Unknown status";

};

System.out.println(message);

What is the correct course of action to ensure the code compiles and runs correctly?

Question 11easymulti select
Read the full Controlling Program Flow explanation →

Which TWO statements about the switch statement in Java are true?

Question 12hardmultiple choice
Read the full NAT/PAT explanation →

A Java developer is writing a batch processing application that reads records from a database and processes them. The processing must continue even if some records cause exceptions (e.g., data conversion errors). However, the application must log each failed record and its error, then continue with the next record. The developer uses a for loop to iterate over a list of records. Inside the loop, a try-catch block wraps the processing logic. After implementing, the developer notices that when an exception occurs, the loop terminates prematurely instead of continuing. The code structure is:

List<Record> records = fetchRecords();

for (Record rec : records) {

try { process(rec);

} catch (Exception e) {

log.error("Failed to process: " + rec.getId(), e);

}
}

What is the most likely reason for the premature termination?

Question 13mediumdrag order
Read the full Controlling Program Flow explanation →

Order the steps to properly handle resources using try-with-resources in Java.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 14mediumdrag order
Read the full Controlling Program Flow explanation →

Order the steps to handle checked exceptions in a method that throws IOException.

Drag steps to the numbered slots on the right, or tap a step then tap a slot.

Steps
Order
1Step 1
2Step 2
3Step 3
4Step 4
5Step 5
Question 15mediummatching
Read the full Controlling Program Flow explanation →

Match each Java module directive to its description.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Makes a package accessible to other modules

Specifies a dependency on another module

Allows reflective access to a package at runtime

Declares a service implementation

Specifies a service interface consumed by the module

Question 16mediummatching
Read the full Controlling Program Flow explanation →

Match each I/O stream class to its description.

Drag a concept onto its matching description — or click a concept then click the description.

Concepts
Matches

Reads text from a character-input stream, buffering characters

Reads raw bytes from a file

Writes primitive types and Java objects to an OutputStream

Prints formatted representations of objects to a text-output stream

Reads primitive Java data types from an underlying input stream

Question 17mediummultiple choice
Read the full Controlling Program Flow explanation →

A developer writes a method that processes a grade and returns a message using a switch expression. The code is:

```java

public static String getMessage(int grade) {
    return switch (grade) {

case 90, 80 -> "Excellent"; case 70, 60 -> "Good"; case 50 -> "Pass"; default -> "Fail";

};
}

```

Which statement is correct about this code?

Question 18hardmultiple choice
Read the full Controlling Program Flow explanation →

Given the following code snippet:

```java outer:

for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        if (i == 1 && j == 1) {

break outer;

}

System.out.print(i + "-" + j + " ");

}
}

```

What is the output?

Question 19easymultiple choice
Read the full Controlling Program Flow explanation →

Consider the following code:

```java boolean a = true, b = false, c = false;

if (a && b || c) {

System.out.println("True");

} else {

System.out.println("False");

}

```

What is the output?

Question 20mediummultiple choice
Read the full Controlling Program Flow explanation →

A method uses an enhanced for loop to iterate over a list of strings and prints each string. The code is:

```java List<String> list = List.of("A", "B", "C");

for (String s : list) {
    if (s.equals("B")) {

break;

}

System.out.print(s);

}

```

What is the result?

Question 21hardmultiple choice
Read the full Controlling Program Flow explanation →

Given the following switch statement:

```java

int x = 2;

switch (x) { default: System.out.print("default "); case 1: System.out.print("1 "); case 2: System.out.print("2 "); case 3: System.out.print("3 "); break; case 4: System.out.print("4 ");

}

```

What is the output?

Question 22easymultiple choice
Read the full Controlling Program Flow explanation →

What is the output of the following code?

```java

int i = 5;
while (i > 0) {

System.out.print(i + " "); i--;

}

```

Question 23mediummultiple choice
Read the full Controlling Program Flow explanation →

Consider the following do-while loop:

```java

int x = 10;

do { x--;

} while (x < 10);

System.out.println(x); ```

What is printed?

Question 24hardmultiple choice
Read the full Controlling Program Flow explanation →

Given the following code:

```java outer:

for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
        if (i == 1) {

continue outer;

}

System.out.print(i + " " + j + " ");

}
}

```

What is the output?

Question 25easymultiple choice
Read the full Controlling Program Flow explanation →

Which of the following correctly uses a switch expression with multiple constants per case?

```java

int day = 2;

String result = switch (day) { case 1, 2, 3 -> "Weekday"; case 6, 7 -> "Weekend"; default -> "Invalid";

};

```

What is the value of result?

Question 26mediummulti select
Read the full Controlling Program Flow explanation →

Which TWO correctly describe the behavior of the following code?

```java

int x = 10;

switch (x) { case 10: System.out.print("ten "); default: System.out.print("default "); case 20: System.out.print("twenty ");

}

```

Question 27hardmulti select
Read the full Controlling Program Flow explanation →

Which THREE statements are true about the enhanced for loop in Java?

Question 28easymulti select
Read the full Controlling Program Flow explanation →

Which TWO of the following are valid forms of the switch statement/expression in Java?

Question 29mediummultiple choice
Read the full Controlling Program Flow explanation →

What is the output when this code is executed?

Exhibit

Refer to the exhibit.

```java
public class SwitchTest {
    public static void main(String[] args) {
        int value = 2;
        switch (value) {
            case 1:
                System.out.print("One ");
            case 2:
                System.out.print("Two ");
            case 3:
                System.out.print("Three ");
                break;
            default:
                System.out.print("Default ");
        }
    }
}
```
Question 30hardmultiple choice
Read the full Controlling Program Flow explanation →

Which change fixes the exception?

Exhibit

Refer to the exhibit.

```
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3
    at LoopExample.main(LoopExample.java:5)
```

Source code of LoopExample.java:

```java
1: public class LoopExample {
2:     public static void main(String[] args) {
3:         int[] arr = {1,2,3};
4:         for (int i = 0; i <= arr.length; i++) {
5:             System.out.println(arr[i]);
6:         }
7:     }
8: }
```
Question 31easymultiple choice
Read the full Controlling Program Flow explanation →

What is the likely cause of this compilation error?

Exhibit

Refer to the exhibit.

```
Error: incompatible types: bad type in switch expression
        return switch(day) {
                     ^
  required: int
  found:    String
```
Question 32easymultiple choice
Read the full Controlling Program Flow explanation →

Given: for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(i==1 && j==1) break; } } What is the value of i after the outer loop completes?

Question 33mediummultiple choice
Read the full Controlling Program Flow explanation →

Given: Object obj = "Hello"; String result = switch(obj) { case String s -> "String of length " + s.length(); case Integer i -> "Integer"; default -> "Unknown"; }; What is result?

Question 34hardmultiple choice
Read the full Controlling Program Flow explanation →

Given: outer: for(int i=0; i<3; i++) { for(int j=0; j<3; j++) { if(j==1) continue outer; } } How many times does the innermost loop body execute?

Question 35easymultiple choice
Read the full Controlling Program Flow explanation →

Given: int x=0; do { x++; } while(x<5); How many times does the loop body execute?

Question 36mediummultiple choice
Read the full Controlling Program Flow explanation →

Given: int a=5, b=10; String result = (a > b) ? "greater" : (a < b) ? "less" : "equal"; What is result?

Question 37mediummultiple choice
Read the full Controlling Program Flow explanation →

Given: Object obj = null; String s = switch(obj) { case null -> "null"; case String str -> str; default -> "other"; }; What is the result?

Question 38hardmultiple choice
Read the full Controlling Program Flow explanation →

Given: int i=0; outer: while(i<3) { for(int j=0; j<3; j++) { if(j==1) break outer; } i++; } What is the value of i after the outer loop?

Question 39easymultiple choice
Read the full Controlling Program Flow explanation →

Given: for(int i=0; i<10; i++) { if(i%2==0) continue; System.out.print(i+" "); } What is the output?

Question 40mediummultiple choice
Read the full Controlling Program Flow explanation →

Given: int x=1; switch(x) { case 1: System.out.print("A"); case 2: System.out.print("B"); break; default: System.out.print("C"); } What is printed?

Question 41mediummulti select
Read the full Controlling Program Flow explanation →

Which two statements about the break statement are true?

Question 42mediummulti select
Read the full NAT/PAT explanation →

Which three of the following are valid case values in a traditional switch statement (non-pattern)?

Question 43easymulti select
Read the full Controlling Program Flow explanation →

Which two statements about the do-while loop are true?

Question 44easymultiple choice
Read the full Controlling Program Flow explanation →

A developer is designing a loop to iterate through an array of integers and stop processing when the value -1 is encountered. Which loop construct should be used?

Question 45mediummultiple choice
Read the full Controlling Program Flow explanation →

Which statement is correct about the following switch expression? String result = switch(day) { case MONDAY, TUESDAY -> "weekday"; case WEDNESDAY -> "midweek"; default -> "other"; };

Question 46hardmultiple choice
Read the full Controlling Program Flow explanation →

A developer has a method that contains a try-catch-finally block inside a while loop. The try block throws a checked exception that is caught by the catch block. The catch block throws a new runtime exception. What is the behavior?

Question 47easymulti select
Read the full Controlling Program Flow explanation →

Which two of the following statements are true about the continue statement in a loop?

Question 48mediummulti select
Read the full Controlling Program Flow explanation →

Which two of the following are valid ways to exit a loop in Java?

Question 49hardmulti select
Read the full Controlling Program Flow explanation →

Which three of the following statements about the switch expression in Java 17 are correct?

Question 50easymultiple choice
Read the full Controlling Program Flow explanation →

Refer to the exhibit. The exhibit shows a stack trace from a Java application. Which line in the code caused the NullPointerException?

Exhibit

Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.length()" because "s" is null
    at com.example.Main.main(Main.java:8)
Question 51mediummultiple choice
Read the full Controlling Program Flow explanation →

Refer to the exhibit. The exhibit shows a code snippet. What is the output when the variable day is set to Day.WEDNESDAY?

Exhibit

enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY }
int numLetters = switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> 6;
    case TUESDAY -> 7;
    default -> { int len = day.name().length(); yield len; }
};
System.out.println(numLetters);
Question 52hardmultiple choice
Read the full NAT/PAT explanation →

In a large enterprise application, a concurrent caching system is implemented using a ConcurrentHashMap that is accessed by multiple threads concurrently. The cache performs atomic operations on individual keys, but some operations require updates on multiple keys. To ensure consistency, the code acquires intrinsic locks on the keys using synchronized blocks. Over time, the system has been experiencing intermittent deadlocks. During post-mortem analysis, it was found that thread A holds a lock on key X and is waiting for key Y, while thread B holds a lock on key Y and is waiting for key X. The development team needs to redesign the locking strategy to eliminate these deadlocks while maintaining high throughput and minimizing code changes. They consider the following proposals: replacing ConcurrentHashMap with Collections.synchronizedMap, using a single ReentrantLock for all cache operations, always acquiring locks on keys in a consistent global order, or using a Lock with tryLock and a timeout and releasing all locks if timeout expires. Based on best practices in concurrent programming and considering the requirements to avoid deadlocks and maintain performance, which approach should they choose?

Question 53easymultiple choice
Read the full Controlling Program Flow explanation →

What is the output of the following code snippet? int x = 5; if(x > 0) { System.out.print('A'); } else if(x > 2) { System.out.print('B'); } else { System.out.print('C'); }

Question 54mediummultiple choice
Read the full Controlling Program Flow explanation →

Given nested loops with labels, which statement correctly breaks out of the outer loop?

Question 55hardmultiple choice
Read the full Controlling Program Flow explanation →

A resource is declared in a try-with-resources statement. The try block throws an exception. The close method throws a different exception. What exception is thrown by the try-with-resources statement?

Question 56easymultiple choice
Read the full Controlling Program Flow explanation →

How many times does the following loop execute? int i=0; while(i<5) { System.out.println(i); i++; }

Question 57mediummultiple choice
Read the full Controlling Program Flow explanation →

What is the output of the following code? int i=5; do { System.out.print(i); i--; } while(i>0);

Question 58hardmultiple choice
Read the full Controlling Program Flow explanation →

Given the following switch expression with colon syntax, what is the result when code equals 2? int val = switch(code) { case 1: yield 10; case 2: yield 20; default: yield 30; };

Question 59mediummultiple choice
Read the full Controlling Program Flow explanation →

A developer is implementing a method that processes a collection of objects. The objects are instances of various classes that implement a common interface. The developer wants to use a switch expression to perform different actions based on the runtime type of each object. Which approach is correct?

Question 60hardmultiple choice
Read the full Controlling Program Flow explanation →

A developer wrote a method that uses a for-each loop to iterate over a list of strings and remove elements that match a certain condition. However, the method throws a ConcurrentModificationException at runtime. What is the most likely cause?

Question 61easymulti select
Read the full Controlling Program Flow explanation →

Which TWO statements about the break and continue statements in Java are correct?

Question 62easymultiple choice
Read the full Controlling Program Flow explanation →

A junior developer writes a method that uses a switch statement to handle different types of user input. The input is an integer representing an operation code. The developer uses a traditional switch statement with break statements. However, when operation code 2 is entered, the program also executes the code for operation 3. What is the most likely cause?

Question 63mediummultiple choice
Read the full Controlling Program Flow explanation →

A developer is implementing a batch processing application that reads records from a list and processes them. The method uses a for loop with an index variable. Inside the loop, if a record is null, the developer wants to skip that iteration and continue with the next index. The developer writes: for (int i = 0; i < records.size(); i++) { if (records.get(i) == null) continue; process(records.get(i)); updateCounter(); } However, the counter is not updated correctly. The developer expects the counter to reflect the number of processed (non-null) records. What is the problem?

Question 64hardmultiple choice
Read the full NAT/PAT explanation →

A financial trading system uses a Java application to process market data. The core algorithm uses nested loops to compare price arrays. The developer uses a labeled continue statement to skip certain combinations. After a code review, the team suspects the algorithm has a bug that causes incorrect results. The developer writes a unit test and discovers that the labeled continue sometimes skips more iterations than intended. The code is: outer: for (int i = 0; i < prices1.length; i++) { for (int j = 0; j < prices2.length; j++) { if (prices1[i] < prices2[j]) continue outer; // process combination } } The developer intended that if any price in prices1 is less than a price in prices2, the entire row (i) should be skipped. However, the algorithm skips rows even when the condition is not met for all j. What is the most likely cause?

Question 65mediummultiple choice
Read the full NAT/PAT explanation →

A developer writes a method that uses a for loop to iterate over a list of strings and remove elements that match a specific pattern using the list's remove(int index) method. The developer uses an index variable that increments normally. However, after running the method, some elements that should have been removed are still present, and some elements are skipped. The list initially contains [A, B, C, D, E] and the developer expects to remove B and D. After the loop, the list is [A, C, E] as expected? Actually, the developer observes that after the loop, the list contains [A, C, D, E] (D was not removed). What is the most likely cause?

Question 66easymultiple choice
Read the full Controlling Program Flow explanation →

A developer needs to iterate over a List<String> and remove elements that are null. Which approach guarantees correct behavior without throwing a ConcurrentModificationException?

Question 67mediummultiple choice
Read the full Controlling Program Flow explanation →

Given an enum Direction { NORTH, SOUTH, EAST, WEST } and a variable d of type Direction, which code snippet correctly uses a switch expression to map each direction to an abbreviation (N, S, E, W) without using a default branch?

Question 68hardmulti select
Read the full Controlling Program Flow explanation →

Which two statements about the enhanced for-each loop in Java are true? (Choose two.)

Question 69mediummultiple choice
Read the full Controlling Program Flow explanation →

Refer to the exhibit. What is the output when the program is executed?

Exhibit

Refer to the exhibit.
```java
public class LoopExample {
    public static void main(String[] args) {
        outer:
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (i == 1 && j == 2) {
                    break outer;
                }
                System.out.print(i + " " + j + " ");
            }
        }
    }
}
```
Question 70hardmultiple choice
Read the full Controlling Program Flow explanation →

A financial application processes a daily batch of 10 million transactions. Each transaction is an object with fields: id, amount, and status (an enum: PENDING, APPROVED, REJECTED). The requirement is to find the first APPROVED transaction with amount greater than 1000. The current implementation uses a while loop with a nested if-else structure that checks each transaction sequentially. The loop also logs each transaction status, which involves a moderately expensive file write operation. Performance analysis shows the method is a bottleneck, often taking over 12 seconds. The development team is considering refactoring. Which course of action will most effectively reduce execution time while maintaining the requirement?

Practice tests

Scored 10-question sessions with instant feedback and explanations.

1Z0-829 Practice Test 1 — 10 Questions→1Z0-829 Practice Test 2 — 10 Questions→1Z0-829 Practice Test 3 — 10 Questions→1Z0-829 Practice Test 4 — 10 Questions→1Z0-829 Practice Test 5 — 10 Questions→1Z0-829 Practice Exam 1 — 20 Questions→1Z0-829 Practice Exam 2 — 20 Questions→1Z0-829 Practice Exam 3 — 20 Questions→1Z0-829 Practice Exam 4 — 20 Questions→Free 1Z0-829 Practice Test 1 — 30 Questions→Free 1Z0-829 Practice Test 2 — 30 Questions→Free 1Z0-829 Practice Test 3 — 30 Questions→1Z0-829 Practice Questions 1 — 50 Questions→1Z0-829 Practice Questions 2 — 50 Questions→1Z0-829 Exam Simulation 1 — 100 Questions→

Practice by domain

Each domain maps to a weighted exam section. Focus on the domain where you are weakest.

Handling Date, Time, Text, Numeric and Boolean ValuesControlling Program FlowUtilizing Java Object-Oriented ApproachHandling ExceptionsWorking with Arrays and CollectionsWorking with Streams and Lambda ExpressionsJava Platform Overview and PackagingJava I/O API and Securing Applications

Practice by scenario

Filter questions by type — troubleshooting, exhibit, drag-and-drop, PBQ, ACLs, OSPF, and more.

Browse scenarios→

Continue studying

All Controlling Program Flow setsAll Controlling Program Flow questions1Z0-829 Practice Hub