Java Learning Notes-method summary

Source: Internet
Author: User

1. Modularization and reusability of the program is one of the central objectives of software engineering. Java provides a number of effective structures to help accomplish this goal. The method is one such structure.
2. Method header Specifies the modifier of the method, returns the value type, the method name, and the parameter.
3. The method can return a value. The return value type is the data type of the value that the method is returning. If the method does not return a value, the return value type is the keyword void.
4. The parameter list refers to the type, order, and quantity of the parameters in the method. The method name and the parameter list together form the method signature. The parameter is optional, that is, a method can contain no parameters.
The 5.return statement can also be used in the void method to terminate the method and return to the caller of the method. In the method, it is useful to use the normal process control of the table occasionally.
6. The actual arguments passed to the method have the same number, type, and order as the formal parameters in the method signature.
7. When the program calls a method, the control is transferred to the method being called. When the return statement of the method is executed or the closing parenthesis of the method ends, the called method is programmed back to the caller.
8. In Java, a method with a return value can also be invoked as a statement. In this case, the calling function simply ignores the return value.
9. Each time a method is called, the system stores the parameters and local variables in an area of the title stack. When one method calls another method, the caller's stack space remains motionless, opening new space to process the new method's call. A method to complete his work and return to its callers, to release its corresponding space.
10. The method can be overloaded. This means that both methods can have the same method name, as long as their method parameter lists are different.
11. A variable declared in a method is called a local variable. The scope of a local variable starts at the point where it is declared, until the end of the block that contains the variable. Local variables must be declared and initialized before they are used.
12. Method abstraction is the separation of the application and implementation of the method. The user can use the method without knowing how the method is implemented. The implementation details of the method are encapsulated within the method and hidden from the user who called the method. This is called information hiding or encapsulation.
13. Methods abstract the program into a neat, hierarchical form. Writing a program into a concise collection of methods makes it easier to write, debug, maintain, and modify than other methods. This writing style also improves the reusability of the method.
14. When implementing a large program, you can use a top-down or bottom-up encoding method. Do not write the whole program at once. This approach seems to waste more coding time, but in fact it saves time and makes debugging easier.

 PackageWelcome;ImportJava.util.Scanner;/** Calculates the average of 10 numbers and counts the number of values greater than the average*/ Public classAnalyzenumbers { Public Static voidMain (string[] args) {Final intNumber_of_elements = 10; Double[] arr =New Double[number_of_elements]; Doublesum = 0; Scanner in=NewScanner (system.in);  for(inti = 0; i < number_of_elements; i++) {System.out.print ("Enter A number:"); Arr[i]=in.nextdouble (); Sum+=Arr[i]; }                DoubleAverage = SUM/number_of_elements; intCount = 0;  for(inti = 0; i < number_of_elements; i++){            if(Arr[i] >average) {Count++; }} System.out.println ("The average is" +average); System.out.println ("The Count is" +count); }}

Java Learning Notes-method summary

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.