Java Reference
In-Depth Information
10.1. Statements and Blocks
The two basic statements are expression statements and declaration
statements, of which you've seen a plethora. Expression statements,
such as i++ or method invocations, are expressions that have a semicolon
at the end. The semicolon terminates the statement. [1] In fact, a semi-
colon by itself is a statement that does nothingthe empty statement. Not
all expressions can become statements, since it would be almost always
meaningless to have, for example, an expression such as x<= y stand
alone as a statement. Only the following types of expressions can be
made into statements by adding a terminating semicolon:
[1] There is a distinction between terminator and separator. The comma between identifiers in declara-
tions is a separator because it comes between elements in the list. The semicolon is a terminator be-
cause it ends each statement. If the semicolon were a statement separator, the last semicolon in a code
block would be unnecessary and (depending on the choice of the language designer) possibly invalid.
Assignment expressionsthose that contain = or one of the op = op-
erators
Prefix or postfix forms of ++ and --
Method calls (whether or not they return a value)
Object creation expressionsthose that use new to create an object
Declaration statements (formally called local variable declaration state-
ments ) declare a variable and initialize it to a value, as discussed in Sec-
tion 7.3.1 on page 170 . They can appear anywhere inside a block, not
just at the beginning. Local variables exist only as long as the block con-
taining their declaration is executing. Local variables must be initialized
before use, either by initialization when declared or by assignment. If any
local variable is used before it is initialized, the code will not compile.
Local class declaration statements declare a local inner class that can be
used within the block in which it was declared. Local classes were dis-
cussed in detail on page 142 .
 
 
Search WWH ::




Custom Search