1. What is object-oriented?
encapsulates functionality into objects, emphasizing the objects with functionality. features: Simplifying complex things and targeting the actors in the previous process into conductors.2. Relationship of classes and objectsA class is an abstract, conceptual definition of a specific thing, and an object is an individual that has a real existence of that kind of thing. In Java, a class describes a thing as a description of something.PropertiesAndBehavior。What is the difference between a member variable and a local variable? |--member Variables: defined in a class, can be accessed throughout a class, established as an object, exists in the heap memory where the object resides, and has default initialization values. |--Local Variables: Defined only in the local scope, in the stack memory, the scope of the action ends, the variable space is automatically freed; The local variable has no default initialization value.Anonymous Objects: When only one call is made to an object method, an anonymous object can be passed as an actual parameter.3. Object-oriented features|--Encapsulation: Hides the properties and implementation details of an object, providing public access only to the outside. Benefits: Isolation of changes, ease of use, improved reusability, and increased security. constructor Functionfeatures: function name is same as class name do not define return value type can not write return statementfunction: Class to Object|--Inheritance: generic extraction. When the same properties and behaviors exist in multiple classes, the content is extracted into a single class to improve code reusability. Benefits: Improves the reusability of the code, and makes the relationship between classes and classes a prerequisite for polymorphism. Features: Java only supports single inheritance, but supports multiple layers of inheritance (inheritance system)|--Abstract classfeatures: 1. Abstract methods can only be defined in abstract classes, and abstract classes and abstract methods must be decorated by the abstract keyword. 2. Abstract methods define method declarations only and do not define method implementations. 3. Abstract classes can not be instantiated 4. This subclass can be instantiated only if the subclass inherits the abstract class and implements all of the abstract methods. ‘Details: 1. There are constructors in the abstract class that are used to initialize the child class object. 2. Abstract classes can define non-abstract methods. 3. Abstract keyword abstraction can not coexist with final,private,static. 4. Abstract methods can be undefined in an abstract class.Template Method Design pattern: When a part of the implementation of the function is determined, part of the implementation is indeterminate. At this point, we can expose the uncertain parts and let the subclasses to achieve them. |--InterfaceInterface is an external rule; it is the extension of the function, and the appearance of the interface reduces the coupling. has a fixed member modifier: member variable public static final member method public abstractFeatures:1. Classes and interfaces are implementations of relationship implements. 2. Interfaces can be multi-implemented, avoiding the limitations of single inheritance. 3. Interfaces can inherit multiple interfaces.the difference between an abstract class and an interface: 1. Abstract classes can only be inherited by sheets, and interfaces may be implemented more. 2. Abstract classes can be defined non-abstract methods, subclasses can directly inherit the use of the interface, there are abstract methods, need subclasses to implement. 3. The abstract class uses the is a relationship, and the interface uses the like a relationship. 4. The member modifiers of the abstract class can be customized, and the member modifiers in the interface are fixed: public. Overrides and Overloads|--Overwrite (override):The child parent class is identical. Note: Private methods in the parent class cannot be overwritten; When overridden, the subclass method permission is greater than or equal to the parent class method permission; Static can only overwrite static. |--overloaded:only look at the parameter list of the function with the same name. The return value can be the same or different, and the return value type cannot be used as a distinguishing criterion for overloaded functions. |--Polymorphism: Multiple forms of ThingsEmbodiment:The parent class reference points to the subclass object.Benefits:Improve the extensibility of the program.Disadvantages:When a parent class reference points to a subclass object, although extensibility is improved, only methods that are available in the parent class can be accessed, not methods that are specific to the method subclass.Prerequisites:1. There must be a relationship (inheritance, implementation). 2. There is usually a overwrite operation. Inner class: Defines a class within another class, Access features: 1. Inner classes can access members in external classes directly, including private members. 2. The external class must establish an inner class object to access the members of the inner class.4. keywords|--this:this represents a reference to this class of objects. When do I use this? Use this when you need to use the object that calls the function within a function.|--super:Super Represents the parent class reference function:When a member of the same name appears in the child parent class, it can be distinguished by super, which can be used when the subclass is calling the parent class constructor.about Super () and this ()Two statements can only have one definition in the first row, so only one can appear;because super () or this () is called the constructor, the constructor is used for initialization, and the initialization action is done first, so be sure to define the first line. |--staticCharacteristics of a member after being modified by static:loaded with the load of the class;precedence over the existence of objects;be shared by all objects;can be called directly by the class name. Note the point:static methods can only access static members;the static method can not write this, super keyword;The main function is static. |--final:can be decorated with classes, methods, variablesFeatures: The final modified class is the ultimate class and cannot be inherited; The final modified method is a final method and cannot be overridden; The final modified variable is a constant and can only be assigned once.5. ExceptionsThrowable:Subclasses use the name of the parent class as the suffix of the child class.can be thrown. |--error:Errors, which typically occur when a major problem occurs, is not written against the code for its processing.|--exception:Everything that happens at run time can be handled by a try catch finally.methods in Throwable: |--getmessage (): Gets the exception information that returns the string.|--tostring ():Gets the exception class name and exception information, which returns a string.|--printstacktrace ():Gets the exception class name and exception information, as well as the location where the exception appears in the program, and returns a value of Vvoid.|--printstacktrace (PrintStream s):You typically use this method to save the exception content in a log file for review.throws and throw:|--throws:Used to identify an exception that is exposed by a function, used on a function, followed by an exception class name.|--throw:Used to throw an exception object, used inside a function, followed by an exception object.Exception Handling:Try{The code to be instrumented}Catch(Exception class, variable) {Exception Handling code}finally{The code that is bound to execute}Note: Only one case of the finally code block will not be executed, that is, System.exit (0) was executed previously. Custom Exceptions:steps:1. The custom class inherits exception or its subclasses. 2. Define the exception information through the constructor function. 3. Throw the custom exception through the throw.Exception Details:1. RuntimeException and its subclasses can be thrown out of a function without being declared on the function. 2. When a method is overwritten, the method that overrides it must throw the same exception or subclass of the exception. 3. If the parent throws multiple exceptions, the override (overwrite) method must throw a subset of those exceptions and cannot throw a new exception.access between packages:
Java Basics-Object oriented