[Detailed + super basic] Java-study notes 01

The blogger has already learned C++
This article is the basic knowledge point of C++ transition Java

1. Method

1. Method format:

Modifier return value type method name (parameter type parameter name,...) {

Method body

return return value;

}

Description:

Modifier: public static

Return value type: what type of data result the method finally produces

Parameter type: what type of data is entered into the method

Parameter name: the variable name corresponding to the data entered in the method (if there are multiple parameters, use commas to separate)

Method body: what the method needs to do, several lines of code

return: One can stop the current method and the other is to return the return value to the caller

Return value: the final data result after the method is executed

2. Three calling formats:

1. Separate call: method name (parameter)

2. Print call: System.out.println (method name (parameter))

3. Assignment call: int num=method name (parameter)

3. Precautions for usage:

1. The method should be defined in the class, but the method cannot be defined in the method, and cannot be nested

2. The order of the method definition does not matter. The method will not be executed after the method is defined. If you want to execute it, you must call

3. If the method has a return value, there must be a "return return value" and the return value data must be consistent with the return value type

4. Method Overload:

: Multiple method names are the same, but the parameter lists are different

For methods with similar functions, because the parameter lists are different, you need to remember too many method names and the trouble of calling multiple methods. Method overloading can implement one method name to achieve multiple similar functions

**Precautions**

Method overloading is related to the following factors: Method overloading has nothing to do with the following factors

1. The number of parameters is different 1. It has nothing to do with the parameter name

2. The parameter type is different 2. It has nothing to do with the return value of the method

3. The order of multiple types of parameters is different

Two, Array

1. Array concept and characteristics:

A container that can store multiple data groups at the same time

Features:

1. Array is a reference data type

2. The types of multiple data in the array must be unified

3. The length of the array cannot be changed during the running of the program

2. Initialization of the array:

Create an array in the content and assign some default values ​​to it

Two common initialization methods:

1. Dynamic initialization (specify length)

2. Static initialization (specify content)

The format of the dynamic initialization array:

Data type [] Array name = new data type [Array length];

Explain the meaning:

Data type on the left: the type of data stored in the array

Brackets on the left: it means this is an array

New on the right: represents the action of creating an array

Data type on the right: the same as the left

The format of static initialization array:

Data type [] Array name = new data type [] {element 1, element 2,...};

Data type [] Array name = {element 1, element 2...};

3. The basic use of arrays

Three, memory in Java

Memory division in Java (5 parts)
1. Stack (Stack): Stores all local variables in methods. The method must run in the stack.

​ Local variables: method parameters, or variables inside the method {}.

​ Scope: Once it exceeds the scope, it immediately disappears from the stack memory.

2. Heap: all new things are in the heap

Everything in the heap memory has an address value: hexadecimal.

The data in the heap memory has default values. rule:

Integer defaults to 0

Floating point number defaults to 0.0

The character defaults to'\u0000'

Boolean defaults to false

The reference type defaults to null

3. Method Area (Method Area) : store class-related information, including method information.

4. Native Method Stack (Native Method Stack): related to the operating system.

5. Register (pc Register): related to CPU.

Guess you like

Origin blog.csdn.net/qq_51808107/article/details/112910075