Identifiers in Java
Composition: number, letter, underscore, dollar $ symbol.
Rule: Cannot start with a number.
Class Name: Capitalize the first letter of each word
Package Name: All lowercase
Variable name, method name: first letter lowercase. Capitalize the back letter
Constants: All uppercase underline connections
Gaze
Single Gaze://
MultiRow gaze:/... /(not nested)
Document Gaze:/* ... .. /(can be parsed into an HTML document (instruction manual) by the Javadoc command)
Variable overview
Format one:
Variable name of data type = initialization value;
Format two:
Data type variable name;
Variable name = initialization value.
Variables must be initialized before they are used.
Data types in Java
Integer: Byte 1 bytes
Short 2 bytes
Int 4 bytes
Long 8 bytes
Float type: float 4 bytes
Double 8 bytes
Character type: Char 2 bytes
Boolean Type: Boolean
Define variables in Java and use the
The assignment of a variable of type Byte,short is guaranteed within its scope. (out of range error)
You must add L and f after assigning a variable of type float to long.
Data type conversions
1) Self-initiated type conversion (implicit conversion)
byte Char short–int–long–float–double
2) Forced type conversion (explicit conversion)
(data type) variable or constant value;
BYTE B1 = 3;
byte b2 = 4;
BYTE B3 = b1 + b2; This line will give an error, because the byte type of the operation will be actively promoted to the int type, possibly losing precision.
byte B4 = 3 + 4; No error, for literal constants 3 and 4, the JVM calculates (optimizes) it at compile time, and evaluates whether the value is within the byte range, assuming that it does not exceed the error.
Arithmetic operators
note:
1) Note that except for operator ,
1) The divisor cannot be calculated for 0. ,
2), and the result is shaping. It will discard the remainder.
For example: 5/ The result is 2
2) + + and – operator principle
Take + + as an example:
separate operation:
is the same as before, which is equivalent to adding the value 1
Participation and Operation:  
+ + Before the first, add and then use. ++a is equivalent to a = a + 1
+ + is followed by a plus. a++ generates a temporary amount, which is the equivalent of a copy of a, and then increases the value of a, returning the value of the copy.
Example:
int x = 10;&nbs P
int y = x++;
//The result is y = ten; x = one;
- int x = 10; - a = a++; - System.out.println(a); // 结果是10
3) Special use of the addition operator:
For example: System.out.println (3 + 4 + "Hello" + 5 + ' a ' + 6 + 7); The output is: 7hello5a67
logical operators
注意: 1) java中不能写成 1 < x < 9 , 而应该写成 x > 1 & x < 9 2) & 和 && 的差别: 单&时,左边不管真假,右边都会參与运算. 双&时,左边为真时,右边才会參与运算;左边为假时,右边不会 參与运算,有短路功能. 3) | 和 || 的差别同理: 对于双或,左边为真时,右边不会參与运算.
Bitwise operators
<< 左移 -- 将运算数的二进制码总体左移指定位数,左移之后的空位用0补充. 相当于乘以2的指定次幂.>> 右移 -- 将运算数的二进制码总体右移指定位数,右移之后的空位用符号位补充,假设是正数用0补充,负数用1补充.相当于除以2的指定次幂.>>> 无符号右移 -- 将运算数的二进制码总体右移指定位数,无论正负,空位所有都用0补充.注意: 1) 没有无符号左移. 2) API中非常多源代码的实现都是採用了位运算符,由于效率高.但咱们开发中自己敲代码一般不会用,易读性差.关于位运算的两个面试题: 1) 用最高效的方式计算2*8的结果. 2 << 3 2) 不使用第三个变量的前提下,交换两个变量的值. int a = 10; int b = 20; // 结果要求: a = 20; b = 10; a = a ^ b; b = a ^ b; a = a ^ b;
Process Control Statements
switch语句注意事项: a:default总体能够省略吗? 能够,可是不建议。 b:default的位置能够放到前面吗? 能够,可是不建议。
c:break能够省略吗? 能够,可是不建议。 default在最后。break是能够省略的。 case后面的break能够省略。可是结果可能有问题。 d:switch语句什么时候结束呢? 就是遇到break或者运行到程序的末尾。
Java Foundation for its own weaknesses summary 01 (prior to the cycle of knowledge)