Java operators can be grouped into the following four groups:
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators:
Java Arithmetic Operators
Operator | Result |
---|---|
+ | Addition |
- | Subtraction (unary minus) |
* | Multiplication |
/ | Division |
% | Modulus |
++ | Increment |
+= | Addition assignment |
-= | Subtraction assignment |
*= | Multiplication assignment |
/= | Division assignment |
%= | Modulus assignment |
-- | Decrement |
The operands of the arithmetic operators must be of a numeric type. You cannot use arithmetic operators on boolean types, but you can use them on char types.
Java bitwise operators can be applied to the integer types: long, int, short, char, byte
.
Bitwise Operators act upon the individual bits of their operands.
Bitwise Operators
Operator | Result |
---|---|
~ | Bitwise unary NOT |
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise exclusive OR |
>> | Shift right |
>>> | Shift right zero fill |
<< | Shift left |
&= | Bitwise AND assignment |
|= | Bitwise OR assignment |
^= | Bitwise exclusive OR assignment |
>>= | Shift right assignment |
>>>= | Shift right zero fill assignment |
<<= | Shift left assignment |
The relational operators determine the relationship between two operands. The relational operators are:
Relational Operators
Operator | Result |
---|---|
== | Equal to |
!= | Not equal to |
> | Greater than |
< | Less than |
>= | Greater than or equal to |
<= | Less than or equal to |
The Boolean logical operators operate only on boolean operands.
Boolean Logical Operators
Operator | Result |
---|---|
& | Logical AND |
| | Logical OR |
^ | Logical XOR (exclusive OR) |
|| | Short-circuit OR |
&& | Short-circuit AND |
! | Logical unary NOT |
&= | AND assignment |
|= | OR assignment |
^= | XOR assignment |
== | Equal to |
!= | Not equal to |
? : | Ternary if-then-else |
Category | Operators |
---|---|
Unary | ++ -- + - ! ~ (type) |
Arithmetic | * / % + - |
Shift | <<>>>>> |
Comparison | <<= >>= instanceof == != |
Bitwise | & ^ | |
Short-circuit | && || |
Conditional | ? : |
Assignment | = op= |
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |