Ch 5 · Operators & Expressions · Java

Topic 5 of 13 in Java — Complete Tutorial (Beginner) — 3 lessons.

Arithmetic Operators

Arithmetic operators perform calculations on numbers. Most match the symbols from maths class. The modulus operator % gives the remainder after division — 17 % 5 is 2. Java also has the increment ++ and decrement -- operators, which add or subtract one from a variable, used constantly in loops and counters. Remember the integer-division rule from Chapter 4: dividing two ints discards the decimals.

Comparison Operators

Comparison operators compare two values and always give a boolean. Note that == checks if two values are equal (a single = means assignment), and != checks if they are not equal. The rest — >, <, >=, <= — work just as in maths. These operators are how your program asks questions about its data and makes decisions.

Logical & Assignment Operators

Logical operators combine boolean conditions: && (AND) needs every condition true, || (OR) needs at least one true, and ! (NOT) flips a boolean. Assignment operators are shorthands for updating a variable: score += 10 means score = score + 10. These appear constantly whenever a value changes step by step or a decision depends on several factors.

All topics in Java Beginner

  1. Introduction to Programming & Java
  2. Your First Java Program
  3. Variables — Your Data Containers
  4. Data Types — Kinds of Values
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Methods
  9. Arrays & Lists
  10. Objects & Classes
  11. Strings — Working with Text
  12. Exception Handling
  13. Mini-Projects & Practice