This is the 16th day of my participation in the More text Challenge. For more details, see more text Challenge
Identifier rules
- Identifier a sequence of characters beginning with a letter, underscore _, or $.
- The first character cannot be a number
- The identifier cannot be a keyword
- Case sensitive, no length limit
Naming conventions
- All package names will be lowercase.
- Capitalize the first letter of the class name and interface word. Such as class AccountBook
- Constant names are all uppercase, with words separated by ‘_’ (underscore). Such as: MAXIMUM_SIZE
- A variable name with the first letter of the first word in lowercase followed by the first letter of the first word in uppercase. Such as int anyVariableWord;
Basic data type
8 species in 4 classes
- Logic: Boolean (1 bit)
- Text: char (16 bits)
- Integer: byte (8), short (16), int (32), long (64)
- Float: float (32), double (64)
Reference type variable
Class, interface array are all reference type variables
The String class
- String is not a primitive type but a class. In Java, strings are objects. Strings can be represented by: String and StringBuffer. In Java, strings do not end with ‘\0’.
- If you want to modify a String, you should use the StringBuffer class.
Basic types and reference types
References in other languages are called Pointers or memory addresses.
When a variable of reference type is declared, only reference space is allocated to the variable, not data space. We need to allocate data space
Basic type mixing operations convert precedence
byte –> short–>char–>int –>long–>float–>double
Low level is automatically converted to high level
Note:
- Even if both operands are byte or short, they are converted to ints
- The divisor of/and % cannot be 0
- % modulus can be used to perform operations with floating point numbers. 3 = 0.5 9.5%
- + allows string concatenation
Logical operations: && and &, | | and |
- &&, a&&b evaluates the value of a on the left hand side first, and only evaluates the value of b if a is true. While the a&n. Whether a is true or not, it calculates b.
- | | | and the above in the same way.
An operation
A logical
- Op1 & OP2 (false is false, same true is true)
- Bitwise and | : op1 | op2 (the same is true is true, false false)
- Xor by bit ^: op1^op2 (same true or same false is false, one true one false is true)
- Invert by bit ~ :
A shift
- Move right >> : OP1 >> OP2 Move OP1 right by two bits
- Left <<: Same
- Unsigned right move >>>: OP1 >>> OP2 OP1 Right move OP2 (unsigned)
Enhanced for loop
After JDK5.0, it is easy to iterate the elements of arrays and collections
// Format: for (element type identifier: iterable expression) statement;
int []numbers={1.2.3.4.5.6};
for(int element :numbers){
System.out.println(element);
}
Copy the code
The break statement is labeled
Flag:for(int i=0; i<10; i++){for(int j=0; j<10; j++){if(...).break flag;/// Jump the entire flag directly.}}Copy the code
An array of
- Array [] comes with.length
- Multidimensional arrays can construct irregular arrays.
int a[][]=new int [2] [];// Only the last dimension can be left out Copy the code
- The arrayCopy method in the Java.lang. System class is recommended for array data replication
public static void arraycopy(Object source,// source arrayintSrcIndex,// Start location of the copy Object dest,// target arrayintDestIndex,// The start bit of the destination arrayint length)/ / the length Copy the code