The first stage 13 code block static main method help documentation singleton

1. Code block

  1. Definition

    It is the code enclosed by a pair of {}

  2. Classification and details

    A: Local code, used locally, can release memory in time and improve efficiency.

    B: Construction code block: The construction code block is automatically called when each construction method runs, and all objects can be initialized

    C: static code block: executed as the class is loaded, and only once, before the main method

    

Suppose we have a Person object. What exactly does Person p = new Person(); do in memory?

step

                  A: Load the Preson.class file into memory.

                  B: Create a small space in the stack memory space to store the p variable.

                  C: Allocate space in heap memory. Create objects.

                  D: Default initialization of member variables in the object.

                  E: Execute the construction code block, if there is no construction code block, do not execute.

                  F: Assign values ​​to member variables in the object.

                  G: The object construction is initialized.

                  H: Assign the first address of the object in the heap memory to the stack memory variable p.

 

Two: staitc

  1. Concept

    Static meaning, used to modify members

  2. Features

    Loaded as classes are loaded

    takes precedence over the existence of the object

    shared by all

    Can be called directly by the class name

  3. Precautions

    A: Static members can only access static members

    B: There cannot be this and super keywords in static methods

    C: main function is static

  4. The difference between static variables (static modified member variables) and non-static variables

   

A: Static variables are loaded as the class is loaded and disappear as the class disappears. Longest life cycle.

                     非静态变量随着对象的创建而存在,随着对象的消失而消失。

B:静态变量和类相关,是所属于类的,可以直接被类名调用,也可以被对象名调用。也称为类变量。

非静态变量和对象相关,是所属于对象的,只能被对象名调用。称为实例(对象)变量。

                  C:静态变量存储于方法区中的静态区。

                     非静态变量存储于对象的区域,在堆内存中。

                  D:静态变量的数据被所有的对象共享。

             非静态变量是每个对象特有的数据

 

三、主方法

public static void main(String[] args){ }

 

(1):public 公共的权限修饰符。

 

(2):static 静态的。

 

(3):void 返回类型是空的。

 

(4):main jvm的入口。

 

(5):String[] args

 

         字符串数组元素的值是什么?

 

         A:args中有没有元素呢?就是判断长度是否为0。

 

         B:长度为0,有用吗?干什么啊?没用,但是我们可以给args赋值。

 

         C:我们还可以给args赋值

 

四、制作帮助文档

1.类中的内容加入文档注释。

2.如果制作呢:

            javadoc -d arrayTool -author -version ArrayTool.java

                        javadoc 是解析文档注释并生成说明书的工具的名字

                        -d arrayTool :-d后面跟的是目录

                        -author -version: 提取author,version。

                        ArrayTool.java 文件名

3.出现问题

                        正在创建目标目录: "arrayTool\"

                        正在装入源文件 ArrayTool.java...

                        正在构造 Javadoc 信息...

                        javadoc: 错误 - 找不到可以文档化的公共或受保护的类。

                        1 错误

                        如何解决呢?把class前面加个权限修饰符public

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324886181&siteId=291194637