Java Statements

Java Tutorial

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:

  1. Declaration Statements

  2. Expression Statements

  3. Selection (Control Flow) Statements

  4. Looping (Iteration) Statements

  5. Jump Statements

  6. 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 TypeExample
ifRuns block if condition is true
if-elseRuns alternative block if false
switch-caseMultiple conditional branches

Example:

 Looping (Iteration) Statements

Used to repeat actions multiple times.

Loop TypeMeaning
forRuns for a defined number of times
whileRuns while condition is true
do-whileExecutes at least once

Example:

Jump Statements

Used to change normal flow.

StatementPurpose
breakExit a loop or switch
continueSkip current loop iteration
returnExit 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

TypeExample
Declarationint x = 5;
Expressionx++;
Selection if, switch
Loop for, while
Jump break, continue, return
Block{ ... }

You may also like...