This is the 16th day of my participation in the More text Challenge. For more details, see more text Challenge


Identifier rules

  1. Identifier a sequence of characters beginning with a letter, underscore _, or $.
  2. The first character cannot be a number
  3. The identifier cannot be a keyword
  4. Case sensitive, no length limit

Naming conventions

  1. All package names will be lowercase.
  2. Capitalize the first letter of the class name and interface word. Such as class AccountBook
  3. Constant names are all uppercase, with words separated by ‘_’ (underscore). Such as: MAXIMUM_SIZE
  4. 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
  1. Logic: Boolean (1 bit)
  2. Text: char (16 bits)
  3. Integer: byte (8), short (16), int (32), long (64)
  4. Float: float (32), double (64)

Reference type variable

Class, interface array are all reference type variables

The String class
  1. 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’.
  2. 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:

  1. Even if both operands are byte or short, they are converted to ints
  2. The divisor of/and % cannot be 0
  3. % modulus can be used to perform operations with floating point numbers. 3 = 0.5 9.5%
  4. + allows string concatenation

Logical operations: && and &, | | and |

  1. &&, 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.
  2. | | | and the above in the same way.

An operation

A logical
  1. Op1 & OP2 (false is false, same true is true)
  2. Bitwise and | : op1 | op2 (the same is true is true, false false)
  3. Xor by bit ^: op1^op2 (same true or same false is false, one true one false is true)
  4. Invert by bit ~ :
A shift
  1. Move right >> : OP1 >> OP2 Move OP1 right by two bits
  2. Left <<: Same
  3. 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

  1. Array [] comes with.length
  2. Multidimensional arrays can construct irregular arrays.
int a[][]=new int [2] [];// Only the last dimension can be left out
Copy the code
  1. 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