Java BASICS (5): java Basics

Source: Internet
Author: User

Java BASICS (5): java Basics

Here are some of the knowledge points and code I summarized in my previous class. Most of the notes I think are very good and classic, sincerely hope that these will help those who want to learn!

It is inconvenient to upload code by module. There are also many things, and they are also clear! If you need it, you can leave your email in the comments. I will certainly send it to you for free! Thank you for making progress on this platform !! Remember that programmers are selfless !!!

Also very welcome to my blog to watch blog address: http://www.cnblogs.com/duscl/

 

/* 1: method (master) (1) method: A code block that completes a specific function. Note: functions are defined in many languages. In Java, functions are called methods. (2) Format: modifier return value type method name (parameter type parameter name 1, parameter type parameter name 2 ...) {method body statement; return value;} modifier: public static is used currently. The other modifier return value type is described in detail later: it is the data type Method Name of the function result, that is, a name is provided, so that we can call this method. Parameter type: indicates the Data Type of a parameter. Parameter Name: Variable Parameter type: real parameter: The data parameter actually involved in the calculation: defined on the method, used to receive the variable body statement of the actual parameter: is the code block for function completion return: return Value of the end method: is the result of the function, which is sent to the caller by return. (3) Two definitions: Return Value Type: Data Type of the result parameter list: number of parameters and corresponding data type (4) method call A: method with a clear return value: independent call, no significance B: Output call, not very good, because I may need to perform further operations without results. But I usually use the lecture. C: Value assignment call. Recommended Solution B: void type modification method a: Independent call (5) Case: A: summation solution B: Obtain the greater values of the two numbers C: compare whether two data items are the same D: get the maximum values among the three E: Output m rows, n columns, star F: Output nn multiplication table (6) method Note: if a method is not called, do not execute B: There is a hierarchical relationship between methods, and no nested definition C: When a method is defined, the parameters are separated by D: When a method is called, data Type E does not need to be passed: if the method has a clear return value type, a return statement is required. (7) method Overloading is in the same class, with the same method name and different parameter lists. It is irrelevant to the returned value. Different parameter lists: the number of parameters varies. The corresponding data types of parameters are different. (8) compare multiple methods with the same name of different types in the case of method overload. 2: array (master) (1) array: a container that stores multiple elements of the same data type. (2) features: each element is numbered, starting from 0. The maximum number is length-1. Number: Index (3) Definition Format A: Data Type [] array name; B: data type array name []; recommended method, forget the B method. But you need to understand (4) array initialization A: Dynamic initialization only for the length, the system gives the default example: int [] arr = new int [3]; B: static initialization provides a value. The system determines the length. For example: int [] arr = new int [] {, 3}; simplified version: int [] arr = {, 3 }; (5) Java memory allocation A: Stack storage local variable B: Heap Storage all new C: Method Area (detailed description of the object-oriented part) D: local Method Area (system-related) E: registers (CPU usage) Note: a: local variables are defined in the method definition or method declaration. B: stack memory and heap memory difference Stack: After data is used up, it disappears. Heap: every new item has an address. Every variable has a default value of byte, short, int, long 0 float, double 0.0 char '\ u0000' boolean false reference type after the use of null data, when the garbage collector is idle. (6) Array Memory Figure A: An array B: Two arrays C: Three arrays (two stack variables point to the same heap memory) (7) Common Operations on arrays: traversal method 1: public static void printArray (int [] arr) {for (int x = 0; x <arr. length; x ++) {System. out. println (arr [x]);} Method 2: public static void printArray (int [] arr) {System. out. print ("["); for (int x = 0; x <arr. length; x ++) {if (x = arr. length-1) {System. out. println (arr [x] + "]");} else {System. out. println (arr [x] + ",") ;}} B: Maximum Value: public static int getMax (int [] arr) {int max = arr [0]; for (int x = 1; x <arr. length; x ++) {if (arr [x]> max) {max = arr [x] ;}} return max ;}minimum: public static int getMin (int [] arr) {int min = arr [0]; for (int x = 1; x <arr. length; x ++) {if (arr [x] <min) {min = arr [x] ;}} return min ;}c: Reverse Order Method 1: public static void reverse (int [] arr) {for (int x = 0; x <arr. length/2; x ++) {int temp = arr [x]; arr [x] = arr [arr. length-1-x]; arr [arr. the length-1-x] = temp;} Method 2: public static void reverse (int [] arr) {for (int start = 0, end = arr. length-1; start <= end; start ++, end --) {int temp = arr [start]; arr [start] = arr [end]; arr [end] = temp;} D: public static String getString (String [] strArray, int index) {return strArray [index];} E: Basic Search Method 1: public static int getIndex (int [] arr, int value) {for (int x = 0; x <arr. length; x ++) {if (arr [x] = value) {return x ;}} return-1;} Method 2: public static int getIndex (int [] arr, int value) {int index =-1; for (int x = 0; x <arr. length; x ++) {if (arr [x] = value) {index = x; break;} return index ;}*\

 

/* 1: Two-dimensional array (comprehension) (1) elements are arrays of one-dimensional arrays. (2) Format: A: Data Type [] [] array name = new data type [m] [n]; B: data Type [] [] array name = new data type [m] []; C: data Type [] [] array name = new data type [] [] {...}, {...}, {...}}; d: Data Type [] [] array name = {{...}, {...}, {...}}; (3) Case study: A: traversing two-dimensional arrays B: summation of two-dimensional arrays C: Yang Hui triangle 2: two questions (understanding) (1) in Java, parameter passing problems only involve value passing in Java. Basic Type: changes in form parameters do not affect the actual parameter reference type: changes in form parameters directly affect the actual parameters (2) a small case of comprehensive data encryption issues. *\

 

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.