In this topic, you will learn about, Types of Java Statements.
Empty statement: An empty statement in Java is written as a single semicolon. The empty statement doesn’t do anything, but the syntax is occasionally useful. For example, you can use it to indicate an empty loop body of a for loop:
for(int i = 0; i < 10; i++)
Labeled Statements: A labeled statement is simply a statement that has been given a name by prepending an identifier and a colon to it. Labels are used by the break and continue statements. For Example:
rowLoop: for(int r = 0; r < rows.length; r++)
// A labeled loop
colLoop: for(int c = 0; c < columns.length; c++)
// Another one
// Use a label
Expression Statements: Most statements in Java are expression statements. Java has seven types of expression statements.
- Method Call
- Allocation Expression
Selection statements: Selection statements are used to select one of the several control flows. There are three types of selection statements.
- if … else
Iteration Statements: Iteration statements are used to repeat one or more statements up to a given no. of time. There are three types of iteration statements.
- do while
Jump Statements: Jump statements are used to pass the control to the beginning or end of the current block, or to a block, or to a labeled statement. Such labels must be in the same block and continue labels must be on an iteration statement. There are four types of jump statements.
Synchronization statement: These statements(e.g. synchronized) are used for handling issues with multi-threading.
Guarding Statements: These statements are used for the safe handling of code that may cause exceptions(such as division by zero). These statements use the keywords try, catch, and finally.
Comment below if you have queries related to the above topic Types of Java Statements.