Annotation
- Single line comment[//]
- Multi-line comment[/* */]
- Documentation comments[/** */]
Identifiers and keywords
1. Identifiers are composed of alphanumeric underscores, cannot start with numbers, and cannot have keywords
2. Keywords have been used in Java
3. Common keywords: class public main static...
type of data
1. Roughly divided into basic data types and reference data types
Type conversion
1.
2. Automatic type conversion: low-high
3. Can not convert the Boolean value type
4. There may be memory overflow or accuracy problems
during conversion . 5. JDK7 has a new feature that can be separated by underscores between numbers, such as 10 —0000—0000, still 1000000000 when output
variable
- The amount that can be changed
- Every variable must be declared type
- The variable name must be a legal identifier
- Variables are divided into: class variables, instance variables, local variables
public class Demo{
static int s=2; //类变量
string str="hello"; //实例变量
public void method(){
int i=0; //局部变量
}
}
constant
- The amount that cannot be changed
Naming conventions
- All variables, methods, class names: see the name know what it means
- Class member variables: first letter lowercase and camel case principle: monthSalary
- Local variables: lowercase initials and camel case
- Constants: uppercase letters and underscores
- Class name: initial capitalization and camel case principle: M I, GoodMan
- Method name: lowercase initials and camel case principle: sun(), sunYuZhuo()
Operator
- Ternary operator (x? y: z)
- Many operations will use tool classes to operate (math class)
- Operator precedence
Packet mechanism
- Generally use the company domain name to make the package name (com.sun.base)
- Import package (import java.util.Date)
- Import all the classes under the package (import java.util.*)
JavaDoc
- @author author name
- @version version number
- @since refers to the jdk version that needs to be used earliest
- @param parameter name
- @return return value situation
- @throws exception throw situation