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 is a binary operator that functions as either a bitwise AND or a logical (non-short-circuiting) AND, depending on the data types of its operands.
Bitwise AND (Integral Types)
When applied to integral data types (byte, short, int, long, char), the & operator performs a bit-by-bit comparison of the two’s complement binary representation of the operands.
Mechanics:
- For each corresponding bit position, the result bit is
1if and only if both operand bits are1. Otherwise, the result bit is0. - Java applies binary numeric promotion before the operation. If neither operand is a
long, both are promoted toint. If one is along, the other is promoted tolong.
Logical AND (Boolean Types)
When applied toboolean operands, the & operator performs a logical AND operation.
Mechanics:
- The expression evaluates to
trueif and only if both the left-hand side (LHS) and right-hand side (RHS) operands evaluate totrue. - Non-short-circuiting evaluation: Unlike the conditional AND operator (
&&), the&operator guarantees the evaluation of both operands. Even if the LHS evaluates tofalse(which mathematically guarantees the final result will befalse), the RHS expression is still fully executed.
Truth Table
The underlying logic for both contexts maps to the following truth table (where1 maps to true and 0 maps to false):
| Operand 1 (LHS) | Operand 2 (RHS) | Result (LHS & RHS) |
|---|---|---|
1 / true | 1 / true | 1 / true |
1 / true | 0 / false | 0 / false |
0 / false | 1 / true | 0 / false |
0 / false | 0 / false | 0 / false |
Master Java with Deep Grasping Methodology!Learn More





