If you want to test a condition in a Java program, the most basic way is with an if statements. As you learned previously, the boolean type is used to store only two possible values: either true or false. The if statement works along those same lines, testing some condition and determining if it is true or false.
For example, if I had two integers defined thusly:
int a = 5;
int b = 6;
I could test if they were the same like this
if (a == b) {
// Yay, they are equal
}
I could also test if a was greater than b like this
if (a > b) {
// Yay, a is greater than b
}
else
If a conditional if statement returns false, it simply skips the block of code underneath it and proceeds on with the rest of the program. If, however, you want to do something else when the if statement fails, you can use the else statement
if(a == b) {
// Yay, they are equal
} else {
// Darn, they aren't equal
}