An operator, in Java, is a special symbols performing specific operations on one, two or three operands and then returning a result.

### Arithmetic Operators

Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators. Assume integer variable A holds 10 and variable B holds 20, then –
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. The following table lists the arithmetic operators.

Assume integer variable A holds 10 and variable B holds 20, then –

 Operator Description Example + (Addition) Adds values on either side of the operator. A + B willgive 30 - (Subtraction) Subtracts right-hand operand from left-hand operand. A - B willgive -10 * (Multiplication) Multiplies values on either side of the operator. A * B willgive 200 / (Division) Divides left-hand operand by right-hand operand. B / A willgive 2 % (Modulus) Divides left-hand operand by right-hand operand andreturns remainder. B % A willgive 0 ++ (Increment) Increases the value of operand by 1. B++ gives21 -- (Decrement) Decreases the value of operand by 1. B-- gives19

### Relational Operators

There are following relational operators supported by Java language. Assume variable A holds 10 and variable B holds 20, then –

 Operator Description Example == (equal to) Checks if the values of two operands are equal or not, ifyes then condition becomes true. (A == B) isnot true. != (not equal to) Checks if the values of two operands are equal or not, ifvalues are not equal then condition becomes true. (A != B) istrue. > (greater than) Checks if the value of left operand is greater than thevalue of right operand, if yes then condition becomes true. (A > B) isnot true. < (less than) Checks if the value of left operand is less than the value ofright operand, if yes then condition becomes true. (A < B) istrue. >= (greater thanor equal to) Checks if the value of left operand is greater than or equalto the value of right operand, if yes then conditionbecomes true. (A >= B) isnot true. <= (less than orequal to) Checks if the value of left operand is less than or equal tothe value of right operand, if yes then condition becomestrue. (A <= B) istrue.

### Bitwise Operators

Java defines several bitwise operators, which can be applied to the integer types, long, int, short, char, and byte.
Bitwise operator works on bits and performs bit-by-bit operation. Assume if a = 60 and b =13; now in binary format they will be as follows -
a = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100
a|b = 0011 1101
a^b = 0011 0001
~a = 1100 0011
The following table lists the bitwise operators.
Assume integer variable A holds 60 and variable B holds 13 then –

 Operator Description Example & (bitwise and) Binary AND Operator copies a bit to the result if itexists in both operands. (A & B) will give 12which is 0000 1100 | (bitwise or) Binary OR Operator copies a bit if it exists in eitheroperand. (A | B) will give 61which is 0011 1101
 ^ (bitwise XOR) Binary XOR Operator copies the bit if it is set inone operand but not both. (A ^ B) will give 49which is 0011 0001 ~ (bitwisecompliment) Binary Ones Complement Operator is unary andhas the effect of 'flipping' bits. (~A ) will give -61which is 1100 0011in 2's complementform due to asigned binarynumber. << (left shift) Binary Left Shift Operator. The left operands valueis moved left by the number of bits specified bythe right operand. A << 2 will give 240which is 1111 0000 >> (right shift) Binary Right Shift Operator. The left operandsvalue is moved right by the number of bitsspecified by the right operand. A >> 2 will give 15which is 1111 >>> (zero fill rightshift) Shift right zero fill operator. The left operandsvalue is moved right by the number of bitsspecified by the right operand and shifted valuesare filled up with zeros. A >>>2 will give 15which is 0000 1111

### Logical Operators

The following table lists the logical operators.

Assume Boolean Variables A holds true and variable B holds false, then –

 Operator Description Example && (logical and) Called Logical AND operator. If both the operandsare non-zero, then the condition becomes true. (A && B) is false || (logical or) Called Logical OR Operator. If any of the twooperands are non-zero, then the conditionbecomes true. (A || B) is true ! (logical not) Called Logical NOT Operator. Use to reverses thelogical state of its operand. If a condition is truethen Logical NOT operator will make false. !(A && B) is true

### Assignment Operators

Following are the assignment operators supported by Java language –

 Operator Description Example = Simple assignment operator. Assigns values from right side operandsto left side operand. C = A + B willassign valueof A + B intoC += Add AND assignment operator. It adds right operand to the leftoperand and assign the result to left operand. C += A isequivalentto C = C + A -= Subtract AND assignment operator. It subtracts right operand from theleft operand and assign the result to left operand. C -= A isequivalentto C = C – A
 *= Multiply AND assignment operator. It multiplies right operand with theleft operand and assign the result to left operand. C *= A isequivalentto C = C * A /= Divide AND assignment operator. It divides left operand with the rightoperand and assign the result to left operand. C /= A isequivalentto C = C / A %= Modulus AND assignment operator. It takes modulus using twooperands and assign the result to left operand. C %= A isequivalentto C = C % A <<= Left shift AND assignment operator. C <<= 2 issame as C =C << 2 >>= Right shift AND assignment operator. C >>= 2 issame as C =C >> 2 &= Bitwise AND assignment operator. C &= 2 issame as C =C & 2 ^= bitwise exclusive OR and assignment operator. C ^= 2 issame as C =C ^ 2 |= bitwise inclusive OR and assignment operator. C |= 2 issame as C =C | 2

### Conditional Operator ( ? : )

Conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable.

The operator is written as –
variable x = (expression) ? value if true : value if false
Following is an example –