10x Blogs Directory

Thursday, February 19, 2009

Statements & Blocks

  • Statement
    -one or more lines of code terminated by a semicolon.
    -Example:System.out.println(“Hello world”);
  • Block
    -is one or more statements bounded by an opening and closing curly braces that groups the statements as one unit.
    -Block statements can be nested indefinitely.
    -Any amount of white space is allowed.
    -Example:

-public static void main( String[] args )

{

System.out.println("Hello");

System.out.println("world”);

}


Coding Guidelines:

  • In creating blocks, you can place the opening curly brace in line with the statement. For example:
    public static void main( String[] args ){
    or you can place the curly brace on the next line, like,
    public static void main( String[] args )‏
    {
  • You should indent the next statements after the start of a block. For example:
    public static void main( String[] args ){
    System.out.println("Hello");
    System.out.println("world");
    }