The interface is the key to implementing component-induced, and the key to insertless components is that there is a public interface, and each component is implemented.
What is an interface? The interface in Java is a series of declarations. It is a collection of method features. One interface only has the realization of the characteristics of the method, so these methods can be implemented in different places, and these implementations can have different Behavior (function). The two meanings of the interface: a Java interface, the structure in the Java language, there is a specific syntax and structure; two, the characteristic set of the method of a class is a logically abstraction. The former is called "Java Interface", the latter is called "interface". In the Java language specification, one method is characterized by only the names, parameters of the method, and the type of parameters, and the return type, parameter name, and exceptions thrown. When the overload of the Java compiler check method, it is determined whether two methods are overloaded methods based on these conditions. However, when the Java compiler checks the replacement, the return type of two methods (sub-hypening and subtypes) will be further checked, and whether the exception thrown is the same. Interface inheritance and implementation of the rules of the inheritance, only one direct parent class, but multiple interfaces can be implemented. The Java interface itself does not have any implementation, because the Java interface does not involve the appearance, and only describes the public behavior, so the Java interface is more abstracting than the Java abstraction class. The Java interface can only be abstract and disclosed. The Java interface does not have a constructor, and the Java interface can have public, static and final properties. The interface is separated by the implementation of the features and methods of the method. This segmentation is reflected in the interface often represents a role, which is packaged with the role-related operations and attributes, and the class that implements this interface is an actor who plays this role. One role is played by different actors, while different actors do not require other common situations in addition to playing a common role.
Why use an interface? Two similar functions in two classes, calling their dynamic decisions, then they provide an abstract parent class, the subclass, the method defined by the parent class, respectively. The appearance of the problem: Java is a single inherited language. Under normal circumstances, which specific class may already have a super class, solve it to add the parent class to its parent class, or parental class to the parent class Only the top of moving to the class level structure. In this way, the insertable design of a specific class has become a modification of all classes in the entire level structure. The interface is an insertable guarantee. Any interface can be implemented in any of a level structure, which affects all subclasses of such classes, but does not affect any superclasses of such classes. This type will have to implement the method specified in this interface, and its subclasses can automatically inherit these methods from this class, of course, can choose to replace all of these methods, or some of them, this time these subclasses have Insertability (and can be loaded with this interface, all of which implement all of his subclasses). What we care is not the specific class, but whether this category implements the interface we need. The interface provides the interposability of the association and method call, the larger the size of the software system, the longer the life cycle, the interface makes the software system flexibility and scalability, and insertability.
Types Use the Java interface to couple the software unit with internal and external. Using the Java interface is not a specific class for variables, the method of returning type declaration, the type of parameter, and the conversion of the data type. In the ideal case, a specific Java class should only implement methods declared in the Java interface and abstract Java classes, and should not give excess methods. Type Grade Structure Java interface (and abstraction class) is generally used as a starting point for a type of level structure. If a class already has a major hypercarcies, then this class can have another secondary type, which is called a mixed type. JAVA Interface Common Method Unilateral Law Interface Public Interface ActionListener () {Public Abstract Void ActionPerformed (ActionEvent Event);} Only only one method, only this interface (the only way to rewrite this interface), you are eligible To the event listener list (parameter is an actionListener type), when the event source changes, this unique actionPerforMed method is automatically called. The identity interface is an interface without any method and attribute. The identification interface does not have any language requirements for implementing its classes, which simply demonstrates that the class belongs to a particular type (delivery). Do not recommend excessive use identification interface. The constant interface uses a Java interface to declare some constants, and then use these constants by the class that implements this interface (I have done it when I do the drawing board). It is recommended not to imitate the practice of this constant interface.
Java Language Type Security Questions Java is a strong type of language. This means that the Java compiler checks the code to determine that there is no assignment, and the call to each method is in line. If there is any unprecedented situation, the Java compiler will give an error. Type check is based on such a simple fact: the declaration of each variable gives this variable type; each method includes the characteristics of the constructor to give this method. In this way, the Java compiler can infer a significant type of expression, and the Java compiler can check the type based on the obvious type. Java language is type safe. That is to say, any legal Java class guarantees accepted by the Java compiler is type safe. In other words, there will be no types of errors during the program run. A Java program is not possible to treat a variable that belongs to a type as another type of variable, so there is no error caused by this. Simply put, Java language relies on three mechanisms to achieve type security: the type inspection during compilation, automatic storage management, array boundary check.
Note: This article is "Java and Mode" of the teacher.