Java--Several simple concepts of object-oriented programming language (OOP)

Source: Internet
Author: User
Java is an object-oriented programming language (OOP), and everything is an object.

Several concepts:

1. References, references are used to manipulate objects, manipulation objects need to be referenced to complete, for example, the remote control (reference) controls the TV (object), can exist independently of each other.

String s = "ASDF"; Create reference and initialize.

string s = new String ("Asdf"), and the reference is associated with the object.

2. Basic type, different from the referenced variable creation,

Including:

Boolean,char,byte,short,int,long,float,double,void.

3. Scope, scope determines the life cycle, and the scope of the variables defined therein.

4. Classes, classes determine the appearance and behavior of a class of objects, which is a collection of similar objects. In layman's terms, a class is a set of basic types for some objects.

Class a{

/**asjgjhg/

} Create Class

A B = new A ();//Create objects of this type

5. Methods and fields, methods, and fields are members of the class.

Class a{

int i;

Double D;

}//class with some fields

Although there is no method for this class, nothing can be done, but the object can still be created

A data = new A ();

Assigning a value to a field

DATA.I = 1;

DATA.D = 1.1;

6. Method, parameter, return value, method is the function, the basic composition of the method includes: name, parameter, return value, method body.

Basic form:

ReturnType (return type) methodName (/* parameter list */) {

/*method body*/

}

Assuming that the return type is int and the argument list is empty, an object A calls the method, int x = A.methodname ();

The parameter list, which is the information passed to the method.

7.static, the description of the global variable (the external variable) is then prefixed with static, which constitutes the global variable. Global variables themselves are static storage, and static global variables are, of course, static storage methods. The two are not different in how they are stored. The difference between the two is that the scope of the non-static global variable is the whole source program, when a source program consists of multiple source files, non-static global variables are valid in each source file. A static global variable restricts its scope, which is valid only within the source file that defines the variable, and cannot be used in other source files of the same source program. Because the scope of a static global variable is limited to one source file, it can be common only for functions within that source file, so you avoid causing errors in other source files.

From the above analysis, it can be seen that changing the local variable to a static variable changes its storage mode, which changes its life time. Changing a global variable to a static variable changes its scope and limits its scope of use.

The static function differs from the normal function scope. Only in this document. Functions that are used only in the current source file should be described as intrinsic (static) and intrinsic functions should be described and defined in the current source file. For functions that can be used outside of the current source file, it should be stated in a header file that the source file to which the function is to be used is to contain the header file

What is the difference between a static global variable and a normal global variable: the static global variable is only initialized once, preventing it from being referenced in other file units;

What is the difference between a static local variable and a normal local variable: the static local variable is initialized only once, the next time based on the last result value;

What is the difference between a static function and a normal function: The static function has only one copy in memory, and the normal function maintains a copy of each call.

Summary of this chapter: the form of a Java program

Import java.util.*; Reference other components, guide package

Class classname{//Create a classes that contain member methods, fields

int method () {//Create a way

/* contains various commands in the method */

}

}

Related Article

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.