DEV Community

Cover image for Java Operators Made Simple — Learning the Logic
Mayur Gharjare
Mayur Gharjare

Posted on

Java Operators Made Simple — Learning the Logic

What Are Operators in Java?
In simple terms, operators are special symbols used to perform operations on variables and values.

Imagine them as the glue that connects logic, numbers, and decisions in Java.
Types of Operators in Java
Here’s a quick breakdown of the different categories:

  1. Arithmetic Operators These are used for basic math: int a = 10; int b = 5; System.out.println(a + b); // Output: 15
  • Addition

  • Subtraction

  • Multiplication

/ Division

% Modulus (Remainder)

2.Relational (Comparison) Operators
Used to compare two values:
int a = 5;
int b = 10;
System.out.println(a < b); // Output: true

== Equal to

!= Not equal to

Greater than

< Less than

= Greater than or equal to

<= Less than or equal to

When I first used == instead of =, my code broke. Lesson learned: double equals compares, single equals assigns!

3.Logical Operators
Used in decision-making with conditions.
int age = 20;
if (age > 18 && age < 30) {
System.out.println("Young and energetic!");
}

&& AND

|| OR

! NOT

This is where Java starts to think logically, just like us.

  1. Assignment Operators Used to assign values: int x = 10; x += 5; // x = x + 5

= Basic assignment

+=, -=, *=, /=, %= Shortcut assignments

  1. Unary Operators Work with a single value: int a = 5; System.out.println(++a); // Output: 6 ++ Increment

-- Decrement

+, - Unary plus and minus

! Logical NOT

  1. Bitwise Operators Operate at the bit level: int a = 5; // 0101 int b = 3; // 0011 System.out.println(a & b); // Output: 1 (0001) &, |, ^, ~, <<, >>

Honestly, bitwise felt scary — but once you visualize binary, it clicks!
Real Life Use Case
Let’s say you're building a voting system. You’d use:

and < to check if someone is above 18.

&& to check multiple conditions (like ID verification and age).

% to count how many votes are odd or even.
Image description

All this, just by combining operators smartly.

Let's Talk
If you’ve ever confused == and =, or struggled with && vs ||, trust me — you're not alone. Let me know your favorite (or most confusing) operator in the comments!

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.