Java variables and data types: Java constants and variables-Le byte

Hello, everyone, again to tell you the basic knowledge of Java. Last time I talked about one of Java variables and data types: Java programming specifications, keywords and identifiers. This time I will go on to talk about Java constants and variables.

PS: Obtain learning resources and technical dry goods: lezijie007 (code 33)

Constants and variables (must be firmly grasped)

1. Constant

1), definition

During the execution of the program, the value does not change.

2), classification

A: Literal constant

B: Custom constants (described later)

3), literal constant

A: The string constant "hello"

B: integer constant 12, 23

C: Decimal constant 12.345

D: Character constants'a','A','@'

E: Boolean constants true, false

F: empty constant null (described later)

4) Four expressions are provided for integer constants in Java

A: Binary is composed of 0 and 1. Start with 0b.

B: The octal system consists of 0, 1,...7. Start with 0.

C: The decimal system consists of 0, 1,...9. Integers are decimal by default.

D: Hexadecimal is composed of 0, 1, ... 9, a, b, c, d, e, f (upper and lowercase). Start with 0x/0X.

2. Variable

Statement: Separate statements with semicolons int a;int b;

1), definition

During the execution of the program, its value can be changed within a certain range.

2), variable definition format:

A: Data type variable name = initialization value;

B: Data type variable name;

Variable name = variable value;

3) Two uses of variables:

1. Deposit value

2. Value

4) Focus on variables:

1. Data type

2. Variable name

3. The value of the variable

4. The scope of the variable is determined according to ()

Variables cannot have the same name in the same scope

The same variable can only have one value in it at a certain moment, and the later value will replace/overwrite the previous value (the previous value will never be found, and there is no cancellation)

5), Use variable attention items:

1. The variable itself exists

2. The value of the variable must exist

3. It must exist in the scope when used

Its scope: from the beginning of the definition to the end of the closing brace opposite to the nearest opening brace.

6) Steps for using variables:

Note: Once a variable is used, it must be guaranteed that its value already exists (except for formal parameters)

Guess you like

Origin blog.csdn.net/dirft_lez/article/details/108024990