Java Statements

Java Statements
A statement in Java is a complete instruction that tells the computer to perform an action. A Java program is made up of many statements that execute in sequence.
Every executable Java statement ends with a semicolon ( ; ).
Types of Java Statements
Java statements can be categorized into:
Declaration Statements
Expression Statements
Selection (Control Flow) Statements
Looping (Iteration) Statements
Jump Statements
Block Statements
Let’s understand each one
Declaration Statements
Used to declare variables.
Expression Statements
These perform actions like assignment, method calls, increments, etc.
Examples:
Selection (Decision-Making) Statements
Used to make decisions based on conditions.
| Statement Type | Example |
|---|---|
if | Runs block if condition is true |
if-else | Runs alternative block if false |
switch-case | Multiple conditional branches |
Example:
Looping (Iteration) Statements
Used to repeat actions multiple times.
| Loop Type | Meaning |
|---|---|
for | Runs for a defined number of times |
while | Runs while condition is true |
do-while | Executes at least once |
Example:
Jump Statements
Used to change normal flow.
| Statement | Purpose |
|---|---|
break | Exit a loop or switch |
continue | Skip current loop iteration |
return | Exit method and optionally return a value |
Example:
Block Statement
A block statement is a group of statements inside curly braces { }.
Blocks are used in:
classes
methods
loops
if conditions
Example Program Using Different Statements
Summary
| Type | Example |
|---|---|
| Declaration | int x = 5; |
| Expression | x++; |
| Selection |
if, switch |
| Loop |
for, while |
| Jump |
break, continue, return |
| Block | { ... } |
