Java methods to organize your notes

Source: Internet
Author: User
Tags modifier modifiers

1. Modular
The big program is broken down into smaller sections, each section has its own tasks, and there is no necessary connection between each section.
After completing each section, connect it together and combine a large program
1.1 The role of modularity
① make the code structure clear;
② makes the code reusable;

2. Method label
Example of the first part of the method: public static void Main (String[]args)
Public: access modifier → permissions to access publicly: Exposed protected: Protected default private: Private

Static: Optional modifiers static: static modifier final: End State modifier
Access modifiers and optional modifier positions are interchangeable

void: return type → all data type void: null return type int: integer return type int[]: array return type
If the return type is void, no data is returned, but return can be used;
If the return type is not void, it must be returned in Java
Return with return keyword

Main: Method name → identifier

(String[]args): parameter list → divided into ① form parameter list ② actual parameter list
A parameter list in a method is a formal parameter, and is an argument when the data is passed or the method is called

Note: The way data is passed in Java: value is passed, and if passed as a reference data type, the reference is passed, and the assigned person points to the
Like.

3. Calls between methods
A method that contains static is called a static method

① static method call static method → If the method is in this class, write the method name directly (); otherwise write the class name. Method Name ();
② static method calls a non-static method → The object example of the class that first creates the required method: Test T1 = new test (); T1.add ();
③ non-static method call static method → If the method is in this class, write the method name directly (); otherwise write the class name. Method Name ();
④ non-static method calls a non-static method → The object example of the class that first creates the required method: Test T1 = new test (); T1.add ();

4. Overloading
A class that has two to many have the same name but a different parameter list, which is called a method overload.
Different parameter list: ① parameter number different ② parameter type ③ parameter order different

5. Method call Stack
What is the method call stack:
When a method is called, the method appears in a structure called the call stack, which is called the method call stack
Knowledge points of the method call stack
The ①java code starts with the main method, first the method call stack of the Main method
② is then placed at the top of the method stack when the method is called
③ when the execution is finished, the previous method in the stack is returned
After the ④ method executes, the data in the stack is destroyed as the method is removed, and the objects in the heap are immediately reclaimed by the GC when they are not referenced.

Java methods to organize your notes

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.