Browse Oracle Certification Guides

1Z0-831 Java 25 Patterns, switch, and Branch Legality Guide

Study 1Z0-831 Java 25 Patterns, switch, and Branch Legality: key concepts, common traps, and exam decision cues.

Modern Java branch questions punish hand-waving. The winning move is still to decide legality first, then flow, then output.

Flow-choice map

If the stem is mainly about… Better first instinct
switch expression result confirm every reachable path yields a value
pattern variable use confirm the pattern actually matched in that control path
preview pattern features check feature status before assuming baseline legality
“obvious” runtime output decide legality first

Common traps

Trap Better rule
assuming any pattern variable is in scope everywhere after the test scope follows the actual matched flow
forgetting yield in block-style switch expressions result production is explicit
assuming modern switch behaves like older fall-through intuition expression rules are stricter

Decision order that usually wins

  1. Decide whether the switch or pattern form is legal.
  2. Determine which arms are reachable.
  3. Confirm how the result is produced.
  4. Only then predict output or exception behavior.

Quiz

Loading quiz…
Revised on Sunday, May 10, 2026