Java Reference
In-Depth Information
expressions are guaranteed to be evaluated in order from left to right (which
matters if any of the arguments have side effects).
Lambda expression ( )
A lambda expression is an anonymous collection of executable Java code, essen‐
tially a method body. It consists of a method argument list (zero or more
comma-separated expressions contained within parentheses) followed by the
lambda arrow operator followed by a block of Java code. If the block of code
comprises just a single statement, then the usual curly braces to denote block
boundaries can be omitted.
Object creation ( new )
In Java, objects (and arrays) are created with the new operator, which is fol‐
lowed by the type of the object to be created and a parenthesized list of argu‐
ments to be passed to the object constructor . A constructor is a special block of
code that initializes a newly created object, so the object creation syntax is simi‐
lar to the Java method invocation syntax. For example:
new ArrayList ();
new Point ( 1 , 2 )
Type conversion or casting ( () )
As we've already seen, parentheses can also be used as an operator to perform
narrowing type conversions, or casts. The first operand of this operator is the
type to be converted to; it is placed between the parentheses. The second
operand is the value to be converted; it follows the parentheses. For example:
( byte ) 28 // An integer literal cast to a byte type
( int ) ( x + 3.14f ) // A floating-point sum value cast to an integer
( String ) h . get ( k ) // A generic object cast to a string
A statement is a basic unit of execution in the Java language—it expresses a single
piece of intent by the programmer. Unlike expressions, Java statements do not have
a value. Statements also typically contain expressions and operators (especially
assignment operators) and are frequently executed for the side effects that they
Many of the statements defined by Java are flow-control statements, such as condi‐
tionals and loops, that can alter the default, linear order of execution in well-defined
ways. Table 2-5 summarizes the statements defined by Java.
Search WWH ::

Custom Search