Java SE 1

Source: Internet
Author: User
Tags java se

1. The main method is the entry point for the entire Java program, and if there is no main method in the definition of the class , the program cannot execute.

2. method definitions cannot be nested, meaning another method cannot be defined in one method. Method can only be defined in a class.

3. About method execution: First you need to define the method, then you can use the method (call method), and when the method call is complete, the method can return a value. The return value of the method is determined by the definition of the method.

4. How do I generate an object? The object is generated by the class (usually using the new keyword to generate the object).

public class person{}


class name variable name = new class name ();

person person = new person (); Person Person1 = new person (); Person Person2 = new person ();

5. The method invocation needs to be done through the object. The method invocation is in the form of an object variable . method Name (actual parameter);

6. notes on the methodology:

1) in the definition of a method, the return type of the method is consistent with the type of the variable or constant following return.

2) When a method is called, the parameters passed to the method are consistent with the parameters of the method definition (the number of parameters is the same as the parameter type).

3) The return type at the time of the method definition is consistent with the variable type of the Receive method return value.

7.

public int Add (int a,,int b) {return a + B;}

The parameters of the method definition are called formal parameters

int a = Test.add (3,8);


The specific value given by the method invocation is called the actual parameter

8. keyword void means that the method does not return a value

9. if the method does not return a value, the Void keyword is used when declaring the method , and there are two possible implementations of the method definition that do not return a value:

1) do not use return statement

2) return is used, but there is no value or variable afterreturn, and a return is followed by a semicolon, which represents the exit method and returns to the calling side of the method.

the attributes in the class are also called member variables (member variable), and the properties are expressed in English as property or attribute.

The objectisalso called an instance (instance), and the process of generating an object is called instantiation of the class.

A property needs to be defined in a class, also called a member variable, whereas a variable defined in a method is called a local variable.

How do I define a property?

public class person{modifier type property name;}

Local variables must be declared and assigned before they are used. Member variables must be declared before they are used, but they can not be assigned an initial value.

the relationship and difference between member variables and local variables:

A) both the member variable and the local variable need to be declared (defined) before use

b) for local variables, it must be initialized before use, and can be uninitialized for member variables. If you start using a member variable without initializing it, there is a default initial value for each type of member variable.

reference type (Reference type): The reference type is used on the object. An object can be pointed to by multiple references, but at the same time, each reference can only point to a unique object. If an object is pointed to by multiple references, it is reflected in other references, regardless of which reference modifies the object's properties.

If a class contains properties and methods, each object of that class has its own properties, but no matter how many objects a class has, the objects share the same method.

Summary of method parameter passing: For method parameter passing in Java, uniform is the pass value (pass by value), regardless of whether the native data type or reference type is passed.

What type of reference can point to what type of object, such as a reference to a people type, can point to an object of type people, but cannot point to an object of type Student.

Construction method (Constructor): The construction method is used to complete the initialization of object properties, the characteristics of the construction method:

A) the name of the construction method must be exactly the same as the class name (including case).

b) the construction method has no return value, and even void cannot occur.

c) If you do not construct a method for a class declaration when you define a class , the Java compiler automatically adds a constructor that has no parameters and Null methods (the default constructor) for the class.

D) If you declare a constructor for a class when you define a class , the Java compiler will no longer add a constructor method to the class.

e) The constructor method of the calling class cannot be displayed, and the construction method is usually implicitly called through the new keyword.

The 21.new keyword accomplishes three things when you build an object:

A) open up memory space for objects

b) constructor method of calling class

c) return the address of the generated object

the default constructor method: The constructor method has no parameters and the method body is empty

When you use new to generate an object, the following parentheses () represent the argument list of the constructed method. If the constructor does not accept parameters, the contents of the parentheses are empty, and if the constructor accepts the arguments, the actual parameters in the parentheses are consistent with the formal parameters in the constructor definition (the number of parameters is consistent, the parameter types are consistent, and the values are assigned sequentially).


This article is from the "Java" blog, so be sure to keep this source http://5737386.blog.51cto.com/5727386/1660364

Java SE 1

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.