1.switch: The accepted type has a byte short int char (for a specific numeric value, but not much.) )
When the condition is established, the statement after the case is executed, and if no break is encountered after execution, or '} ', the execution of the executed statement will continue to execute, and the condition will not be judged until a break is encountered again, or '} '.
2. Looping statements:
①while (conditional expression)
{
Loop body (execution statement);
}②do
{
Loop body (execution statement);
} while (conditional expression);
③for (initialization expression; cyclic conditional expression; post-loop action expression)
{
Execute the statement;
}
The difference between 2.1.while and for about variables:
The variable has its own scope. For the for: if the increment that is used to control the loop is defined in the For statement, then the variable is valid only within the FOR statement. The For statement is executed and the variable is freed in memory.
2.2 For and while can be interchanged. If you need to define a loop increment, use for is more appropriate.
3. Function: A separate applet, also known as a method, that defines a specific function in a class.
3.1 Format of the function:
Modifier returns a value type function name (parameter type form parameter 1, parameter type parameter 2,...)
{
Execute the statement;
return value;
}
Return value type: The data type of the result after the function is run.
Parameter type: is the data type of the formal parameter.
Formal parameter: is a variable that stores the actual arguments passed to the function when the function is called.
Actual parameter: The specific value passed to the formal parameter.
return: Used to end the function.
Return value: The value is returned to the caller. (identified with the keyword void when the function does not return a specific value.) )
3.2. Overloading of functions: in the same class, more than one function with the same name is allowed, as long as the number of arguments or the type of the parameter is different.
Overload specific: Regardless of the return value type, see only the parameter list (also related to the parameter order).
Benefits of overloading: easy to read, optimized for programming.
overloading Example:
Returns two integers and a
int add (int x, int y) {return x+y;}
Returns three integers and a
int add (int x, int y,int z) {return x+y+z;}
Returns two decimals and
Double Add (double x, double y) {return x+y;}
4. Memory Structure:
When a Java program runs, it needs to allocate space in memory. In order to improve computational efficiency, space is divided into different regions, because each region has a specific way of processing data and memory management.
Stack memory: Used to store local variables, and when the data is used up, the occupied space is automatically freed.
Heap Memory:
1> Arrays and objects are stored in heap memory by the instances created by new.
2>. Each entity has a memory address value.
3> The variables in the entity have default initial values.
4> Entities are not being used and are reclaimed by the garbage collector for an indeterminate period of time.
5. Array (reference data type): A collection of data of the same type. The array is actually a container.
The benefits of arrays: You can automatically number the elements in the array starting with 0 to facilitate manipulation of these elements.
Format 1:
element type [] Array name = new element type [element number or array length];
Eg:int [] arr = new INT[5];
Format 2:
element type [] Array name = new element type [] {element, element, ...};
Eg:int [] arr = new int[]{1,2,5,3};//creates an entity in the heap memory space and assigns a specific value to each element.
int [] arr = {1,2,5,3};//data can be abbreviated in case of explicit
New function: Used to generate a container entity in heap memory.
int [] Arr:int represents the type of the element; [] table array; Arr represents the array type. ARR is an array variable in the stack memory that is actually assigned the address of the array in the heap memory, in addition arr is in the stack memory, and then gets the container entity address that new creates in heap memory, pointing to the array in the heap memory.
java--Base Statement