Java basic syntax: variables and constants

Source: Internet
Author: User
Basic Java Syntax: variables and constants-general Linux technology-Linux programming and kernel information. For more information, see the following. 1. variables:
Definition: I believe that the definition of it should not be mentioned :) everyone should be familiar with it.
For example:
A, a1, and name are all valid variables.
Note:
1) Java requires that the type of the variable be declared before a variable is used.
2) the declaration of a variable in Java is a complete Java statement, so a semicolon should be used at the end.
3) Naming rules for variables:
The variable must start with a letter.
Variable names are any combination of letters or digits.
In Java, letters indicate any character in Unicode, which is equivalent to a letter.
A digit also contains any Unicode character other than 0-9 that is equal to a digit.
+ The copyright information symbol Circle C and space cannot be used in the variable name.
Variable names are case sensitive.
The length of the variable name is basically unlimited.
If you want to know which Unicode characters are considered to be letters in Java, you can use the isJavaIdentifierStart and isJavaIdentifierPart methods in the Character class to check.
Java reserved words cannot be used in variable names.
4) multiple variables can be declared in one statement. Different variables are separated by commas.
2. Variable assignment and initialization:
The value of a variable can be obtained in two ways. One is a value assignment. To assign a value to a variable, a value assignment statement is required. Another method is initialization, Which is initialization. It is actually a value assignment statement, but this value assignment statement is completed together when the variable is declared.
For example:
Int a = 10; // This is the initialization process of a variable.
The functions of the following two statements are the same as those of the preceding statement, except that the declaration and value assignment of variables are separated here.
Int;
A = 10; // it should end with a semicolon at the end of the value assignment statement.
Note:
1) there is absolutely no uninitialized variable in Java. You must assign a value to the variable before using it.
2) declarations can appear at any position in the code, but can be declared only once for a variable in any code block of the method.
3. constants:
Definition: a constant is a constant.
For example:
1. "hello"
Note:
1) Use the final keyword in Java to define a constant.
Int final a = 10; // declares an integer constant a whose value is 10.
2) The constant name is often capitalized.
Related Article

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.