A statement specifies an action in a Java program, such as assigning the sum of x and y to z, printing a message to the standard output, writing data to a file, etc.
Statements in Java can be broadly classified into three categories:
- Declaration statement
- Expression statement
- Control flow statement
Declaration Statement
A declaration statement is used to declare a variable. For example,
int num; int num2 = 100; String str;
Expression Statement
An expression with a semicolon at the end is called an expression statement. For example,
/Increment and decrement expressions
num++;
++num;
num--;
--num;
//Assignment expressions
num = 100;
num *= 10;
//Method invocation expressions
System.out.println("This is a statement");
someMethod(param1, param2);
Control Flow Statement
By default, all statements in a Java program are executed in the order they appear in the program. Sometimes you may want to execute a set of statements repeatedly for a number of times or as long as a particular condition is true.
All of these are possible in Java using control flow statements. If block, while loop and for loop statements are examples of control flow statements.
You can learn more about these stements in seperate tutorials in this blog.
Happy Learning !!
Leave a Reply