Bitwise and Logical Operators

Table 3.4 summarizes the operators that can be used on individual bits in integer primitives and in logical expressions. Bitwise operators are used in expressions with integer values and apply an operation separately to each bit in an integer. The term logical expression refers to an expression in which all of the operands can be reduced to boolean primitives. Logical operators produce a boolean primitive result.

Table 3.4. Bitwise and Logical Operators
PrecedenceOperatorOperator TypeDescription
1~IntegralUnary bitwise complement
1!LogicalUnary logical complement
4<<IntegralLeft shift
4>>IntegralRight shift (keep sign)
4>>>IntegralRight shift (zero fill)
5instanceofObject, typeTests class membership
6==ObjectEquals (same ...

Get Java 2™ Programmer Exam Cram™ 2 (Exam CX-310-035) 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.