1. Behavior of the object:
(1) method call Stack: All method calls are maintained in a structure called the call stack.
The first method called is main (), which is called by the JVM, so the main () method is always at the bottom of the call stack.
(2) Call method: When a method is called, the method is placed at the top of the call stack, knowing that the method execution is complete.
Three cases: The ① method returns a value: a base data type or a reference data type that is passed back to the caller of the method;
The ② method does not return a value: The return value is declared void;
The ③ method throws an exception to the caller of the method.
methods in Java can only appear in a class, and methods that are not declared as static can only be called in instances of the class.
(3) method signature: The method signature does not contain any statements in the method body, and the signature is just the declaration part of the method.
① access modifier: public, private, protected, default access modifier;
② Optional modifiers: Static, final, abstract, native, synchronized (the order of access modifiers and optional modifiers is arbitrary);
③ return Value: The method signature must include the return value type;
④ Method Name: The method name must appear after the return value and can be any valid Java identifier;
⑤ formal parameter list: The method must be followed by a list of formal parameters enclosed in parentheses.
(4) Formal parameters and arguments: Formal parameter: The type used to declare the data passed to the method;
actual parameter: Pass the data that is passed to the parameter.
Delivery in Java is only a value pass.
(5) Call by value:
Concept: In programming, the process of copying data before a method call is called by value.
How it works: regardless of the type of actual argument passed to the method, the relevant formal parameter will be a copy of the data, which is how the call by value works.
Flaw: The only limitation caused by a value call is that the method cannot change the point of the reference.
add : 1. Breakpoint Debugging: ① location (set breakpoint);
② start debugging;
③ Single step execution, observation;
④ modified.
2.① the property or method that is modified with static is called a static member and is shared for all objects of the class;
② in static methods, only static members can be called directly, and non-static members cannot be called directly;
③ in member methods, you can call static or non-static members directly;
④ calls a static member with the class name.
3. Local variables allocate memory in the call stack when the execution of the method is complete, the variables are discarded.
4. If the data that we want to pass to the method is a very large object, then the object is not passed in, but the object's reference is passed in.
(6) Method overloading: When a class has two methods with the same name but with a different argument list .
(7) constructor: Called when an object is created, it is a special method in the class.
① Purpose: Initializes a member variable in an object.
②:⒈ By default, there is a parameterless constructor in the class, which is generated automatically at compile time;
⒉ when a parametric constructor is written out, no parameterless constructor is created to use the parameterless constructor;
⒊ calls the constructor in the same class in the constructor, and with this (), the statement must be the first day of the constructor's executable statement.
The difference between a ③ constructor and a method is that its two properties: the ⒈ constructor name must be the same as the class name;
Array chant when instantiated.
⑤ The This keyword used within the constructor in Java is different from the this reference for each object itself.
2. Arrays:
(1) An array is a collection of elements stored in a contiguous block of memory, which is a reference type.
① declaration array: int sum = new Int[5]; (each element of the array will have a default value after allocating space)
Each element in an array of ② objects is an object;
Object array: Single element type [] Array name = new Type [length]
The elements in the ③ array are accessed by index values.
(2) Array length: The size of the array is represented by the length property, which can greatly reduce the possibility of the array accessing out of bounds.
(3) Array initialization: Declare an array reference with a statement, instantiate an array, and populate the array elements. It is useful for creating a decimal group that contains known data.
①int[] num = new int[]{,,}
②int[] num = {,,}
③int[] num;
num = new int[]{,,}
(4) Array replication: You can write a for loop to copy the contents of an array to another, or you can use the static method Arraycopy () in the System class.
The signature of the Arraycopy () method is as follows:
public static void Arraycopy (object source, int sourcepos, object destination, int destinationpos, int length)
Sourcepos ———— The source array to copy
Destinationpos ———— to copy to the target array.
Length ———— parameter represents the number of elements to be copied
Arrays can be initialized using the new keyword or using an array initializer.
The Javadoc tool can produce an HTML page containing class information that contains any Javadoc comments that appear in the source code.
Add:
Stack: A data structure that filo (first int last out) when it accesses the information. Save the value of the local variable: a reference to the base type's value and reference type, which is the address.
Heap: Used to store dynamically generated data, such as new objects.
When a reference type is compared with "= =", the comparison is referred to.
String:①concat ();
Eg:string a = "abc";
Print a Get ABC.
Print A.concat ("123") to get abc123.
②charAt ();
Eg:string a = "abc";
System.ou.println (A.concat (2)); Print out C
③compareTo ();
Eg:string a = "is";
String B = "more";
A.compareto (b): In the dictionary, judge the string A, B. If A.compareto (b) <0, then A is before B.
④indexOf (int a); Find character, start index
EG:AGVAJDGVJVBMSV. Finds the index of the first occurrence of a in the string, and returns 1 if the character does not appear.
⑤subString (start, end), starting from start (including), until end (not included).
3. Inheritance (initial): through extending an existing class and inheriting the class's properties and behavior, the class creates a new class (which can inherit public, protected members), and the keyword extends.
(1) An existing class is called a parent class, and a new class is called a subclass. The parent class derives the subclass, and the subclass inherits the parent class.
Eg:public class Hourly extends employee{}
4. Advanced concepts of the class:
① access Modifiers:
|
This class |
Non-homogeneous in the same package |
Different packages |
Sub-class |
Public |
√ |
√ |
√ |
√ |
Protected |
√ |
√ |
|
√ |
Default |
√ |
√ |
|
|
Private |
√ |
|
|
|
② encapsulation: Is the technique of making member variables in a class private and providing public methods to access these member variables. Encapsulation is also known as data hiding, and its role is to ensure data security.
The Get method that allows you to get member variables is called accessor methods, and the method that allows you to modify member variables is called a modifier method.
About Getter/setter:
1 Public classsalesperson{2 PrivateString name;3 PublicSalesperson (String name) {4 This. Name =name;5 }6 Public voidsetName (String name) {7Name =N;8 }9 Public voidGetName () {Ten returnname; One } A -}
Advanced concepts about the behavior of objects, arrays, inheritance, and classes