Operators
Arithmetic
Binary operators
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (returns the integer remainder)
Unary operators
- Unary negation (reverses the sign)
++ Increment (can be prefix or postfix)
-- Decrement (can be prefix or postfix)
Assignment
= Assign
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Modulus and assign
&= Bitwise AND and assign
|= Bitwise OR and assign
^= Bitwise XOR and assign
<<= Left shift (zero fill) and assign
>>= Right shift (sign-propogating) and assign
>>>= Right shift (zero fill) and assign
Comparison
== Equal
!= Not equal
> Greater than
>= Greather than or equal to
< Less than
<= Less than or equal to
Conditional
? : Ternary comparison operator
condition ? val1 : val2 (Evaluates val1 if condition is true; otherwise, evaluates val2)
Boolean
- Short-circuit logical operations
- Evaluates the minimal number of
expressions necessary
- Partial evaluation (rather than full
evaluation)
&& and
|| or
! not (logical negation)
Bitwise
Binary operators
& And (can also be used as a boolean operator for full evaluation)
| Or (can also be used as a boolean operator for full evaluation)
^ Xor
<< Shift left (zero fill)
>> Shift right (sign-propogating); copies of the leftmost bit (sign bit) are shifted in from the left.
>>> Shift right (zero fill)
For positive numbers, >> and >>> yield the same result.
Unary operators
~ Not (inverts the bits)
String
= Assignment
+ Concatenation
Resources URL:
notes/java/resources
Sources URL:
notes/java/sources
- Subtraction
* Multiplication
/ Division
% Modulus (returns the integer remainder)
++ Increment (can be prefix or postfix)
-- Decrement (can be prefix or postfix)
= Assign
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Modulus and assign
&= Bitwise AND and assign
|= Bitwise OR and assign
^= Bitwise XOR and assign
<<= Left shift (zero fill) and assign
>>= Right shift (sign-propogating) and assign
>>>= Right shift (zero fill) and assign
Comparison
== Equal
!= Not equal
> Greater than
>= Greather than or equal to
< Less than
<= Less than or equal to
Conditional
? : Ternary comparison operator
condition ? val1 : val2 (Evaluates val1 if condition is true; otherwise, evaluates val2)
Boolean
- Short-circuit logical operations
- Evaluates the minimal number of
expressions necessary
- Partial evaluation (rather than full
evaluation)
&& and
|| or
! not (logical negation)
Bitwise
Binary operators
& And (can also be used as a boolean operator for full evaluation)
| Or (can also be used as a boolean operator for full evaluation)
^ Xor
<< Shift left (zero fill)
>> Shift right (sign-propogating); copies of the leftmost bit (sign bit) are shifted in from the left.
>>> Shift right (zero fill)
For positive numbers, >> and >>> yield the same result.
Unary operators
~ Not (inverts the bits)
String
= Assignment
+ Concatenation
Resources URL:
notes/java/resources
Sources URL:
notes/java/sources
!= Not equal
> Greater than
>= Greather than or equal to
< Less than
<= Less than or equal to
? : Ternary comparison operator
condition ? val1 : val2 (Evaluates val1 if condition is true; otherwise, evaluates val2)
Boolean
- Short-circuit logical operations
- Evaluates the minimal number of
expressions necessary
- Partial evaluation (rather than full
evaluation)
&& and
|| or
! not (logical negation)
Bitwise
Binary operators
& And (can also be used as a boolean operator for full evaluation)
| Or (can also be used as a boolean operator for full evaluation)
^ Xor
<< Shift left (zero fill)
>> Shift right (sign-propogating); copies of the leftmost bit (sign bit) are shifted in from the left.
>>> Shift right (zero fill)
For positive numbers, >> and >>> yield the same result.
Unary operators
~ Not (inverts the bits)
String
= Assignment
+ Concatenation
Resources URL:
notes/java/resources
Sources URL:
notes/java/sources
|| or
! not (logical negation)
Binary operators
& And (can also be used as a boolean operator for full evaluation)Unary operators
| Or (can also be used as a boolean operator for full evaluation)
^ Xor
<< Shift left (zero fill)
>> Shift right (sign-propogating); copies of the leftmost bit (sign bit) are shifted in from the left.
>>> Shift right (zero fill)
For positive numbers, >> and >>> yield the same result.
~ Not (inverts the bits)
String
= Assignment
+ Concatenation
Resources URL:
notes/java/resources
Sources URL:
notes/java/sources
+ Concatenation
Resources URL:
notes/java/resources
Sources URL:
notes/java/sources