Java Study Notes (2), java Study Notes
I. Common java Data Types
Data Type |
Bytes occupied |
Note: |
Int |
4 |
|
Char |
2 |
|
Double |
8 |
|
Float |
4 |
Float a = 2f; (f or F must be added; otherwise, the default value is double) |
Boolean |
1 |
Only true or false without 0 or non-0 |
String |
|
String type |
Long/short int |
8/2 |
|
Byte |
1 |
1 byte is 8 bits |
Ii. Data Type Conversion
1. automatic conversion: byte-> short int-> char-> int-> long int-> float-> double
Conversion condition: the variable type from low type to high type (that is, the conversion direction indicated by the arrow) will not change, but the calculated value will change to high type
2. Forced type conversion (data type) variable names such as char a; (int) a --------- a will be forcibly converted to int type such
Convert a = 3.2 of double type to int type, and remove. 2 automatically. Conversion from high precision to low precision will result in loss of accuracy.
Iii. Naming rules in java
I. Naming rules
1. All project names are in lower case
2. All package names are in lower case
3. The first letter of a class name is capitalized. If the class name is composed of multiple words, the first letter of each word must be capitalized.
For example, public class MyClass {}
4. The variable name and method name are in lower case. If the name is composed of multiple words, the first letter of each word must be in upper case.
For example, int index = 0;
Public void toString (){}
5. All constant names are capitalized.
For example, public static final String GAME_COLOR = "RED ";
6. All naming rules must follow the following rules:
1) The name can only contain letters, numbers, underscores, and $ characters.
2) cannot begin with a number
3) The name cannot use keywords in JAVA.
4) Chinese and Pinyin names are not allowed.
Ii. Notes
// Single line comment
/* Multi-line comment */
4. Operators
Arithmetic Operators: +,-, *,/, % (the number on both sides of the remainder must be an integer), ++ (auto-increment), and -- I auto-subtraction. (Note the differences between I ++ and ++ I)
Link:>, <,! =, <=, >=, =
Value assignment operator: =
Logical operators: & and, or |, non !, & Continuous routing and, | Do not short circuit or. (No short circuit means)
Bit OPERATOR :...........
Operator: a = a> 0? B: c;
// If a is greater than 0, a = B, otherwise a = c;
2. Priority: