JAVA OPERATORS

Java Operators Explained – A Complete Guide

Java Operators Explained: A Complete Guide for Beginners

๐Ÿ“˜ Introduction

Operators are the foundation of Java programming. Whether you're performing mathematical operations, comparing values, or making decisions in your code — Java operators are essential tools in every Java developer’s toolkit.

๐Ÿงฎ Types of Java Operators

Java provides several categories of operators:

  • Arithmetic Operators
  • Relational (Comparison) Operators
  • Logical Operators
  • Assignment Operators
  • Unary Operators
  • Bitwise Operators
  • Ternary Operator
  • Instanceof Operator

๐Ÿ”ข 1. Arithmetic Operators

OperatorDescriptionExampleOutput
+Addition5 + 38
-Subtraction5 - 23
*Multiplication4 * 28
/Division10 / 25
%Modulus10 % 31
int a = 10, b = 3;
System.out.println("Addition: " + (a + b));

⚖️ 2. Relational (Comparison) Operators

OperatorDescriptionExample
==Equal toa == b
!=Not equal toa != b
>Greater thana > b
<Less thana < b
>=Greater than or equal toa >= b
<=Less than or equal toa <= b
int a = 5, b = 10;
System.out.println(a < b);  // true

๐Ÿง  3. Logical Operators

OperatorDescriptionExample
&&Logical ANDa > 5 && b < 10
||Logical ORa > 5 || b < 5
!Logical NOT!(a > 5)
boolean result = (a > 5 && b < 10);

✍️ 4. Assignment Operators

OperatorExampleEquivalent To
=a = 5
+=a += 3a = a + 3
-=a -= 2a = a - 2
int a = 10;
a += 5; // a = 15

➕ 5. Unary Operators

  • +a: Unary plus
  • -a: Unary minus
  • ++a / a++: Increment
  • --a / a--: Decrement
  • !a: Logical NOT

⚙️ 6. Bitwise Operators

  • &: Bitwise AND
  • |: Bitwise OR
  • ^: Bitwise XOR
  • ~: Bitwise Complement
  • <<: Left shift
  • >>: Right shift

❓ 7. Ternary Operator

int a = 10, b = 20;
int max = (a > b) ? a : b;
System.out.println("Max: " + max);

๐Ÿงฌ 8. instanceof Operator

String str = "Hello";
System.out.println(str instanceof String);  // true

๐ŸŽฏ Java Operators – Interview Questions

  1. What is the difference between == and .equals() in Java?
  2. How does the && operator differ from &?
  3. Explain the use of the ternary operator with an example.
  4. What is the output of 10 + 20 + "Java" in Java?
  5. How do pre-increment (++a) and post-increment (a++) behave differently?
  6. What are bitwise operators and when are they used?
  7. Can the modulus operator (%) be used with floating-point numbers in Java?
  8. What is the use of instanceof in Java?

๐Ÿ“ Conclusion

Java operators are essential tools for building logic and functionality in your applications. Understanding them deeply helps you write better, cleaner, and more efficient code.

๐Ÿ’ฌ Comments Section

Join the Discussion

๐Ÿ‘‡ What’s your experience with Java operators?

  • Do you have a shortcut or tip to share?
  • Stuck with an operator? Drop your code!
  • Want help solving a logic problem?

Leave a comment below and let's learn together! ๐Ÿง‘‍๐Ÿ’ป

Comments