Keywords and reserved words
- Key words
- Words that are given special meaning by the Java language
- All made up of lowercase letters
- Reserved words
- Reserved by Java, not used in the current version, words that may be keywords in later versions
- For example:goto,const
Identifier
is the custom name in the program, variable name, method name, class name, interface name, etc.
Naming rules
- A. consist of letters, numbers, _ and $;
B. Cannot begin with a number;
C. Inability to use keywords and reserved words;
D. No duplicate name and case sensitivity within the same scope;
Naming rules
| Package Name |
All lowercase |
Beanutil |
| Variable name, method name |
Hump rule + First Letter lowercase |
Beanutil |
| Class name, interface name |
Hump Rule + First letter capitalization |
Beanutil |
| Constant name |
All caps + underline segmentation |
Bean_util |
Comments
It is used for the annotation program, which improves the readability of the code and facilitates later maintenance.
① Single-line comment :
Format://...
The end of the line from//To this line is a comment.
② Multi-line comments
Format:/* ... */
The comments are between/* and the next */. (so multi-line annotations cannot be nested )
③ Document Comments
Format:/** ... */
Is a Java-specific comment that generates the API documentation for the code . (same cannot be nested)
Variable 1) data type
Java is a strongly typed language , and each variable must declare its type before it is used, and the system allocates a different size of memory space for different types of variables.
| Integral type |
Byte |
1 bytes |
-128~127 |
byte B = 100; |
| Short |
2 bytes |
-215~215-1
|
Short S = 5; |
| Int |
4 bytes |
-231~231-1 |
int i = 1; |
| Long |
8 bytes |
-263~263-1 |
Long large = 12345L; |
| Floating point Type |
Float |
4 bytes |
Single precision |
float F = 3.14F; |
| Double |
8 bytes |
Double precision |
Double d = 3.14; |
| Character type |
Char |
2 bytes |
0~65535 |
Char C1 = ' a ', c2 = ' \ n ', C3 = ' Medium ', C4 = 65535, C5 = ' \u0041 '; |
| Boolean type |
Boolean |
1 guests |
true | False |
Boolean B1 = True, B2 = false; |
Note :
- Integer literals are type int by default, and floating-point literals are by default double type;
- Both float and double are imprecise, so try to avoid using floating-point types in comparisons;
- A long literal is appended with an L suffix; the literal of type float is added with an F suffix;
- Boolean has only two values of true and false, cannot be 0 1 or null;
- The char type occupies 2 bytes, representing the characters in the Unicode character set, which can be numbers, letters, symbols, Chinese, Japanese, and Korean, and there are three ways to assign them:
- Use single quotation marks to contain a single character or escape character: ' A ', ' \ n '
- Use single quotation marks to include 16 decimal numbers: ' \u0041 '
- Number of direct uses between 0~65535:65
2) variables
- Concept
- is a storage area in memory;
- The region has its own type (data type) and name (variable name);
- The value of the region can only change within the data type range;
- Significance
- Used to store constants of the same type and can be reused;
- Attention
- The scope of the variable;
- Declared first, then initialized before it can be used;
- Use formatting
- Variable name of data type = initialization value;
JAVA002---java basic syntax