# if Statement

*noun*

say it: **“if STAYT-ment”** **/ɪf ˈsteɪtmənt/**

Code that runs a block only when a condition is true, and skips it otherwise.

## What does **if Statement** do in Java?

**if Statement** — A statement that runs code only when its condition is true.

```java
class Venue {
    boolean canEnter(int age) {
        boolean isAdult = age >= 18;
        boolean isSenior = age >= 65;

        if (isAdult && !isSenior) {
            return true;
        }

        return false;
    }
}
```

## In a sentence

- “I wrapped the discount in an **if statement** so it only applies when the total is over 100.”

Level: Novice · [More Java terms at this level](https://www.ask-codey.com/glossary?category=java&level=1)

Updated: October 26, 2026

## In other subjects

- [if Statement in C#](https://www.ask-codey.com/glossary/if-statement-c-sharp)
- [If Statement in C#](https://www.ask-codey.com/glossary/if-statement-c-style)
- [if Statement in JavaScript](https://www.ask-codey.com/glossary/if-statement-javascript)
- [if Statement in PowerShell](https://www.ask-codey.com/glossary/if-statement-powershell)
- [if Statement in Python](https://www.ask-codey.com/glossary/if-statement)
- [if Statement in Unix](https://www.ask-codey.com/glossary/if-statement-unix)

Source: https://www.ask-codey.com/glossary/if-statement-java
