Java

Operators

Do math, compare values, and make decisions! A complete guide to Java operators.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Do math, compare values, and make decisions! A complete guide to Java operators. This hands-on tutorial focuses on practical implementation of operators concepts.

Operators

Operators are symbols that perform operations on variables and values.

1. Arithmetic Operators

Used to perform common mathematical operations.

OperatorNameDescriptionExample
+AdditionAdds together two valuesx + y
-SubtractionSubtracts one value from anotherx - y
*MultiplicationMultiplies two valuesx * y
/DivisionDivides one value by anotherx / y
%ModulusReturns the division remainderx % y
++IncrementIncreases the value by 1++x
--DecrementDecreases the value by 1--x

2. Comparison Operators

Used to compare two values. Returns a boolean.

OperatorNameExample
==Equal tox == y
!=Not equalx != y
>Greater thanx > y
<Less thanx < y
>=Greater than or equal tox >= y
<=Less than or equal tox <= y

3. Logical Operators

Used to combine conditional statements.

OperatorNameDescriptionExample
&&Logical andReturns true if both statements are truex < 5 && x < 10
||Logical orReturns true if one of the statements is truex < 5 || x < 4
!Logical notReverse the result, returns false if the result is true!(x < 5 && x < 10)

4. Assignment Operators

Used to assign values to variables. =, +=, -=, *=, /=, %=.

Example: x += 3 is same as x = x + 3.

5. Bitwise Operators

Used to perform manipulation of individual bits of a number. & (AND), | (OR), ^ (XOR), ~ (Complement), << (Left Shift), >> (Right Shift).

6. Type Comparison Operator

instanceof compares an object to a specified type.

String str = "Hello";
boolean result = str instanceof String; // true

7. Ternary Operator

Ideally a shorthand for if-else. variable = (condition) ? expressionTrue : expressionFalse;

int time = 20;
String result = (time < 18) ? "Good day" : "Good evening";

Interactive Code

Test your math skills!

JAVA PLAYGROUND
⏳ Loading editor…

[!TIP] Notice that 10 / 3 prints 3, not 3.33. This is because both are integers. To get a decimal, cast one to double: (double) a / b.

AI Mentor

Confused about "Java arithmetic, logical and comparison operators details"? Ask our AI mentor for a simplified explanation.

Quiz

Quiz

Question 1 of 4

What is the result of 10 % 3?

3
1
0
3.33

Next Steps

Now that we can manipulate data, let's learn how to control the flow of our program with Control Flow Statements (if-else, loops).