Java Operators Explained

📘 Java 👁 59 views 📅 Dec 01, 2025
⏱ Estimated reading time: 2 min

Operators in Java are special symbols used to perform operations on variables and values. They help in building expressions, performing computations, making decisions, and controlling the flow of a program. Java supports a wide variety of operators grouped into several categories.


1. Arithmetic Operators

These operators perform basic mathematical operations.

OperatorDescription
+Addition
-Subtraction
*Multiplication
/Division
%Modulus (remainder)

Example:

int a = 10, b = 3; int result = a % b; // result = 1

2. Relational (Comparison) Operators

Used to compare two values. They return a boolean result (true/false).

OperatorMeaning
==Equal to
!=Not equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

Example:

if (a > b) { ... }

3. Logical Operators

Used to combine multiple boolean expressions.

OperatorMeaning
&&Logical AND
||Logical OR
!Logical NOT

Example:

if (age > 18 && age < 60) { ... }

These operators are essential in decision-making and conditional evaluations.


4. Assignment Operators

Used to assign values to variables. The basic operator is =, and Java supports many compound assignments.

OperatorExampleEquivalent To
+=a += 5a = a + 5
-=a -= 5a = a - 5
*=a *= 5a = a * 5
/=a /= 5a = a / 5
%=a %= 5a = a % 5

These operators make code more concise.


5. Increment and Decrement Operators

Used to increase or decrease the value of a variable by 1.

  • ++a (pre-increment)

  • a++ (post-increment)

  • --a (pre-decrement)

  • a-- (post-decrement)

Example:

int x = 5; int y = ++x; // x = 6, y = 6

6. Bitwise Operators

Operate directly on bits and are useful in low-level programming.

OperatorDescription
&Bitwise AND
|Bitwise OR
^Bitwise XOR
~Bitwise NOT
<<Left shift
>>Right shift
>>>Unsigned right shift

Example:

int a = 5 << 1; // 5 becomes 10 in binary shifting

7. Ternary (Conditional) Operator

The ternary operator ?: is a shorthand for if-else.

Syntax:

condition ? value1 : value2

Example:

String result = (age >= 18) ? "Adult" : "Minor";

8. instanceof Operator

Used to test whether an object belongs to a particular class or interface.

Example:

if (obj instanceof String) { ... }

Conclusion

Operators are the building blocks of Java expressions and play a crucial role in performing mathematical operations, making decisions, comparing values, and controlling program logic. Understanding the different categories of operators helps programmers write efficient, readable, and well-structured Java code.


🔒 Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes