An expression
Expressions consist of variables, operators, and method calls, and the return value type of an expression is determined by the elements in the expression (such as operators, variables, and so on), such as:
Cadence = 0
The preceding code returns a value of type int, because the assignment operator returns a box with the same data type as the left operand type, and of course the expression can return other types such as Boolean and string.
You can also combine multiple expressions in Java to form a more complex expression, such as
x + y/100 // Note operator Precedence
Statement
A Java statement is similar to a sentence in a natural language, and the statement is a complete execution unit with the following semicolon ";" At the end, the statement can be formed:
- An assignment expression
- All use
++ or--的变量
- Method reference
- Create an expression for an object
Examples are as follows:
// an assignment expression avalue = 8933.234; // Add statement (using + +)avalue++; // method Invocation Statement System.out.println ("Hello world!" ); // Creating object Statements New Bicycle ();
In addition to the expression statements are control flow statements and declaration statements, which are declared as follows:
double avalue = 8933.234;
code block
A block of code consists of 0 or more statements within curly braces that can be used anywhere a single statement can be used. Note that the variable defined in the code block is not valid until the block is executed, and is a local variable.
Java Basics-expressions, statements, and code blocks