The 1 interface interface all methods of the Implement interface are automatically owned by public. Therefore, when declaring a method in an interface, you do not have to provide the keyword public. An interface can contain multiple methods,constants can be defined in the interface。 The fields in the interface will be automatically set to public static final. Swingconstants is defined only by constants, and no method is defined, and any class that implements the Swingconstant interface automatically inherits these constants, and can refer to some constants directly in the method. The feature interface of the 1.1 interface is not a class, especiallyYou cannot instantiate an interface with the new operatorBut you can declare interface variables,the class object that implements the interface must be referenced。 Use instanceof to check whether an object belongs to a particular class, or you can use instance to check whether an object implements a particular interface. Each class can only have one superclass, but can implement more than one interface 1.2 interface and abstract class abstract class is also only defined methods, but the total point is that inheritance can inherit only one,implementing an interface can implement multiple。 2 object Cloning when you copy a variable, the original variable references the same object as the copy variable. Other wordschanging the object referenced by one variable will have an effect on the other variable。 Copy and Clone:
The Clone method Clone method is a protected method of the object class, that is, it cannot be called directly in the user-written code.
- 1 whether the default clone method meets the requirements
- 2 whether the default clone method can be patched by invoking the clone of a mutable child object
- 3 Should you not use clone
3 is the default if you need to select 1 and 2
- A implements the Cloneable interface class
- B redefine the Clone method with the public access modifier
The 3 interface and callback callback callback is a common programming pattern. In this mode, you can point out a specific action that should take place. 4 Internal ClassesInnerClass is the reason that classes that are defined in another class require an inner class:
- A inner class method can access all the data in the scope of the class definition, including private data
- b Inner classes can be hidden from other classes in the same package
- c When you want to define a callback function and don't want to write a lot of code, it's easier to use anonymous inner classes
4.1 Using an internal class to access the object state access to the instance class inner class of the outer class can access both its own data field, or the object that creates its perimeter class object, there is always an implicit reference (outer), which points to the outer class object that created it. 4.2 Special syntax rules for inner classes access the formal syntax of the perimeter class reference is complex, and the expressionOuterclass. ThisRepresents a perimeter class reference. Outside the scope of the perimeter class, it is possible to refer to the inner class outerclass.innerclass4.3 inner class for usefulness, necessity, and security the compiler will translate the inner class into($) dollar sign separates external class name fieldsThe generic class file for the internal class name. If the inner class accesses the private data domain, it is possible to access them by attaching other classes in the package in which the perimeter class is located, but doing so requires great skill and determination. 4.4 Local Inner class local classes cannot be declared with public and private access specifiers. Its scope is scoped to the block that declares the local class. Local classes have an advantage in that they can be completely hidden from the outside world. 4.5 access to the final variable by an external method is not only able to access the external classes that contain them, but also local variables, as compared to the inner classes. Those local variables must be final when the inner class is first presented, the prototype compiler automatically transforms local variables that are modified in the inner class. 4.6 Anonymous Inner class if you only create an object of this class, you do not have to name it. This kind of exhaustion is called anonymous inner class. 4.7 Static inner classes use inner classes just to hide a class inside another class, you can declare an inner class as static, so that the resulting reference 5 proxy java1.3 can be created at run time by a new class that implements a given set of interfaces. Suppose you have a class object that represents an interface, and its exact type is not known at compile time. To construct a class that implements these interfaces, you need to use the Newinstance method or reflection to find the constructor for the class. However, you cannot instantiate an interface,You need to define a new class when the program is in a running state。 The proxy mechanism is a solution where the proxy class can create entirely new classes at run time. Such a proxy class can implement the specified interface. Specify all the methods required by the interface, all methods in the object class, but no longer define new code for these methods at run time, but instead provide a call processor (invocation handler). The calling processor is an object that implements the Invocationhandler interface. There is only one method in this interface: Object Invoke (Object Proxy,method method,object[] args) whenever a method of invoking a proxy object is invoked, the Invoke method of the calling processor is called and passed to the Met The Hod object and the original invocation parameters. The calling processor must give a method to process the call. To create a proxy object, you need to use the Newproxyinstance method of the proxy class. This method has three parameters
As part of the Java security model, a class loader can use different class loaders for system classes and classes that are downloaded from the Internet.
An array of class objects, each of which is an interface that needs to be implemented
A call processor.
- There are two issues that need to be addressed.
How do I define a processor? What can I do with the result proxy object?Route method calls to a remote serverThe user interface events are associated with the action during the run of the program. for debugging, trace method callsThe attribute proxy class for the 5.1 proxy class iscreated during program runOf All the proxy classes areextended to ProxyClass, a proxy class has only one instance domain-the calling processor, which is defined in the superclass of the proxy. All the proxy classesare overridden by methods in the object class ToString, Equals, and Hashcode。 Like all proxy methods, these methods only invoke invoke of the processor. Other methods of the object class have not been redefined. Without the name of the proxy class defined, the proxy class in the Sun virtual machine willgenerates a class name that begins with the string $proxy。 The proxy class must be public and final. If all interfaces implemented by the proxy class are public, the proxy class does not belong to a particular package, otherwise all non-public interfaces must belong to the same package, and the proxy class belongs to the package. You can use the Isproxyclass method in the proxy class to detect whether a particular class object represents a proxy class.
Java basic syntax < nine > interfaces and internal classes