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.

HomeCertifications1Z0-829DomainsControlling Program Flow
1Z0-829Free — No Signup

Controlling Program Flow

Practice 1Z0-829 Controlling Program Flow questions with full explanations on every answer.

77questions

Start practicing

Controlling Program Flow — choose a session length

10 questions~10 min20 questions~20 min30 questions~30 min50 questions~50 min

Free · No account required

1Z0-829 Domains

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 Controlling Program Flow questions

10Q20Q30Q50Q

All 1Z0-829 Controlling Program Flow questions (77)

Start session

Click any question to see the full explanation and answer options, or start a focused practice session above.

1

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?

2

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?

3

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?

4

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

5

Which THREE statements are true about loops in Java?

6

What is the output?

7

What is the output?

8

What is the output?

9

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?

10

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

11

What is the output of the program?

12

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

13

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?

14

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

15

What is the result?

16

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?

17

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

18

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

19

Match each Java module directive to its description.

20

Match each I/O stream class to its description.

21

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?

22

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?

23

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?

24

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?

25

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?

26

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

27

Consider the following do-while loop: ```java int x = 10; do { x--; } while (x < 10); System.out.println(x); ``` What is printed?

28

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?

29

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?

30

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 "); } ```

31

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

32

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

33

What is the output when this code is executed?

34

Which change fixes the exception?

35

What is the likely cause of this compilation error?

36

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?

37

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?

38

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?

39

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

40

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

41

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

42

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?

43

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

44

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?

45

Which two statements about the break statement are true?

46

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

47

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

48

What is the output?

49

What is the output?

50

What is the output?

51

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?

52

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

53

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?

54

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

55

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

56

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

57

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

58

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

59

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?

60

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'); }

61

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

62

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?

63

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

64

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

65

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; };

66

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?

67

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?

68

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

69

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?

70

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?

71

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?

72

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?

73

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

74

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?

75

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

76

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

77

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 all 77 Controlling Program Flow questions

Other 1Z0-829 exam domains

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

Frequently asked questions

What does the Controlling Program Flow domain cover on the 1Z0-829 exam?

The Controlling Program Flow domain covers the key concepts tested in this area of the 1Z0-829 exam blueprint published by Oracle. Courseiva provides free domain-focused practice, mock exams, missed-question review, and readiness tracking across all 1Z0-829 domains — no account required.

How many Controlling Program Flow questions are in the 1Z0-829 question bank?

The Courseiva 1Z0-829 question bank contains 77 questions in the Controlling Program Flow domain. Click any question to see the full explanation and answer breakdown.

What is the best way to practice Controlling Program Flow for 1Z0-829?

Start with a 10-question focused session to identify your baseline accuracy in this domain. Read every explanation — even for questions you answer correctly — to understand the reasoning. Once you score consistently above 80%, move to a 20–30 question session to confirm depth before moving to the next domain.

Can I practice only Controlling Program Flow questions for 1Z0-829?

Yes — the session launcher on this page draws questions exclusively from the Controlling Program Flow domain. Choose 10, 20, 30, or 50 questions for a focused session, or click individual questions to review them one by one.

Free forever · No credit card required

Track your 1Z0-829 domain progress

Save your results, see per-domain analytics, and get readiness scores — free, for every certification.

Sign Up Free

Free forever · Every certification included

Practice Session

10 questions20 questions30 questions50 questions

Study Resources

All DomainsPractice TestMock ExamFlashcardsStudy Guide