Java Reference
In-Depth Information
and efficiency. Also, the { and } exist only in your program's source code. Java does
not, per se, execute the { or }.
As you will see later in this topic, blocks of code have additional properties and uses.
However, the main reason for their existence is to create logically inseparable units of code.
Semicolons and Positioning
In Java, the semicolon is a separator that is used to terminate a statement. That is, each
individual statement must be ended with a semicolon. It indicates the end of one logical
entity.
As you know, a block is a set of logically connected statements that are surrounded by
opening and closing braces. A block is not terminated with a semicolon. Since a block is
a group of statements, with a semicolon after each statement, it makes sense that a block
is not terminated by a semicolon; instead, the end of the block is indicated by the closing
brace.
Java does not recognize the end of the line as a terminator. For this reason, it does not
matter where on a line you put a statement. For example,
is the same as the following, to Java:
Furthermore, the individual elements of a statement can also be put on separate lines.
For example, the following is perfectly acceptable:
Breaking long lines in this fashion is often used to make programs more readable. It can
also help prevent excessively long lines from wrapping.
Search WWH ::




Custom Search