O'Reilly logo

Oracle Certified Associate, Java SE 7 Programmer Study Guide by Richard M. Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The if statement

The if statement is used to control the flow of execution based on a Boolean expression. There are two basic forms that can be used and there are several variations. The if statement consists of the if keyword, followed by a logical expression enclosed in parentheses and then by a statement. In the following diagram a graphical depiction of a simple if statement is presented:

The if statement

The following illustrates this form of the if statement where we compare rate to 100 and if it is equal to 100 we display a message to that effect:

if (rate==100) System.out.println("rate is equal to 100");

However, this is not as readable as the following equivalent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required