Software Training Institute in Chennai with 100% Placements – SLA Institute
⭐ Exclusive Summer Courses Offer ⭐ 💰 Flat ₹5,000 - ₹10,000 off on all courses 👨‍👩‍👧 Additional discounts for group enrollments 🎓 100% Placement Support 🏆 90,000+ Students Successfully Placed 🚀 Avail now! Limited seats only!
Java Operators
Share on your Social Media

Java Operators

Published On: April 8, 2026

Introduction to Java Operators

In Java, operators are special symbols that perform certain operations on a single, two, or three operands and then produce a final result. Operators in Java are the building blocks of any logical operations within a Java program. Java offers a wide range of operators for efficient data management, from simple arithmetic to complex bitwise operations. Explore our Java course syllabus to get started.

1. Arithmetic Operators in Java

Arithmetic operators are used in mathematical statements in the same manner as in algebra. They are the most frequently used Java operators for simple data management.

OperatorNameDescriptionExample (A=10,B=20)
+AdditionAdds values on either side of the operatorA+B=30
SubtractionSubtracts the right-hand operand from the left-hand operandA−B=−10
*MultiplicationMultiplies values on either side of the operatorA∗B=200
/DivisionDivides the left-hand operand by the right-hand operandB/A=2
%ModulusDivides the left-hand operand by the right-hand operand and returns the remainderB%A=0
++IncrementIncreases the value of the operand by 1B++=21
DecrementDecreases the value of the operand by 1B−−=19

Post-increment versus Pre-increment

The most common confusion is the placement of the operators (the placement of the ++ or the — operator).

  • Prefix (++count): The operator increments the variable and then uses the new value for the expression.
  • Postfix (count++): The operator uses the current value for the expression and then increments the variable.

Code Example:

int x = 10;

int y = ++x; // x is 11, y is 11

int a = 10;

int b = a++; // a is 11, b is 10

2. Relational (Comparison) Operators in Java

Relational operators check the relationship between the two operands, i.e., the relationship of the first operand to the second operand. The relational operators check for equality and order between the two operands. The outcome of a relational operator is always a Boolean data type (true or false).

OperatorDescriptionExample (A=10,B=20)
==Checks if the values of two operands are equal(A==B) is false
!=Checks if the values of two operands are not equal(A!=B) is true
>Checks if the left operand is greater than the right operand(A>B) is false
<Checks if the left operand is less than the right operand(A<B) is true
>=Checks if the left operand is greater than or equal to the right operand(A>=B) is false

Begin your learning journey with our Java tutorial for beginners.

3. Logical Operators in Java

The logical operators are mainly used to create complex conditions using several relational expressions. They are subject to the rules of Boolean algebra.

  • Logical AND (&&): This operator returns true if both operands are true. This operator also uses “short-circuit” evaluation, meaning that if the first operand is false, the second operand is not evaluated.
  • Logical OR (||): This operator returns true if at least one of the operands is true. If the first operand is true, the second operand is not evaluated.
  • Logical NOT (!): This operator simply reverses the logical condition of the operand.

Code Example:

boolean isAdult = true;

boolean hasTicket = false;

if (isAdult && hasTicket) {

    System.out.println(“Entry Allowed”);

} else if (!hasTicket) {

    System.out.println(“Please buy a ticket.”);

}

4. Bitwise Operators in Java

Java has several bitwise operators, and these are applicable to the integer data types: long, int, short, char, and byte.

OperatorNameDescription
&Bitwise ANDResult is 1 if both bits are 1
|Bitwise ORResult is 1 if either bit is 1
^Bitwise XORResult is 1 if bits are different
~Bitwise ComplementInverts all bits (unary operator)
<<Left ShiftShifts bits to the left, fills with zero
>>Right ShiftShifts bits to the right, fills with sign bit
>>>Unsigned Right ShiftShifts bits to the right, fills with zero

5. Assignment Operators in Java

The assignment operators are used for assignment operations. The simple assignment operator is =, but there are compound assignment operators that can be used to shorten the code for certain operations.

OperatorExampleEquivalent to
=C = A + BAssigns the value of A+B to C
+=C += AC = C + A
-=C -= AC = C – A
*=C *= AC = C * A
/=C /= AC = C / A
%=C %= AC = C % A

Gain expertise with our Java training in Chennai.

6. The Ternary Operator in Java (?:)

The ternary operator is a special operator in Java, and it is the only operator that takes three operands. The ternary operator is often used to replace an if-else statement.

Syntax: variable = (condition) ? valueIfTrue : valueIfFalse;

Code Example:

int time = 20;

String greeting = (time < 18) ? “Good day” : “Good evening”;

System.out.println(greeting); // Prints “Good evening”

7. The instanceof Operator

The instanceof operator is used only for object reference variables. The instanceof operator checks whether the object is of a particular type or not, i.e., it checks whether it is of class type or interface type.

String name = “SLA”;

boolean result = name instanceof String; // Returns true

Operator Precedence in Java

If an expression contains more than one operator, Java has its own order of precedence. The use of parentheses is allowed.

  • Postfix: expression++, expression–
  • Unary: ++expression, –expression, +, -, ~, !
  • Multiplicative: *, /, %
  • Additive: +, –
  • Shift: <<, >>, >>>
  • Relational: <, >, <=, >=, instanceof
  • Equality: ==, !=
  • Bitwise AND: &
  • Bitwise XOR: ^
  • Bitwise OR: |
  • Logical AND: &&
  • Logical OR: ||
  • Ternary: ?:
  • Assignment: =, +=, -=, etc.

Thrive in your career with our Java interview questions and answers.

Conclusion

Mastering Java operators enables you to write compact and efficient code. Arithmetic and relational operators are sufficient for day-to-day programming, but learning bitwise and ternary operators helps you optimize your code for better performance. Learn Java operators comprehensively in our software training institute in Chennai.

Share on your Social Media
Get Your Instant Job & Placement Eligibility
Report in Just 30 Seconds!
Below 30% - not Eligible (Needs Preparation)
30% – 70% - Partially Eligible (Needs Guidance)
Above 70% - Fully Eligible (Ready to Start)

We are excited to get started with you

Give us your information and we will arange for a free call (at your convenience) with one of our counsellors. You can get all your queries answered before deciding to join SLA and move your career forward.