---- Java programming language Java foundation base composition (2)

1, the function: defines a separate piece applet having a specific function in the class (also referred to as method)
  due to different calculation result data acquisition, repeated code appears, in order to improve reusability of code, the code of the extraction. This part is defined as a separate function for easy access in the future, Java definition of the function is in the form of a function to be embodied.
java function defined in the format:
modifier return type function name (parameter type in the form of parameter 1, parameter-type-1 parameter, ...) {
        execute the statement;
        return return value;}
explained above nouns:
modifier: allows the function have more meaning
return value type: result type of function runs after
the function name: as long as the legal line, the first first letter lowercase
parameter types: a data type of a formal parameter
in the form parameter: is a variable for storing the calling function when the actual parameters passed to the function,
actual parameters: parameters passed to the specific values in the form of incoming method call
return: for terminating the function returns the value: this value is returned to the caller

Function characteristics:
①, function codes defined functions can be encapsulated;
②, to facilitate the multiplexing function;
③, the called function will be performed;
appears ④, improve the function code reusability.
  When the function does not return a specific value, returning void return type is represented by a keyword.
  If the function return value type is void, return statements can be omitted, the system will automatically help you add.
return: for the end of the function. The end of the function.
Note: The function can only call the function, the function can not be defined inside the function;
  when defined function, the function should return the result to the caller, the caller referred to treatment.
Programming is constantly realize the function, while Java is the smallest functional unit function. As long as the line definition function is defined in the function, the main function to the calling function only.

How to define a function?
Function is actually a function, defined function is to realize the function, clearly done by two:
1), a clear result of the operation of the complete function is in fact clear return type of the function.
2) In the process of implementing this function if there are unknown content involved in the operation, in fact, in a clear list of parameters of this function (parameter type and number of parameters).

Overloaded function: In the same class, to allow more than one function of the same name, as long as they have different number of parameters or parameter types can.
Features: non-return type, just look at the list of parameters ---- different function parameter list of the same name that is overloaded

When a heavy load?
  When the same as defined function, but different operations involved unknown content. Well, this is just the definition of a function name to indicate its function, easy to read, and to distinguish between multiple functions of the same name with different argument list.

8, the array: the same type of data set (actually the array is a container).
Define an array in two formats:
1>, the element type [] variable name = new element type [or the number of elements in the array length];
2>, the element type [] = {variable name element 1, element 2 ...};
  element type [] = new element type variable name [] {element 1, element 2 ...};
data with a second clear; not clear with a first, respectively assigned.
Problems that may arise between them:
ArrayIndexOutOfBoundsException (array subscript bounds exception): Operating arrays, access to an array subscript that does not exist.
A NullPointerException (null pointer exception): When the reference point is not the case any null value, this reference is also for operating entity.


Java altogether divided in memory at startup five space to store your data:

   栈内存(栈区)、堆内存(堆区)、方法区、本地方法区、寄存区

Stack memory: local variables in the stack memory. Data use, will be released automatically.
Heap memory: heap memory are stored entities: arrays and objects. Heap memory data have default initialization value, data recovered by the garbage collection mechanism.

Two-dimensional array:
  int [] arr = new new int [. 3]; // one-dimensional array
  int [] [] arr = new new int [. 3] [. 4]; // defines the name of a two-dimensional array arr, two-dimensional the array has a three-dimensional array; one-dimensional array in each of four elements.
  ARR [. 1] [2] = 78; // second one-dimensional array assigned to the third element 78
  arr.length // dimensional array length
  arr [0] .length first two-dimensional array // one-dimensional array length


In this chapter important code demonstrates:

// for loop nest: 99 multiplication table to print
Print 99 multiplication table
the results:
Here Insert Picture Description
// remaining functions in the array operations inside the demo are included
to find // array: the general look both binary search

Here Insert Picture Description
Here Insert Picture Description
Operation result:
Here Insert Picture Description
Sort // array: java own method, sort and select Customize bubble sort
Here Insert Picture DescriptionHere Insert Picture Description
operation result:
Here Insert Picture Description
  This article is based on java foundation courses Auspicious teacher summary, please indicate.

Guess you like

Origin blog.csdn.net/weixin_39771344/article/details/91550675