Java Expressions, Statements and Blocks

In java, Statements are composed of one or many expressions. They may also be grouped into blocks.


Expressions in java are made of variables, operators and method invocations. An expression always evaluates to a single value.

//Examples of valid expressions
a =0;
"Hello "+firstName + " "+ lastName
d = a + b;



A statement in java is a complete unit of execution. Assignment expressions, pre-increment operators, pre-decrement operators, post-increment operators, post-decrement operators, method invocation and object instantiation expressions can compose a statement by terminating the expression with a semicolon (;) .

// using the Examples to create valid statements
int a =0;
System.out.println("Hello "+firstName + " "+ lastName);
double d = a + b;



A block in Java is composed of zero or more statements enclosed inside curly braces { }. Blockes are allowed wherever statements are allowed. Blocks can be nested.

// Example of two blocks
{ // block 1 beginning
  int x=0;
  System.out.println("Block 1 is executed");
} // block 1 ending
{ // block 2 beginning
  System.out.println("Block 2 is executed");
} // block 2 ending