0Pricing
Java Academy · Lesson

If Statements – Basics

Write decisions with if, else if, else. Combine comparisons with logical operators and avoid common mistakes.

Decisions Overview

Decisions with if

Programs often need to choose a path based on data. In Java, if evaluates a boolean expression and executes a block when it is true.

  • Comparison: == != > < >= <=
  • Logical: && (and), || (or), ! (not)
  • Blocks are inside braces { }.

If Syntax

Basic syntax

The condition in parentheses must be true or false.

public class Main {
    public static void main(String[] args) {
        int age = 18;

        if (age >= 18) {
            System.out.println("Adult");
        }
    }
}

All lessons in this course

  1. If Statements – Basics
  2. If Statements – Practice & Nested
  3. Common Pitfalls & Debugging Messages
← Back to Java Academy