Operators Reference Java
From Free Knowledge Base- The DUCK Project: information for everyone
Relational Operators Operator Use Description ------------------------------------------------------------------------------- > op1 > op2 Returns true if op1 is greater than op2 >= op1 >= op2 Returns true if op1 is greater than or equal to op2 < op1 < op2 Returns true if op1 is less than op2 <= op1 <= op2 Returns true if op1 is less than or equal to op2 == op1 == op2 Returns true if op1 and op2 are equal != op1 != op2 Returns true if op1 and op2 are not equal Conditional Operators Operator Use Description ------------------------------------------------------------------------------- && op1 && op2 Returns true if op1 and op2 are both true; conditionally evaluates op2 || op1 || op2 Returns true if either op1 or op2 is true; conditionally evaluates op2 ! !op Returns true if op is false & op1 & op2 Returns true if op1 and op2 are both boolean and both true; always evaluates op1 and op2; if both operands are numbers, performs bitwise AND operation | op1 | op2 Returns true if both op1 and op2 are boolean and either op1 or op2 is true; always evaluates op1 and op2; if both operands are numbers, performs bitwise inclusive OR operation ^ op1 ^ op2 Returns true if op1 and op2 are different — that is, if one or the other of the operands, but not both, is true Shift Operators Operator Use Description ------------------------------------------------------------------------------- << op1 << op2 Shifts bits of op1 left by distance op2; fills with 0 bits on the right side >> op1 >> op2 Shifts bits of op1 right by distance op2; fills with highest (sign) bit on the left side >>> op1 >>> op2 Shifts bits of op1 right by distance op2; fills with 0 bits on the left side Logical Operators Operator Use Operation ------------------------------------------------------------------------------- & op1 & op2 Bitwise AND if both operands are numbers; conditional AND if both operands are boolean | op1 | op2 Bitwise OR if both operands are numbers; conditional OR if both operands are boolean ^ op1 ^ op2 Bitwise exclusive OR (XOR) ~ ~op Bitwise complement The Bitwise AND Function Bit in op1 Corresponding Bit in op2 Result ------------------------------------------------------------------------------- 0 0 0 0 1 0 1 0 0 1 1 1 The Bitwise Inclusive OR Function Bit in op1 Corresponding Bit in op2 Result ------------------------------------------------------------------------------- 0 0 0 0 1 1 1 0 1 1 1 1 The Bitwise Exclusive OR (XOR) Function Bit in op1 Corresponding Bit in op2 Result ------------------------------------------------------------------------------- 0 0 0 0 1 1 1 0 1 1 1 0