5.1. The if, if-else, and ternary constructs

[3.3] Create if and if/else and ternary constructs

In this section, we’ll cover if, if-else, and ternary constructs. We’ll examine what happens when these constructs are used with and without curly braces {}. We’ll also cover nested if, if-else, and ternary constructs.

5.1.1. The if construct and its flavors

An if construct enables you to execute a set of statements in your code based on the result of a condition. This condition must always evaluate to a boolean or a Boolean value. You can specify a set of statements to execute when this condition evaluates to true or false. (In many Java books, the terms constructs and statements are used interchangeably.)

Multiple flavors of the ...

Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.