Thuta Learning
BasicProgrammingbeginner

Operators

Relax. We'll talk through this in plain words — no textbook voice.

An operator is a symbol that performs an operation on values. Java has arithmetic, assignment, comparison, and logical operators. Once you're comfortable using operators, you can write calculations, conditions, validation, and filtering logic.

java
public class Main {
  public static void main(String[] args) {
    int price = 100;
    int discount = 15;
    int finalPrice = price - discount;

    boolean isAffordable = finalPrice <= 90;
    boolean hasStock = true;

    System.out.println("Final price: " + finalPrice);
    System.out.println("Can buy: " + (isAffordable && hasStock));
  }
}

price - discount calculates the final price. finalPrice <= 90 checks the condition and produces true/false. && is the logical AND operator, which is true only when both sides are true.

You should see
Final price: 85 Can buy: true

Real-world use

Discount calculations, login validation, user permission checks, and stock availability checks are all written using operators.

Easy traps

  • The most common mistakes are using = where you meant to check a condition, and not realizing that integer division doesn't produce a decimal result.