Statements in Java

Statements are roughly equivalent to sentences in natural languages. In a programming language, a statement is the smallest complete unit of execution. Statements can be classified into various categories depending upon the action they perform in the program. In Java we can have the following types of statements:

Declaration statements: These statements are used to declare variables, methods, arrays, etc. For examples:

int val; //declare a variable named val of int type
int add(int a, int b); //declare add as method
float product[]; //declare product as an one dimensional array

Object Creation Statement: This statement is used to create an object. Suppose Vehicle is a class defined by the user. To create an object of this class we use:

Vehicle car new Vehicle(); // car is an object of Vehicle class.

Assignment statement: This statement is used to assign the value of an expression to a variable. For example:

val=5: //assignment statement

Control statements: These statements are used to control the flow of execution of statements. For example: if, if…else, for, while, do…while, break, continue, etc.

Increment and Decrement statements: These statements are used to increase or decrease the value of a variable. For example:

val++; //increment statement
val--; //decrement statement

Method invocation statements: These statements are used to call a method.

val=add(x,y); // Method invocation statement
System.out.println(val); //Method invocation statement

These statements are explained in detail wherever they are used.

Leave a Reply