Java (2)

Source: Internet
Author: User

1-method

A method is a block of code for a series of statements that can alter the state of an object and implement the behavior of a class

A method usually can only complete a specific function, which can make the program structure clear, facilitate the reuse of the module

2-parameters
2-1-Formal parameters

public void m (int a) {}//a: formal parameter

2-2-Actual parameters

public void N () {int B; }//b: Actual parameters

2-3-static method

Methods that use the static keyword are static methods that can be called before they are instantiated, and static methods are not instantiated

Static methods can only be method-static methods in this class, and static methods cannot be accessed

2-4-Construction method

A method used to initialize a class when the method is constructed, usually called automatically when the object is created, or by using the This keyword.

Construction method has no return value, the name must be the same as the type and cannot be modified with static final

Class person{

Public person () {}//constructor method}

2-5-Main () method

Main method is Java's program entry

The main method is a static method

The main method can only be called by the system and cannot be called by another method or class

3-this keywords

Call the properties of the current class or other constructor methods

public class person{

Public person () {

This ()}

public person (int a,int b) {

System.out.print (A, b)}}

1-When another constructor is called within one constructor, the calling code must be placed in the first row

2-The constructor cannot be called within any function other than the constructor

3-only one constructor can be called within a constructor

4-Process Control
4-1-Sequential structure

Statements are executed from top to bottom in order of precedence

4-2-Select structure 4-2-1-relational operations
Operator Name Example
== Equals A = = B
!= Not equal to A! = B
> Greater than A > B
< Less than A < b
>= Greater than or equal A >= b
<= Less than or equal A <= b
4-2-2-logical operation
logical operators Name Example
&& And A>b && C>d
|| Or A>b | | C>d
! Non - ! (A>B)
4-2-3-Conditional operations
Trinocular operator Expression 1 True Expression 1 False
Expression 1? Expression 2: Expression 3 Expression 2 Expression 3
4-2-4-if statements
if (a>b) {
}esle if (a>c) {
}esle{
}
4-2-5-swtich statements

Switch (key) {
Case Value:

Break

Default
Break
}

4-3-Cyclic structure
For loop

for (int i = 0; i < args.length; i++) {

}

While loop

while (condition) {

}

Do-while Cycle

do {

} while (condition);

4-4-Jump Statement

Break ends This cycle

Continue end of this cycle

Java (2)

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.