Java supports many kinds of operators. Operators can be applied on variables or constants. Classification of operators is shown below.
Type | Operators | Meaning | Example | Result |
Arithmetic operators | + | Addition | 2+3 | 5 |
- | Substation | 5-2 | 3 | |
* | Multiplication | 5*4 | 20 | |
/ | Division | 8/4 | 2 | |
% | Modulus | 5%2 | 1 | |
Relational operators | > | Greater than | 10>3 | true |
>= | Greater than or equal to | 5>=7 | false | |
< | Less than | 4<3 | false | |
<= | Less than or equal to | 4<=4 | true | |
== | Equal to | 5==4 | false | |
!= | Not equal to | 5!=4 | true | |
Logical operators | && | AND | (2>1)&&(4<2) | true |
|| | OR | (2>1)||(2<1) | true | |
! | NOT | !true | false | |
Assignment operators | =, +=, -=, *=, /=, %= | Assignment | x=3 x+=4 | x=3 x=7 |
Bit wise operators | & | Bitwise AND | 13 & 14 | 12 |
| | Bitwise OR | 13 | 14 | 15 | |
^ | Bitwise XOR | 13 ^ 14 | 3 | |
<< | Left shift | 50<<3 | 400 | |
>> | Right shift | 50>>4 | 3 | |
>>> | Right shift with zero fill | 50>>>3 | 6 | |
~ | Complement | ~5 | -6 | |
Other operators | - | Unary minus | x=3, x=-x | x=-3 |
?: | Ternary conditional | k=10>5 ? 1 : 2 | k=2 | |
++ | Increment | x=3, x++ | x=4 | |
-- | Decrement | x=3, x- - | x=2 | |
instanceof | instance of operator | Box b1=new Box() b1 instanceof Box | true | |
. | dot operator | s1.name | | |
+ | concatenation | “ravi”+”varma” | ravivarma |
0 comments:
Post a Comment