A, Java main class structure

1, the basic components

The basic unit is composed of Java classes, class body also includes properties and methods.
Each application must contain a main () method, comprising main () method is called class - main class

package Number
public class First{
    static String s1 = "您好"
    public static void main(String[] args){
        String s2="Java";
        System.out.println(s1);
        System.out.println(s2);
    }
}

File names must be the same name as the class that First.java case-sensitive, java case-sensitive.

Package declaration, a java program consists of a number of classes, so the package where it is kind of where the package keyword, the package called Number.

2, variable declaration

  1. Global variables: type attribute, declared in the class body. (Also known as member variables)
  2. Local variables: the method attributes declared in the method body.

3, the preparation of main () method

  1. public, static, void permission modifier are main () method, the static modifier, the return value modifier.
  2. main () method must be declared as public static void.
  3. String [] args an array of type string. Is the main () parameters.

Guess you like

Origin www.cnblogs.com/hasz/p/12194603.html