Java Self-study note (sixth day)

Source: Internet
Author: User

(*)static (invariant)- keyword: A modified variable is called a class variable that loads as the class is loaded and disappears as the class disappears.

The members of the static modifier are called static members (invariant members, class members),

Not only can be called by the object, but also can be called directly by the class name

shared by all objects

Precedence over the existence of objects

(*) The difference between a class variable and an instance variable :

Different storage locations, class variables in the method area and instance variables in heap memory

The life cycle is different, the class variable and the similar, the instance variable and the instance are in the same

(*) Static use precautions:

Static members can access static members only , and non-static members have access to static and non-static members

The static method cannot use the This and Super keywords because static does not take precedence over the existence of the object so this is not available in static

The main function is static

(*)main- function: public static void Main (string[] args), a special function, as the entry of the program, is called by the JVM

Public: Access Modifiers

Static: Invariant member, as the existence of the class exists

void: The return type is void

Main: Not a keyword, but a special word that is recognized by the JVM

(string[] args): Parameter list, an array of type String, the args variable name can be changed

The main function is a fixed format and is recognized by the JVM

The following code is correct

(*) When to define a static variable, the static function

When the value of a variable is shared by all objects, the variable can be defined as a static variable

The function can be defined as a static function when only a static variable is involved in a function or when no variable is involved.

Members that are modified by static are class members

(*) set the class file path (the path where the. class file is located) on the cmd command line set classpath=.;    C: \; , (.) indicates a lookup in the current directory, and C: \ Indicates a directory lookup in the drive.

(*) make a Javadoc document (a description of the. class file), build the Javadoc document with Javadoc.exe compilation, cmd command-line commands javadoc-d-author-version Xx.java

Syntax for adding comments to a class:/** @author @version ... @param @return */

(*) A static block of code that executes as the class is loaded and executes only once to initialize the class.

Format:

static{

Code

}

static code block, which constructs the execution order of the code block : The constructor that is called when the class---->static code block is loaded---->new object----> Constructs a code block---->new

Classes are loaded only when the contents of the class are used, for example: class name xx = null; This class is not loaded, the XX object variable is meaningless, and the static code block in the class is not executed.

Java Self-study note (sixth day)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.