Java Basic Course Learning notes (5)

Source: Internet
Author: User
Tags type null

1: Method (Master)(1) Method: A block of code that completes a specific function. Note: In many languages there is a definition of a function, whereas in Java, a function is called a method. (2) Format: Modifier Returns a value of type method name (argument type parameter name 1, parameter type argument Name 2 ...)   {method body statement;  return value; } modifier: Use public static now.  Further details on other modifiers return value types: is the data type method name of the functional result: it is a name that makes it easy for us to call the method. Parameter type: is the parameter's data type parameter name: is the variable argument class: argument: The actual participation in the operation of the data parameter: method defined, to receive the actual parameters of the variable method body statement: Is the completion of the function of the code block return: End method return Value: The result of the function, by return Brought to the caller. (3) Two clear: Return value type: The data type parameter list of the result: number of parameters and corresponding data type (4) method call A: A method with a definite return value A: Call alone, no meaning B: the output call is not good, because I may need to do further operations without results.   But I used the lecture in general. C: Assignment invocation, recommended scheme b:void type modification method A: Call alone (5) Case: A: Sum scheme B: Get the larger value in two numbers C: compare two data is the same D: Get the maximum value in three numbers E: The star of the output m row n column F: output nn multiplication table (6) Precautions for the methodA: The method does not call do not execute B: The method is a peer relationship, cannot nest definition C: Method definition, the parameter is used, separated by the D: Method at the time of invocation, do not pass the data type E: If the method has an explicit return value type, you must have a return statement returned. (7) method overloadingIn the same class, the method name is the same, and the parameter list is different.   Is independent of the return value.   Parameter list is different: The number of parameters is different. The corresponding data type of the parameter is different. (8) Method overload case comparison of multiple methods with the same name for different types. method invocation Plot: 2: Array (master)(1) array : A container that stores multiple elements of the same data type. (2) Features: Each element has a number, starting from 0, the maximum number is the length-1.  Number of professional names: Index (3) define format A: data type [] array name;   B: Data type array name [];  Recommendation is a way, B method forget it. But to be able to understand (4) array initialization the array in Java must be initialized before it can be used. Initialize: Allocates the memory space for array elements in arrays and assigns values to each array element. how arrays are initialized:A: Dynamic initialization gives only the length, the system gives the default value example: int[] arr = new INT[3];   B: Static initialization of the given value, the system determines the length example: int[] arr = new int[]{1,2,3}; Simplified version: int[] arr = {£ º};    Note: Do not simultaneously dynamically and statically format the following: int[] arr = new int[3]{1,2,3}; Error (5) memory allocation in JavaA: Stack stores local variablesB: Heap storage for all newC: Method Area (Detailed explanation of object-oriented section) D: Local method Area (System dependent) E: Register (CPU use) Note: A: A variable that is defined by a local variable in a method definition or a method declaration.    B: Stack memory and heap memory difference stack: The data is used, it disappears.       Heap: Every new thing that comes out has an address each variable has a default value of Byte,short,int,long 0 float,double 0.0 char ' \u0000 ' Boolean false Reference type NULL when the data is used, it is reclaimed when the garbage collector is idle. (6) array memory graph  A: An array (slightly)    B: Two arrays   C: Three arrays (two stack variables point to the same heap memory) (7) Array of common operations   A: Traversal     Way 1:    public static void PrintArray (int[] arr) {     for (int x=0; x<arr.length; x + +) {      Sys Tem.out.println (Arr[x]);     }   }       mode 2:    public static void PrintArray (int[] arr) {     system.out.print ("[");     for (int x=0; x<arr.length; x + +) {      if (x = = arr.length-1) {      &NBSP;SYSTEM.OUT.PRINTLN (arr[x]+ "]");     }else {       system.out.print (arr[x]+ ",");     }     }   }  B: Maximum value     Max:    public static int Getmax (int[] arr) {     int max = arr[0 ];          for (int x=1; x<arr.length; x + +) {      if (arr[x] > max) {&N Bsp      max = arr[x];     }     }          return max;   }        min:    public static int getmin (int[] arr) {     int min = arr[0];    &NB sp;     for (int x=1; x<arr.length; x + +) {      if (Arr[x] < min) {       min = arr[x];     }     }          return min;  &N Bsp }  C: Reverse     WAY 1:    public static void reverse (int[] arr) {     for (int x=0; x<ar R.LENGTH/2; x + +) {      int temp = arr[x];      Arr[x] = arr[arr.length-1-x];      Arr[ar R.length-1-x] = temp;     }   }       mode 2:    public static void re Verse (int[] arr) {     for (int start=0,end=arr.length-1; start<=end; start++,end--) {    & nbsp int TEMP = arr[start];      Arr[start] = arr[end];      Arr[end] = temp;     }&nbs P  }  D: Look up the table     public static String getString (string[] strarray,int index) {     return s trarray[index];   }  E: Basic find     way 1:    public static int GetIndex (int[] arr,int value) {     for (int x=0; x<arr.length; x + +) {      if (arr[x] = = value) {      & Nbsp;return x;     }     }          return-1;   }        Way 2:    public static int GetIndex (int[] arr,int value) {     int Index = -1;        for (int x=0; x<arr.length; x + +) {      if (arr[x] = = value) {&nbsp ;      index = x;       break;     }     }    &N bsp;    &NBsp;return index;   }

Java Basic Course Learning notes (5)

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.