Statements and Expressions

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

int highScore = 450000;

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[] args) {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 ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.