Java Statements
3 min read ·
Java statements are instructions that tell the program what action to perform. Every Java program is made up of one or more statements that execute step by step.
What Is a Statement in Java
A statement is a complete line of code that performs a specific task. In Java, most statements end with a semicolon.
Each line above is a separate Java statement.
Note
The semicolon tells the Java compiler that the statement has ended.
Declaration Statements
Declaration statements are used to declare variables.
These statements reserve memory for variables but do not assign values.
Assignment Statements
Assignment statements store values inside variables.
You can also declare and assign a value in a single statement.
Expression Statements
Expression statements perform calculations or method calls.
These statements evaluate expressions and may produce a result.
Method Call Statements
Calling a method is also a Java statement.
Here, a method is called to display output on the screen.
Real World Scenario
Pressing a button on a remote control sends a command. A method call statement works the same way in Java.
Control Statements
Control statements decide the flow of execution in a program.
They allow Java programs to make decisions and repeat actions.
Block Statements
A block statement is a group of statements enclosed within curly braces.
Blocks are commonly used with conditions, loops, and methods.
Empty Statements
An empty statement contains only a semicolon.
It does nothing and is rarely used, but it is still a valid Java statement.
Caution
Using empty statements by mistake can lead to logical errors that are hard to detect.
Order of Statement Execution
Java executes statements from top to bottom unless a control statement changes the flow.
The output will follow the same order as the statements.
Why Statements Matter
Understanding Java statements helps you:
Read programs correctly
Write logical code
Debug errors easily
Goal Achieved
You now understand how Java statements work and how they form the backbone of every Java program.