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, lower first letter uppercase
Constants: All uppercase with underline connection
Comments
Single-line Comment://
Multi-line Comment:/... /(not nested)
Documentation Comments:/* ... .. /(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
Assigning a variable of type Byte,short is guaranteed within its range. (out of range error)
You must add L and f after assigning a variable of type float to long.
Data type conversions
1) automatic 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 that participates in the operation is automatically promoted to type int, possibly losing precision.
byte B4 = 3 + 4; No error, for literal constants 3 and 4, the JVM computes (optimizes) it at compile time, and compares its value to a byte range, without error if not exceeded.
Arithmetic operators
Note:
1) note except operator  
2) shaping and shaping, The result is still plastic. It will discard the remainder.  
example: 5/2– result is 2
2) + + and – operator principle
single operation:  
in front of all the same, equivalent to the value plus 1 
participate in the operation:  
++ in front, first add after use. ++a equals a = a + 1 
++ after the first use after adding. a++ will produce a temporary amount, which is equivalent to a copy of a, and then increment the value of a to return the value of the copy.  
example:
int x = 10;
int y = x++;
//result is y = ten; x = one;
- int x = 10; - a = a++; - System.out.println(a); // 结果是10
3) Special usage 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或者执行到程序的末尾。
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Foundation for its own weaknesses summary 01