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 !!

Leave a Reply

0 Comments
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions, and frequently asked interview questions.

Our Blogs

REST API Tutorial