All about Java operators

With the help of Java operators, we can perform mathematical or logical operations on different data types.

Types

Explanation –

Code sample –

Arithmetic operator –

Output – 3

Assignment operator –

Output – 11

Bitwise operator –

Output – 14

Conditional operator –

Output – 1

Logical operator –

Output –

false

true

false

Relational operator –

Output – true

Unary Operator –

Output – 6

— Notes —

Logical operator

&&
any one side is false., then result is false
true && false = false
true && true = true
false && false = false
———————-
||
any one side is true. result is true
true || false = true
true || true = true
false || false = false
—————
!
!(true) = false
!(false) = true

Bitwise operator

& – if any one side is 0, then result is 0
6 = 0110
8 = 1000
result = 0000 = 0

| – if any one of the side is 1, then result is 1
6 = 0110
8 = 1000
1110 = 14

Content posted is based on learning or working experience, Share the post with others if find useful, Any queries?, leave comments or discuss on our facebook:qavalidation.com, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: