The concept and use of Java methods

Source: Internet
Author: User

Method

To extract a piece of logic or function, the form of this extraction is the function

Format

Modifier returns a value type function name (argument list) {

Method body;

return value;

}

An explicit return value type---two integers and determines that the result must be an integer---The return value type is int

Whether there is an unknown amount involved in the execution of the function---the number of two integers, the two integers can not be automatically generated during the execution of the function, is two unknown amount, the unknown quantity needs to be reflected in the form of parameters

Defining a parameter is equivalent to declaring a few variables

Parameters declared in a function---formal parameters---form arguments

Function name + parameter list---method signature---Add (int i, int j)

public static int Add (int i, int j) {

int sum = i + j;

return sum;

}

The actual value passed in when the function is called---argument---actual argument

Add (3,5);

Attention:

1. If the function does not return a value, the return value type is defined as void

2. Return subsequent code is no longer executed

3. Any entity function has a return statement

Overload

When there is a function in a class with a function name that is consistent, and the argument list is inconsistent, it is said that there is an overload between the multiple functions.

The function will be the first to match the most consistent format when calling

When overloading a function, try to overload all cases in case there are multiple functions matching

Recursion of functions

Refers to calling itself in a function

Exercise: Ask for the factorial of any number

Stackoverflowerror---Stack overflow error---the response function executes in the stack---function does not release stack memory until execution is complete---recursion too many times, this error occurs

Note: The basic data type is passed the actual value, and for the reference type the address is passed

Eclipse---Eclipse

Intelligent Development Tools---IDE

Green, open source, free, plugin-based

Idea--intelli J

MyEclipse

alt+/Prompt Key

Object oriented

Object-oriented is relative to process-oriented. The process is focused on the process, the emphasis is on the action, object-oriented objects, as long as the corresponding object is found, then naturally have all the functions of the object

Object-oriented is process-oriented.

Is object-oriented necessarily better than process-oriented? When the scene is more complex, it is recommended to use object-oriented; When things are simpler, it is advisable to use process-oriented

The concept and use of Java methods

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.