Java Operators

Java Operators

Operators in Java are special symbols used to perform operations on variables and values.

Java provides several types of operators:


1. Arithmetic Operators

Used to perform mathematical operations.

OperatorNameExampleResult
+Addition10 + 515
-Subtraction10 - 55
*Multiplication10 * 550
/Division10 / 52
%Modulus (Remainder)10 % 31

Example:




2. Assignment Operators

Used to assign values to variables.

OperatorMeaningExample
=Assignx = 5
+=Add and assignx += 3 // x = x + 3
-=Subtract and assignx -= 3
*=Multiply and assignx *= 3
/=Divide and assignx /= 3
%=Modulus and assignx %= 3

3. Comparison (Relational) Operators

Used to compare two values.

OperatorMeaningExample
==Equal tox == y
!=Not equalx != y
>Greater thanx > y
<Less thanx < y
>=Greater or equalx >= y
<=Less or equalx <= y

Example:




4. Logical Operators

Used to combine multiple conditions.

OperatorMeaningExample
&&Logical AND(x > 5 && y < 10)
``
!Logical NOT!(x > 5)

Example:




5. Unary Operators

Used with a single operand.

OperatorMeaning
+Positive
-Negative
++Increment
--Decrement
!Logical NOT

Example:




6. Bitwise Operators

Used to perform operations on bits.

OperatorMeaning
&Bitwise AND
``
^Bitwise XOR
~Bitwise NOT
<<Left shift
>>Right shift

7. Ternary (Conditional) Operator

Short form of if-else.




⭐ Example Program Using Operators:



You may also like...