Saturday, March 18, 2006



If you want your program to do anything at all, you will have to write statements. Just like the sentence is the smallest structure that make any sense to humans, a statement is the smalest structure that make any sense to the computer. Statements consists of tokens and expressions, like sentences consist of words and phrases in English.

A statement is similar to a sentence in a natural language like English, except that a statement tell the computer how to do something.

Concept: A statement is the smallest part of a program that the computer can understand.


class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");


In the application above, System.out.println("Hello World!"); is a statement, and the only line which actually does something.

A statement in Java must be terminated with the semicolon, the ';' character.


The following is the Java grammar for a Java statement:

Statement =
StatementWithoutTrailingSubstatement | LabeledStatement | IfThenStatement | IfThenElseStatement | WhileStatement | ForStatement ;

The grammar look more difficult than it really is. Just click around in the grammar to get a feeling what you may do with a statement.

No comments: