Zero, Java keywords
Declarations for classes and interfaces: class, extends, implements, interface
Package import and package declaration: import, package
Data type: boolean, byte, char, short, int, long, float, double
Optional values for certain data types: false, true, null
Process control: default, return, if, else, for, switch, case, do, while, break, continue,
Exception handling: try, catch, finally, throw, throws
Modifiers: abstract, final, native, private, protected, public, static, static, synchronized, transient, volatile
Operator: instanceof
Create an object: new
Quote: this, super
Method return type: void
Java reserved words: const and goto
1. Comments in java: There are three forms
1. // Single line comment
2. /* One or more lines of comment*/
3. /** Document comment*/ It must be placed outside the method body, and the command javadoc can be used to generate HTML documents.
2. ";", "{}", "" in Java code
Java statements separated by semicolons
Java code blocks are included in braces to ignore spaces.
Identifier: Used to name classes, methods, variables, and packages
Identifier naming rules:
1. Start with a character, "_" or "$". Only letters, numbers, "_" and "$"
2. Case sensitive.
3. No length limit.
4. The initial letter of the class/interface name is capitalized;
5. The first letter of the method name and variable name is lowercase, and the remaining first letter is uppercase;
6. Constant names are all capitalized;
7. Package name is all lowercase.
4. Basic data types:
name | Explanation | Storage requirements | Range or accuracy | illustrate |
Byte type | byte | 1 byte | -128 to 127 | |
Short-form | Short | 2 bytes | -2^15 to 2^15-1 | |
Integer | int | 4 bytes | -2^31 to 2^31-1 | |
Long shape | long | 8 bytes | -2^63 to 2^63-1 | Long integer numbers have a suffix L |
Single precision floating point type | float | 4 bytes | (The effective decimal places are 6~7) | When indicating float type data, you need to add the suffix F afterwards. Float data without suffix F is considered to be of double type. |
Double precision floating point type | double | 8 bytes | (The effective decimal places are 15 digits) | |
Character type | char | 2 bytes | Used to store characters in Unicode encoding tables. char is an unsigned 16-bit integer, and the literal value must be enclosed in single quotes (Note: single Chinese characters enclosed in single quotes are also correct) | |
Boolean type | boolean | uncertain | There are only two values, true and false, and it and integer cannot be converted to each other. |
5. The scope and lifetime of variables:
1. Variables are the basic units that store data.
2. Variables can be declared anywhere in the code block
3. The block starts with the left brace and ends with the right brace
4. The scope of a variable is the block where it is located
5. Member variable: declared in a class, its scope is the entire class. (can be defined anywhere other than methods in the class)
6. Local variables: An internal declaration of a method or a block of a method's code. If declared inside a method, its scope is the entire method; if declared inside a code block of a method, its scope is the code block. (Local variables must be defined first and then used)
7. Method parameters: Parameters of ordinary methods or constructors, whose scope is the entire method.
8. Exception handling parameters: Its scope is a code block immediately following the catch(Exception e) statement.
6. Data conversion type:
1. Automatic type conversion: When a variable of one type is assigned to a variable of another type, automatic type conversion will occur if the two types are compatible and the target type is larger than the source type. The following figure shows the legal conversion between numeric types: (The real arrow is a conversion without information loss, and the virtual arrow indicates that the accuracy may be lost):
2. Casting: Casting is used for explicit type conversion. If the data type of the converted value is greater than its target type, some information is lost. Type casting causes the program to treat the variable as a certain type, although this variable contains another type of data.
Syntax: (target type) The name of the variable to be converted;
Example:
float c = 34.56789f;
int b = (int) c; // Convert c to integer
7. Operator:
1.
Operators | describe | Example |
Arithmetic operators | Arithmetic operators use numeric operands. These operators are mainly used in mathematical calculations | +, -, *, /, % |
Relational operators | Relational operators are used to test the relationship between two operands. The result of an expression using relational operator is boolean | ==, >, >=, <, <= , != |
Logical operators | Logical operators are used for boolean operands | &, |, ^, &&, ||, ! |
Conditional operator | The conditional operator is unique because it is a ternary operator that uses three operands to form an expression. It can replace some type of if-else statement | ? : |
Assignment operator | The assignment operator is an equal sign = which assigns the value to the variable | =, *=, /=, +=, -= |
order | Operators |
1. | Brackets, such as ( ) and [ ] |
2. | Unary operators such as -, ++, - and! |
3. | Arithmetic operators such as *, /, %, + and - |
4. | Relational operators such as >, >=, <, <=, == and != |
5. | Logical operators such as &, ^, |, &&, || |
6. | Conditional operators and assignment operators, such as ?:, =, *=, /=, += and -= |
8. Control flow statement:
1. Judgment statement:
(1). if-else statement:
General syntax:
if (<condition>) { <statement block 1> } else { <statement block 2> } If the condition is true, execute the statement in statement block 1;
If the condition is false, execute the statement after else (the statement in statement block 2).
(2). switch-case statement:
General syntax:
switch (expression) { case 1: statement for operation 1; break; case 2: statement for operation 2; break; …. case n: statement for operation n; break; default: default statement; }Note: The value type of the expression in switch brackets must be a basic type compatible with the int type (including byte, short, char, and int), and the end of each case clause must be followed by a break;
2. Loop statement:
(1). while loop: execute the loop body as long as the specified condition is true. If the condition is false at the beginning, the while loop is never executed. The syntax is as follows:
while (condition){ // loop statement} (2). do-while loop: execute the loop body first, and then test the conditions. The syntax is as follows:
do{ // loop body statement} while (condition); (3). for loop: mainly used to execute statements or statement blocks in a predetermined number of times: The syntax is as follows:
for(initialization; test; update counter){ // Operation statement; } 3. Jump statement:
(1). break interrupt loop
(2). countrye only interrupts this loop
(3). return Exit this method and jump to the upper level to call the method. If the return type of this method is not void, the corresponding return value needs to be provided.
9. Array: Use a data structure that stores a set of data of the same type.
1. The array can be declared in three ways:
(1). Data type [ ] identifier; //Declare an array
(2). Data type [ ] Identifier = new Data type [size]; //Create an array
(3). Data type [ ] Identifier = {value 1, value 2,…value N}; //Declare, create and initialize
2. The first value of the array can be accessed through integer subscripts. For example: a is an integer array, then a[0] is the first element in the array.
3. Once an array is created, it cannot be changed in size.
4. You can use the array name.length to get the number of elements of the array.
5. Multidimensional array:
Two-dimensional array: It is actually an array of arrays.
For example: int [][] arr = new int[2][3]; In this program fragment, two-dimensional array objects with 2 rows and 3 columns are configured. Its configuration relationship can be shown as shown in the figure:
So, based on the above principle, you can create irregular arrays.
10. Command line parameters:
Entry method in Java program: main method has the String[] args parameter, which means that the main method receives an array in a character, that is, the command line parameter.
11. Escape characters:
Escape sequence | name | describe |
/a | warn | Generate a warning. |
/n | Line break | Move the cursor to the first box of the next line. |
/r | Enter | Move the cursor to the first box of the current row. |
/t | Level Table | Move the cursor to the next horizontal tab position. |
/' | Single quotes | Generate a single quote. |
/" | Double quotes | Generate a double quote. |