Discussion Script: Java Operators
Operators are symbols that allow us to perform actions or computations on values or variables
in a program.
For example, when we write:
a+b
The + symbol is the operator, and a and b are called operands—these are the values being
operated on.
Unary and Binary Operators
Operators can be classified based on how many operands they require:
1. Unary Operators – these operators work with only one operand.
Examples include:
o - (negation) → makes a value negative
o ~ (bitwise complement)
o ++ (increment) → adds 1 to the value
o -- (decrement) → subtracts 1 from the value
For example:
x++;
This means we are increasing the value of x by 1.
2. Binary Operators – these operators need two operands.
Examples include:
o + (addition)
o - (subtraction)
o * (multiplication)
o / (division)
For example:
a+b
Here, the operator + uses two values: a and b.
Arithmetic Operators
Just like in math, Java uses arithmetic operators to perform common calculations.
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo (remainder)
++ Increment (add 1)
Operator Description
-- Decrement (subtract 1)
Example:
int a = 10, b = 3;
[Link](a + b); // 13
[Link](a - b); // 7
[Link](a * b); // 30
[Link](a / b); // 3
[Link](a % b); // 1 (because 10 divided by 3 leaves a remainder of 1)
Important Notes
The modulo operator % gives the remainder of a division.
++ and -- are shortcut operators to increase or decrease a value by 1.
Wrap-Up
To summarize:
Operators allow us to perform actions on values.
Unary operators need one operand.
Binary operators need two operands.
Arithmetic operators help us perform math operations in Java.
Would you like me to also create:
✅ A short quiz
✅ A worksheet
✅ A PowerPoint presentation
✅ Visual examples with code output
🔼 Increment (++)
Increment means add 1 to the value of a variable.
Example:
int x = 5;
x++; // this means x = x + 1
So now,
x becomes 6.
Think of it like:
++ pushes the number up by 1.
🔽 Decrement (--)
Decrement means subtract 1 from the variable.
Example:
int y = 10;
y--; // this means y = y - 1
So now,
y becomes 9.
Think of it like:
-- pulls the number down by 1.
📌 Easy Comparison
Code Meaning Result
x++ x = x + 1 x increases
x-- x = x - 1 x decreases
🟢 Complete Example to See the Change
int a = 4;
[Link](a); // 4
a++; // increase by 1
[Link](a); // now 5
a--; // decrease by 1
[Link](a); // now 4 again
✋ But there's one more thing...
Sometimes ++ or -- can be written before the variable or after it:
Form Example Meaning
Postfix x++ Use the value first, then add 1
Prefix ++x Add 1 first, then use the value
Example to show the difference:
int n = 5;
[Link](n++); // prints 5, then n becomes 6
[Link](n); // prints 6
int m = 5;
[Link](++m); // m becomes 6 first, prints 6
🧠 Tip to Remember
n++ : “Later add”
++n : “Now add”
If you'd like, I can also make:
✅ A simple mini quiz
✅ A worksheet
✅ A PowerPoint slide for your class
💡 What is an Operand?
An operand is the value or variable that the operator works on.
In other words:
Operand = the number or variable being used in the operation
Operator = the symbol that performs the action
Example
a+b
a and b → Operands (the values)
+ → Operator (the action: addition)
Another Example
x++;
x is the operand (the value changing)
++ is the operator (adds 1)
So this means:
x=x+1
Super Simple Memory Tip
Operators = symbols that do something (+, -, *, /, ++, --)
Operands = the "things" being affected (numbers or variable names like x, y, 5, 10)
Quick Practice
Can you identify the operator and operands here?
7%3
Operands: 7 and 3
Operator: % (modulo / remainder)