Java re-learning 3

Object Oriented: super is a reference to the immediate parent class object. You can use super to access methods or properties in the parent class that are overridden by the subclass.
Ordinary method: there is no order restriction, you can call it at will.
In the constructor: In the constructor of any class, if the first line of code of the constructor does not call super(...); then Java will call super(); as the initialization function of the parent class by default. So super(); can be added or not.


final modified variable: constant Modified method: this method cannot be overridden by subclasses. But can be overloaded. Modified classes: Modified classes cannot have subclasses and cannot be inherited.


Encapsulation: Hide the complexity inside the object and only expose simple interfaces to the outside world. It is convenient for external calls, thereby improving the scalability and maintainability of the system.
Program design pursuit: high cohesion, low coupling.
High cohesion: the internal data operation details of the class are completed by themselves, and external interference is not allowed;
low coupling: only a small number of methods are exposed for external use.
Key points of encapsulation: Handling of class attributes: 1. Generally, private is used. (Unless this property is determined to be inherited by subclasses)
2. Provide corresponding get/set methods to access related properties. These methods are usually public, thus providing read operations on properties. (Note: the get method of the boolean variable starts with: is!)
Some auxiliary methods that are only used in this class can use private. I hope that methods called by other classes use public



Polymorphism: The actual type of the referenced object is determined during execution (not the compiler), and its corresponding method is called according to its actual type. Because it is a dynamic implementation at runtime, which method to call can not be determined until the new object is generated, so polymorphism is also called dynamic binding.
Polymorphism is an important feature in oop, which is mainly used to achieve dynamic compilation, that is, the final state of the program is determined only during execution, not during compilation. This can improve the flexibility and scalability of the system for large systems.
There are two types of reference variables: compile-time type (fuzzy, usually a parent class), determined by the type at the time of declaration.
The runtime type (at runtime, which subclass is which subclass) is determined by the actual corresponding object type.
There are three necessary conditions for the existence of polymorphism: there must be inheritance, there must be method overriding, and the parent class reference points to the child class object.


The abstract class provides a common template for all subclasses. Subclasses can extend this template.
By abstract classes, you can avoid the arbitrary design of subclasses. Through abstract classes, we can strictly limit the design of subclasses and make them more common among subclasses.
Key points: 1. Classes with abstract methods can only define abstract classes.
2. Abstract classes cannot be instantiated, and new cannot be used to instantiate abstract classes.
3. An abstract class can contain properties, methods, and constructors. But the constructor cannot be used to new instance, it can only be used to be called by subclasses.
4. Abstract classes can only be used for inheritance.
5. Abstract methods must be implemented by subclasses.


The interface can constrain subclasses in a more standardized way, and comprehensively realize: the separation of specifications and specific implementations.
An interface is a specification, defining a set of rules that embody the "if you are...must be able to..." mentality. The essence of an interface is a contract


An array is an ordered collection of data of the same type. Arrays describe several data of the same type, arranged and combined in a certain order. Each of these data is called an array element, and each array element can be accessed by a subscript.
Three characteristics of the array: 1. Its length is determined. Once an array is created, its size cannot be changed. If it is out of bounds, report: ArrayIndexOutofBoundsException 2. Its elements must be of the same type, and mixed types are not allowed. 3. The elements in the array can be of any data type, including primitive types and reference types.
Arrays are of reference type.
There are two ways to declare a bunch of arrays: type[] arr_name; type arr_name[]
Default initialization: array elements are equivalent to member variables of objects, and the default values ​​are the same as the rules for member variables. Number 0, boolean false, char\u0000
Dynamic initialization: for(int i=0;i<a.lenght;i++) {a[i]=i*12}
Static initialization: int c[]={12,21, 55,78} (length 4, index range [0-3]).

A Java string is a sequence of Unicode characters. For example, the string "java" is composed of four Unicode characters j, a, v, and a.
Java does not have a built-in string type, but provides a predefined class String in the standard Java class library, and each string enclosed in double quotes is an instance of the String class.

StringBuilder, which tests for mutable character sequences. Thread unsafe and efficient. StringBuffer (thread-safe, low-efficiency) is
not described, and the length of the character array is initially 16;
Arraylist is a dynamic array that implements the List interface. The so-called dynamic is that its size is variable. Implements all optional list operations and allows all elements including null, and this class also provides methods to manipulate the size of the array used internally to store the list.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324915112&siteId=291194637