- Variable
- Variable: A piece of storage space in memory that is the basic unit for storing data.
- Use: Declare first, then assign value, in use.
- Declaration: Data type + variable name = value. (example: int a = 5;)
- Data type
- Classification:
- Detailed
String type:à ("") is used to generate 0 to multiple bytes.
- Type conversions
- Type conversions
- Two types are required to be compatible with each other, and the destination type is greater than the source type.
Example: Byte B = 5------Short s = b;à automatic type promotion to short.
- Type promotion
- Operator
- Arithmetic operators: +,-, *,%,++,--
- Assignment operator: =,+=,-=,*=,/=,%=
- Relational operators: ==,>,>=,<,<=,!=
- Logical operator:&& (short-circuit and),& (non-short-circuit and), | | (short circuit or), | (non-shorted or),!
- Ternary operators
- Self-Summary:
The above is the language foundation of Java, which explains the declaration of variables, the classification of data types, the conversion of data types and the promotion and operators.
Attention:
- The Java language is a strongly typed programming language, and the data type and value must be of the same type when declaring variables.
- Assignment of long: long L = 10L or long l=10l; value of float type: float f=10.1f or float f = 10.1F
- The arithmetic operation when + = does not perform type automatic promotion.
- Example: byte B = 10;
b = B + 1-->false (automatic elevation of type)
B + = 1-->true
Basic Java Notes (1)----Language basics