Java gives you four decision-making constructs, and the choice between them comes down to what shape your condition has rather than to any preference about style.
| Construct | Shape of the problem | Produces a value? |
|---|---|---|
if | One boolean test | No, it is a statement |
if-else | Two mutually exclusive paths | No, it is a statement |
if-else if ladder | A range of thresholds, tested in order | No, it is a statement |
switch expression | One value matched against a fixed set of cases | Yes, it is an expression |
The distinction in the last column is the important one and it drives everything else. An if is a **statement**, so it performs an action and yields nothing. A switch used in expression form is an **expression**, so it produces a value you can assign, return, or pass along.
if (temperature > 30) {
System.out.println("Hot");
// performs an action
}String label = switch (temperature) {
// produces a value
default -> "thawing";
};