A java method body is a series of one or more statements. In a java programming language, a statement is a basic unit of execution which follows the syntax of the language and includes one or more clauses.
Note: All statements except blocks terminated by a semicolon(;).
Type of Java Statements
Java supports three different types of statements:
- Blocks: Blocks are denoted by open and close curly braces.
- Empty Statements: The empty statement, represented by a semicolon(;) and nothing else, does nothing.
- Declaration statements : Declare variables.
- Expression statements: Change the values of variables, call methods and create objects.
- Control flow statements: Determine the order that statements are executed. Statements in java source code generally executed from top to bottom, in the order they appear. However, with control-flow statements, that order can be interrupted to implement decision making, branching or looping so that the Java program can run particular blocks of code based on certain conditions. Control flow statements categorize as below:
A block is a series of zero or more statements between a matching set of open and close curly braces. For example :
- The bodies of methods and switch statements are blocks.
- The bodies of if, for, while, and do-while statements may also be blocks.
- You can also simply create a new block inside another block by enclosing code within curly braces. A block contained within another block is itself a statement of the outer block.
- Blocks that contain no statements are called an empty block.
Example of Statements
At the high level below are some examples of statements. You can get more detail about each type of statement in the corresponding link.