Java Basics-expressions, statements, and code blocks

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.