After the 1970s, OOP used a completely different approach to developing computer applications. The program is no longer designed around the task to be solved, but rather is designed around the object in question to be solved (structured programming). A class is an abstraction of an object that is an instance of a class that is a collection of objects with the same properties and behavior.
Method Syntax Rules:
1 access modifiers (public,protected,private,default)
2 return value type
3 Method Name
4 List of parameters
5 method Body (function code block to be implemented)
Declare the variable as a member variable under the class: Java assigns it automatically, and declares the variable as a local variable under the method: the initial value is not assigned. (Scope of a member variable: Available in all methods in a class; local variables: Used only in methods declared by itself)
Precedence of member variables and local variables: local variables take precedence over member variables
The package uses the fully qualified name to find the path to the class, and the package naming convention: Name the organization's domain name upside down. The declaration of the package must be the first executable statement of the source file, with the package name all lowercase.
Packages are a mechanism in the Java organization and management classes, and can prevent class naming collisions.
Two basic uses of the package: 1, provides a mechanism for an organization Class 2, provides a namespace for the classes in the package.
In Java, the keyword class is used to declare a class, which is composed of member variables and methods, the keyword new is used to instantiate an object, this represents the current member, the This reference: each object has a reference to itself.
The point operator is used to access the member variables and methods of an object together with a reference to an object.
In a Java program, main () is the first method to be called. When invoking a method execution, there are three scenarios: 1, the method returns a value of 2, the method does not return a value of 3, and an exception.
Method signature (The signature of the method does not contain any statements within the method body, and the signature is only part of the declaration portion of the method):
1. Access modifiers
2. Optional modifiers
3. Return value
4. Method name
5. Form parameter list
6. Exception list
Properties or methods that are decorated with static are static members and are shared for all objects of the class. In a static method, only static members can be called directly, non-static members cannot be called directly, and static or non-static members can be called directly in the member method. (Static member used: Class name.) In the way called)
When the actual parameter is passed to the formal parameter, the data of the actual parameter is copied to the formal parameter; in programming, the process of copying data between method calls is called by value. In the same class, the method name is the same, the parameter's data type is different or the number of arguments is different is called the method overload. A constructor is a special method in a class that is called to execute when the class creates an object. By default, there is a parameterless constructor in a class, but when a parameter constructor is written in a class, the default parameterless constructor is not generated by the system. The role of the constructor: initializes the member variable.
Constructor Features: 1, the name of the constructor must be the same as the class name 2, the constructor method does not return a value.
An array is a collection of elements stored in a contiguous block of memory, and each element in the array must be of the same data type and be distinguished by an index. The index of the first element in the array is 0.
In Java, the steps to create an array are: 1, declare an array of reference 2, initialize the arrays with the new keyword, and specify the size of the array
Example: The first step: int[] array; Step two: Array=new int[10]; (Note: array elements have default values after allocating space)
Each array in Java has a length property to represent the lengths of the array, and using the length property can greatly reduce the likelihood of an array's access out of bounds. (arrayindexoutofbondsexception indicates that subscript is out of bounds)
foreach is used for array or collection traversal (advanced use of For loops) syntax: for (data type variable name: array name or collection name).
Java second week