Statements and Expressions

All tasks that you want to accomplish in a Java program can be broken down into a series of statements.

A statement is a simple command written in a programming language that causes something to happen.

Statements represent a single action that is taken in a Java program. All of the following are simple Java statements:

int weight = 295;

System.out.println("Free the bound periodicals!");

song.duration = 230;

Some statements can convey a value, such as when you add two numbers together in a program or evaluate whether two variables are equal to each other. These kinds of statements are called expressions.

An expression is a statement that results in a value being produced. The value can be stored for later ...

Get Sams Teach Yourself Java 2 in 21 Days, Second 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.