Operators

There are several kinds of operators in Java, including relational, bitwise, and arithmetic.

Logical Operators

The two logical operators in Java are

AND: &&

OR: ||

These are primarily used in if and while tests. For example, you might have

if(x > 5 && y < 12)            // if both conditions are true,
                               // do the following
     System.out.println("x qualifies");
else                           // They are not both true
      if(a ==3 || b < 7)       // if one or both of these
                               // conditions is true do the
                               // following code
           System.out.println("a might qualify");

The AND condition says that both Boolean tests must resolve to true for the overall test to be true. Remember that an if test must resolve to a Boolean condition of true or false. The OR test says that either the ...

Get PURE Java™ 2 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.