Java Core Technology Volume I-fourth learning notes __ Learning Notes

Source: Internet
Author: User

Objects and classes

1. A class is a template or blueprint for constructing an object. The process of constructing an object from a class is called creating an instance of a class.
2. Encapsulation (data hiding) is an important concept related to objects. The form is to combine the data and behavior in a package, and the object's consumers hide the way the data is implemented.
3. The superclass of all classes is the object class. The process of building another class by extending a class is called inheritance.
4. The three main characteristics of the object: Behavior, status, identity (unique identity of the object).
5. Use constructors to construct objects in Java. The constructor should be the same as the class name and need to precede the constructor with the new operator, such as New Date (). If you need to construct an object that can be used more than once, you need to store the object in a variable.
6. Differences between objects and object variables:
Date deadline defines an object variable deadline that can refer to objects of type date. However, realize that the variable deadline is not an object and actually does not refer to the object. Therefore, you cannot apply any date method to this variable. Variable dateline must be initialized first:
(1) Deadline = new Date ();
(2) deadline = birthday;
Now these two variables refer to the same object.
Note: An object does not actually contain an object, but simply refers to an object.

7. In Java, the value of any object variable is a reference to an object that is stored in another place. The return value of the new operator is also a reference.
8. If a method is applied to an object that has a value of NULL, a run-time error is generated.
9. A class typically includes an instance domain of a type that belongs to a class. For example, the Name field in private string name is a string type object.
10. The constructor has the same name as the class. When you construct an object for a class, the constructor runs automatically to initialize the instance domain to the desired state.
11. The constructor is always used with the execution of the new operator, not the constructor for an existing object to be reset to the purpose of setting the instance domain.
12. About Constructors Summary:
Constructors have the same name as the class;
Each class can have more than one constructor;
The constructor can have 0, one, or more parameters; The
constructor has no return value; The
constructor is always invoked with the new operator.
13. All Java objects are constructed in the heap, and constructors are always used with the new operator.
14. Do not define local variables that have the same name as the instance domain in the constructor.

16. The accessor needs to return a copy of the variable data and should use clone.
17. A static method is a method that cannot be applied to an object-oriented operation. This means that there is no implicit argument.
18. Each class can have a main method, which is a common technique for unit testing of classes.
19. A value invocation representation method receives the supplied value. The
by reference invocation representation method receives the variable address provided by the caller.
A method can modify the value of a variable that passes a reference instead of modifying the value of the variable that is the value of the pass call. The Java programming language is always called by value (the object reference is a value pass).
In other words, the method gets a copy of all the parameter values, especially if the method cannot modify the contents of any parameter variables passed to it.
20. A method cannot modify a parameter of a basic data type. An object reference is different as a parameter and can easily change its value.
Method parameter Usage in 21.java:
A method cannot modify the parameters of a basic data type (that is, numeric and Boolean);
A method can change the state of an object parameter;
A method cannot have object arguments referencing a new object.
22. If more than one method has the same name and different parameters, the overload is generated. The compiler picks the appropriate method by matching the parameter types given by each method to the value types used by the particular method invocation.
23. Signature of method: Method name and Parameter type.
24. Process steps for calling constructors:
(1) All data fields are initialized to the default value (0,false,null), and
(2) Executes all the field initialization statements and initialization blocks sequentially, in the order in which they appear in the class declaration;
(3) If the second constructor is invoked in the first row of the constructor, the second constructor body is executed, and
(4) executes the constructor body. The
. Import statement is a concise description of the class that is included in the package. The import statement should be at the top of the source file (but at the back of the package statement).
26. To put a class into a package, you must place the package name at the beginning of the source file, before the code for the class is defined in the package.

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.