/***********
Directory
I. Classes, methods, and variables in Java
Two. Java Namespaces and access rules
Three. How objects are constructed
Four. Memory analysis of objects
Five. Use of the This keyword
Six. Method overloading (overload)
**********************************************************/
I. Classes, methods, and variables in Java
1. An object is an instance of a class. An abstract data type is called a class. A class is a template for an object.
2. Syntax specification for classes.
Modifier for class: public; abstract abstraction; final end; Default mode Friendly
One group: Public Private protected
Two groups: Static final transient
The first letter of the class name is capitalized (canonical)
The type of the member variable can be any data type in Java, including classes, interfaces, arrays
Hump Mark: Namesecond
Default initialization table for global variables:
Note: No initialization of member variables is automatically initialized.
Error if local variable is not initialized.
Compilation Result:
3. Specification of method definitions
Method Modifiers:
The parameter type can be a simple data type, or it can be a reference data type (array, class, or interface)
How arguments are passed: a simple data type is a value pass, and an object is a reference pass.
4. Parameter passing for simple data types, notes
Description difference:
System.out.print No line wrapping after output
System.out.println output after line break
can use SYSTEM.OUT.PRINTLN (); To change the line directly
5. Reference delivery
The change is the address, and the reference is the pointer. This pass is an object intarray of int[], so the pass is passed as a reference.
The results of the operation are as follows:
In summary, value passing is a copy of the data, and reference passing is the passing of an object pointer.
6. Important Parts (example methods and class methods):
instance variables and class variables, as explained earlier.
The instance method has no static, and the class method has a static addition.
Class (Static) member methods are referred to simply as class methods and static methods.
Member Instance methods (object methods) are referred to as instance methods.
7. Important part (construction method):
(i) The life cycle of an object
- The creation of the object must have a constructor method.
- Create object sub-declaration and allocate memory two steps.
Memory conditions:
Defines a variable that does not allocate memory, and only assigns the initial value to allocate memory.
Defines a local variable and assigns an initial value, at which time there is memory allocated in the stack area. When the life cycle of this function is complete, the contents of the stack are cleared.
3. Garbage collection
To force garbage collection, use:
System.GC ();
Called is the finalization method, which can be overridden. Equivalent to a destructor.
Understand the following code:
When the person is empty, there is no reference, and the property in the heap is not referenced, so it can be destroyed.
If there is a reference, even if the System.GC () is used; objects are not destroyed.
Finalize can be used to do some special work, such as C + + cooperation. Generally, the use is not advocated.
"Learning Notes" Java Object-oriented programming 1