“This is the 26th day of my participation in the November Gwen Challenge. See details of the event: The Last Gwen Challenge 2021”.

function

By return value type: Void method name (){} Method name (){return value type} Void/Return value type Method name (){} With parameter modifier void/ return value type Method name (parameter list){} Function overload: In a class, if the method name is the same, the number of parameters is different, or the parameter type is different, it is called overload. Remember that overloading only looks at the number and type of arguments, not the return value, not the modifier.Copy the code

An array of

An array can be thought of as a container that holds data. An array is a container that holds data of the same type. Note: Array length is immutable format: type [] array name =new type [specify length]; Type [] Array name =new type []{values 1, 2, 3..... }; Type [] Array name ={value 1, value 2.... }; Arrays are continuous containers of data of fixed length, and they all have subscripts that can be used to find values. Java memory allocation: The JVM divides Java code into five fast regions, which make it easier for the JVM to manage our Java code. Stack space: local variables defined in a class or method (small scope, destroyed when used) 2. Heap space: the space where objects that are new are stored and where a memory address is allocated. 3. Method area: Stores class-related attributes and values. 4. Native Method Stack: OS dependent 5. PC Register: CPU related.Copy the code

Base data types and reference data types

In Java, types are divided into two big blocks, one is the basic data type (eight). All types other than the basic data type are called reference data types. Basic data types have default values if no values are assigned during initialization integer :byte short int long Default value 0 float :float double default value 0.0 Boolean: Boolean Default value flase Character type: char Default value: '\ u0000' Spaces; Reference data types default to NULL if they are not assigned at initializationCopy the code

An array of API

Create:1.Dynamic initialization: When initialized, no value is assigned to the contents of the array/*** * dynamic initialization: when it is initialized, no value is assigned to it. The programmer can assign a value to it dynamically. * /
	public class initone {
	    public static void main(String[] args) {
	         int[] arr =new int[10];
	         arr[0] =10;
	         arr[2] =15; }}2.Static initialization: When initialized, the contents of an array are assigned a value directly/*** * directly assigns */ when initialized
	public class inittwo {
	    public static void main(String[] args) {
	        int[] arr =new int[] {1.5.10}; }} : array name [subscript]= XXX; Get length: The array provides a length property to get its length system.out.println (arr.length); Get elements: system.out.println (arr[1]); Traversal elements:/*** * primitive for loop */
    int[] arr =new int[] {1.10.8.15.22};
    for(int i=0; i<arr.length; i++){ System.out.println(arr[i]); }/*** * enhance for */
    for(int i:arr){
        System.out.println(i);
    }
Copy the code

Exceptions: Exceptions refer to errors that occur in the permitted process of the program. Exceptions are generally divided into two types: one is the exception that can be found during compilation, and the other is the exception that can only occur when execution is required. Therefore, exceptions are generally divided into compile-time exceptions and run-time exceptions.

In an array of common Exception: 1. The Angle of the cross-border Exception: the Exception in the thread "is the main" Java. Lang. ArrayIndexOutOfBoundsException: 5 2. Null pointer Exception: the Exception in the thread "is the main" Java. Lang. NullPointerExceptionCopy the code

Array sort:

Bubble sort:package com.ly.array;

	/** ** ** ** */
	public class maopaosort {
	    public static void main(String[] args) {
	        int[] arr =new int[] {10.2.5.8.1.22};
	        for(int x=0; x<arr.length; x++){for(int y=0; y<arr.length-1-x; y++){int temp=0;
	                   if(arr[y]>arr[y+1]){
	                       temp=arr[y];
	                       arr[y]=arr[y+1];
	                       arr[y+1]=temp; }}}for(int i:arr){
	            System.out.print(i+"\t"); }}} select sort:public static void main(String[] args) {
    int[] arr =new int[] {10.2.8.19.5.7.3};
    for(int i=0; i<arr.length-1; i++){/*** * i=0 y=1 y=2 y=3 y=4 y=5 y=6 * i=1 y=2 y=3 y=4 y=5 y=6 * i=2 y=3 y=4 y=5 y=6 * i=3 y=4 y=5 y=6 * i=4 y=5 y=6; * i=5 y=6 */
        for(int y=i+1; y<arr.length; y++){int temp=0;
            /*** * subscripts 0 and 1 de-ratio the maximum value to 1 minimum value 0 * subscripts 0 and 2 de-ratio the maximum value to 2 minimum value 0 * subscripts 0 and 3 de-ratio the maximum value to 3 minimum value 0 **.... * subscript 0 and 6 to compare * subscript 1 and 2 to compare * subscript 1 and 3 to compare * subscript 1 and 4 to remove glue *... Subscript 1 and subscript 6 compare */
            if(arr[i]>arr[y]){ temp=arr[i]; arr[i]=arr[y]; arr[y]=temp; }}}for(int x:arr){
        System.out.print(x+"\t"); The JDK also provides a sort class for quick sorting of Arrays using sort();public static void main(String[] args) {
        int[] arr =new int[] {18.6.2.15.3};
        / / sorting
        Arrays.sort(arr);
        /** * ascending */
        for(int i=0; i<arr.length; i++){ System.out.println(arr[i]); } System.out.println("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
        /*** * descending */
        for(int i=arr.length-1; i>=0;i--){
            System.out.println(arr[i]);
        }
    }
Copy the code

Two-dimensional array: a two-dimensional array is an array of the contents of the village in the array, such data is a two-dimensional array.

Initialization of a two-dimensional array: dynamic initialization:int[][] arr =new int[2] [3];
             int[] ar1 =new int[] {1.3.5};
             int[] ar2 =new int[] {2.6.9};
             arr[0]=ar1; jaca arr[1]=ar2; Static initialization:int[][] arr=new int[] [] {{1.3.5}, {2.6.9}}; Get: first get the inner dimension array by the subscript of the outer array, and then find the specific value by the subscript of the inner dimension array; arr[0] [2]; Traversing a two-dimensional array:Copy the code