Java Statement Types – Computer Sir Ki Class


Code Learning#JAVA#3755 siteicon   siteicon   siteicon  

Java Statement Types

Demonstration of different types of java statements.

Learning Objectives

  • Understanding different types of statements.

Source Code

TC++ #3755

Source Code

class AllStatements
public static void main(String[] args)
int x=1;
System.out.println("Output after declaration statement = "+x);
System.out.println("Output after assignment statement = "+x);
System.out.println("Output after increment statement = "+x);
Character c=new Character('A');
System.out.println("Output after object creation statement = "+c);
boolean mi=Character.isDigit(c);
System.out.println("Output after method invocation statement = "+mi);
for(int i=0;i<2;i++) x++;
System.out.println("Output after flow control statement = "+x);

Test it !

Run Output

Output after declaration statement = 1
Output after assignment statement = 13
Output after increment statement = 14
Output after object creation statement = A
Output after method invocation statement = false
Output after flow control statement = 16

Code Understanding

int x=1;
This is a declaration statement. In this case we are initialising along with declaration itself.
System.out.println(“Output after declaration statement = “+x);
Here we are printing variable declared with its initial value

This is simply an assignment statement. The right side of assignment may contain a long expression also.
System.out.println(“Output after assignment statement = “+x);
Here we are printing the value assigned.

This is a increment statement. This could be other types of unary prefix or postfix operator also.
System.out.println(“Output after increment statement = “+x);
Output of increment statement is printed here.

Character c=new Character(‘A’);
This is a object creation statement. The new operator is the hallmark of this statement
System.out.println(“Output after object creation statement = “+c);
The created object value is printed here.

boolean mi=Character.isDigit(c);
This is a method invocation statement. The method of Character class is being invoked here.
System.out.println(“Output after method invocation statement = “+mi);
The returned value of method invoked is being printed here.

for(int i=0;i<2;i++) x++;
This is a flow control statement
System.out.println(“Output after flow control statement = “+x);
The value modified during the flow control is being printed here.

Code Notes

  • Following 4 are classified as Expression Based Statements
    – Assignment expression based
    – Increment/Decrement expression based
    – Method invocation expression based
    – Object creation expression based
  • The other 2 types are –
    – Declaration Statement
    – Control flow Statements (which are decision flows and iteration flows)
  • The documentation related to expressions and statements can be read at –

Suggested Filename(s):


sunmitra| Created: 5-Mar-2018 | Updated: 5-Mar-2018|