1. Keywords
Boolean, break, Byte, case, Char, class, continue, default, do, double, else, final, float, For,goto, if, import, int, Lon G, new, package, private,protected, public, return, short, static, switch, this, void, while, abstract, catch, const, exte NDS, Assert, finally, implements, instanceof, interface, native, STRICTFP, Super, Synchronized,throw, throws, transient, t RY, volatile
2. Reserved words
True, FALSE, NULL
3. Identifiers
Naming rules: A. Identifiers can contain letters, numbers, underscores, dollar signs
B. Identifiers cannot be keywords or reserved words
C. Identifiers cannot begin with a number
D. Identifiers are case-sensitive and do not specify a maximum length
For example: identifier, user_name, _sys_varl, $change, etc.
Naming conventions: A. " "(Choose concise English words as identifiers)
B. Each word starts with a lowercase letter, the first letter of the second word is capitalized or the first letter of each word is uppercase (camel-named)
For example: Mystudentcount, Databaseuser
c. Words are not separated by a space break or connection number (-), the bottom line (_), the first letter of each word (Pascal nomenclature)
For example: FirstName, UserName
4. Data type
Base data type: Numeric (Integer (Byte, short, int, long), float (float, double)), character (char), Boolean
Reference types: Class, Interface (interface), arrays, strings (string)
Note: Strings are denoted by double quotation marks for character literals, such as "A", which declares strings with string name;
"+" in the string to connect the literal
Table-java Basic data types
Data type |
Key words |
Size |
BYTE type |
Byte |
1 bytes (8 bits) |
Short-integer |
Short |
2 bytes (16 bits) |
Long integer type |
Long |
8 bytes (64 bits) |
Single-precision |
Float |
4 bytes (32 bits) |
Double-precision Type |
Double |
8 bytes (64 bits) |
Integral type |
Int |
4 bytes (32 bits) |
Character type |
Char |
2 bytes (16 bits) |
Boolean type |
Boolean |
Not sure |
Note: The Boolean value is True, False
5. Constants
Final data type constant name = constant value;
For example: Final double PI = 3.14159;
6. Casting
The cast operator consists of a data type of a strong conversion that is placed in parentheses. ();
When a numeric data expression performs a calculation, an automatic type conversion is performed from low precision to high precision, that is, byte < short < int < long < float < double.
For example: int x;
Double d = 3.5;
x = D; cannot be compiled by
x = (int) d; can be compiled by
Escape character for 7.Java
\b: Backspace
\ t: Tab
\ n: Line break
\ r: Enter
\ ": Double quotation marks
\ ': Single quote
\ \: Back slash
8. Operators
Operators and Precedence in Java
Operator classification |
operator |
Pre-or post-increment/decrement |
+ + 、-- |
Unary operators |
+ 、-、 ~,! , (CAST) |
Multiplication/Division/Modulus |
*、/、% |
Add/subtract/String connections |
+ 、-、 + |
Shift Operators |
<<, >>, >>> |
Comparison operators |
<, <=, >, >=, instanceof |
Equality operators |
= =,! = |
Bitwise operators |
&, |, ^ |
Conditions and, or |
&&, | | |
Trinocular operator |
? : |
Assignment operators |
= |
Extended assignment operators |
*=,/=,%=, + =,-=, <<=, >>=, >>>=, &=, ^=, |= |
A. Increment and decrement operators
A. Pre-increment
For example: int x = 5;
int z = ++x;
Output: x = 6 z = 6;
B. Post-increment
For example: int x = 5;
int y = x + +;
Output: x = 6 y = 5;
B. Three-mesh operator
Syntax form: (Boolean expression)? x:y;
For example: (x = = 5)? "Yes": "No"; If x equals 5, then "Yes" is displayed, otherwise "no" is displayed.
Using the If/else statement: if (x = = 5) {
SYSTEM.OUT.PRINTLN ("yes");
}else{
System.out.println ("no");
}
9.Java comments
Single-line Comment://
Multi-line Comment:/*......*/
Text/Document notes:/**......*/(primarily written on a class or method)
Java Basic syntax