Java Statements

A statement specifies an action in a Java program. For example, a statement may tell the add of values of x and y and assign their sum to the variable z. It then prints a message to the standard output or writing data to a file, etc.

Java statements can be broadly classified into three categories:

  • Declaration statement
  • Expression statement
  • Control flow statement

1. Java Declaration Statement

A declaration statement is used to declare a variable. For example,

int num;
int num2 = 100;
String str;

2. Java 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);

3. Java Flow Control 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 flow control statements. The if statement, while loop statement and for loop statement are examples of control flow statements.

You can learn more about these statements in separate tutorials in this blog.

Happy Learning !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.