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 the Exclusive OR (XOR) operator. It functions as a bitwise operator when applied to integer primitives and as a logical operator when applied to boolean primitives. It evaluates to 1 (or true) if and only if the operands are strictly different, and 0 (or false) if they are identical.
Bitwise XOR (Integer 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.
Bitwise Truth Table:
0 ^ 0yields00 ^ 1yields11 ^ 0yields11 ^ 1yields0
int and long), Java performs binary numeric promotion, widening the smaller type to match the larger type before applying the XOR operation.
Logical XOR (Boolean Types)
When applied toboolean operands, the ^ operator evaluates whether the two boolean expressions have different truth values.
Crucially, unlike the conditional logical operators (&& and ||), the logical ^ operator does not short-circuit. Both the left-hand and right-hand operands are strictly evaluated before the XOR operation is applied.
Logical Truth Table:
false ^ falseyieldsfalsefalse ^ trueyieldstruetrue ^ falseyieldstruetrue ^ trueyieldsfalse
Compound Assignment (^=)
Java provides a compound assignment operator for XOR, which applies the operation and assigns the result to the left-hand operand. It includes an implicit cast to the type of the left-hand operand.
Syntax Visualization:
Master Java with Deep Grasping Methodology!Learn More





