TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
| operator in Java functions as both a bitwise inclusive OR operator for integral types and a logical non-short-circuiting OR operator for boolean types. It evaluates two operands and yields a result based on whether at least one of the corresponding bits or boolean expressions evaluates to a positive state (1 or true).
Bitwise Inclusive OR (Integral Types)
When applied to integral data types (byte, short, int, long, char), the | operator performs a bit-by-bit comparison of the binary representations of the operands.
For each corresponding bit position, the operator applies the following truth table:
0 | 0 = 00 | 1 = 11 | 0 = 11 | 1 = 1
- If either operand is of type
long, the other operand is promoted tolong, and the result islong. - Otherwise, both operands are promoted to
int(even if they arebyte,short, orchar), and the result isint.
Logical Non-Short-Circuiting OR (Boolean Types)
When applied toboolean operands, the | operator evaluates to true if either the left-hand operand or the right-hand operand is true.
Crucially, the | operator guarantees the evaluation of both operands. This is the mechanical difference between the bitwise/logical OR (|) and the conditional OR (||). The conditional OR short-circuits (skips evaluating the right-hand operand if the left-hand operand is true), whereas the | operator forces full evaluation.
boolean, the return type of the | operation is strictly boolean. It cannot be mixed with integral types; attempting to use | with one boolean and one numeric type results in a compilation error.
Master Java with Deep Grasping Methodology!Learn More





