Previous Section  < Day Day Up >  Next Section

Statements and Expressions

Computer programs are a set of instructions that tell the computer what to do. Each of these instructions is called a statement. The following example from a Java program is a statement:


int HighScore = 400000;


You can use brackets to group a set of statements together in a Java program. These groupings are called block statements. Consider the following portion of a program:


1: public static void main(String[] arguments) {

2:    int a = 3;

3:    int b = 4;

4:    int c = 8 * 5;

5: }


Lines 2–4 of this example are a block statement. The opening bracket on Line 1 denotes the beginning of the block, and the closing bracket on Line 5 denotes the end of the block.

Some statements are called expressions because they involve a mathematical expression and produce a result. Line 4 in the preceding example is an expression because it sets the value of the c variable equal to 8 multiplied by 5. You'll be working with several different types of expressions throughout the coming sections.

    Previous Section  < Day Day Up >  Next Section