Forum

Learn Java Operator…
 
Notifications
Clear all

Learn Java Operators

1 Posts
1 Users
0 Reactions
13 Views
 josh
(@josh)
Member Admin
Joined: 2 months ago
Posts: 510
Topic starter  

Let’s decode Java operators together—it’s like teaching your code how to do math, logic, and comparisons 🧠✨


Arithmetic Operators

These handle basic math:

Operator Meaning Example Result
+ Addition 5 + 3 8
- Subtraction 5 - 3 2
* Multiplication 5 * 3 15
/ Division 6 / 3 2
% Modulus 7 % 3 1 (remainder)

🔍 Relational/Comparison Operators

Used to compare two values—returns true or false:

Operator Meaning Example
== Equal to 5 == 5true
!= Not equal to 5 != 3true
> Greater than 5 > 3true
< Less than 3 < 5true
>= Greater or equal 5 >= 5true
<= Less or equal 3 <= 5true

🤖 Logical Operators

Used for combining boolean conditions:

Operator Meaning Example Result
&& AND true && false false
`   ` OR `true   false` true
! NOT !true false

🧪 Assignment Operators

Used to assign values:

Operator Meaning Example
= Assign x = 5
+= Add then assign x += 2 (same as x = x + 2)
-= Subtract then assign x -= 2
*= Multiply then assign x *= 2
/= Divide then assign x /= 2
%= Modulus then assign x %= 2

✨ Bonus: Unary Operators

They work on a single operand:

  • ++x or x++ : Increment by 1
  • --x or x-- : Decrement by 1
  • +x : Positive (rarely used)
  • -x : Negation

 


   
Quote
Share: