2021-2-28 Java Basics

Annotation

  1. Single line comment[//]
  2. Multi-line comment[/* */]
  3. 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. Type priority
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

  1. The amount that can be changed
  2. Every variable must be declared type
  3. The variable name must be a legal identifier
  4. 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

  1. The amount that cannot be changed

Naming conventions

  1. All variables, methods, class names: see the name know what it means
  2. Class member variables: first letter lowercase and camel case principle: monthSalary
  3. Local variables: lowercase initials and camel case
  4. Constants: uppercase letters and underscores
  5. Class name: initial capitalization and camel case principle: M I, GoodMan
  6. Method name: lowercase initials and camel case principle: sun(), sunYuZhuo()

Operator

  1. Operator
  2. Ternary operator (x? y: z)
  3. Many operations will use tool classes to operate (math class)
  4. Operator precedence

Packet mechanism

  1. Generally use the company domain name to make the package name (com.sun.base)
  2. Import package (import java.util.Date)
  3. Import all the classes under the package (import java.util.*)

JavaDoc

  1. @author author name
  2. @version version number
  3. @since refers to the jdk version that needs to be used earliest
  4. @param parameter name
  5. @return return value situation
  6. @throws exception throw situation

Guess you like

Origin blog.csdn.net/qq_52332852/article/details/114214857