Java Programming Thought Notes "One"

1. Objects have behavior, state, and identity.

2. The character set used by the java language: Unicode character set , which has 65535 bytes and can represent any character.
3. Identifier
    Definition: A sequence of characters consisting of letters, numbers, underscores, $ and other characters.
    Function: used to represent variable names, method names, class names, interface names, etc.
    Rules:
        > Cannot start with a number > Can contain numbers, letters, currency symbols, Chinese characters, etc. > The length is not limited, but it is best not to be too long > Cannot contain Spaces, semicolons, commas, single quotes, double quotes, etc. > java keywords (reserved words) cannot be used as identifiers
         
         
         
        

4. Three major characteristics of java: inheritance, encapsulation, and polymorphism

    Inherit

        About inheritance:

                         > Improve code reusability;

                         > Class is the abstraction of objects, inheritance is the abstraction of a certain group of classes, so as to achieve better modeling of the real world                          > Keyword extends
 

                        > There is only single inheritance in java (only one direct parent class), avoiding the complexity of multiple inheritance in c++,

                            Multiple inheritance can be achieved by implementing interfaces.

                         > In addition to inheritance, composition can also achieve code reuse, but from a modeling perspective, inheritance is an is-a relationship, and composition is a has a relationship.

                            However, try to use combination to generate new types in code design, otherwise too much use of inheritance will make code design too complicated.

                           Inheritance breaks encapsulation
  package
        Purpose : High cohesion, low coupling
                > High cohesion----- The internal data operation details are completed by themselves, and external interference is not allowed
                > Low coupling---- only expose a small number of methods for external use

        Packaging points:

                 > All general member variables use private modification, constant or static modified class variables, use public    

                > Provide the corresponding set/get method to access the corresponding attribute, (the get method of the boolean variable starts with is)

               > Auxiliary classes in this class, use private

polymorphism

        About polymorphism:

                 > Polymorphism refers to polymorphism of methods, fields and static methods do not exist polymorphism
                > Three necessary conditions for polymorphism: inheritance, method overriding, parent class reference pointing to child class object
                > Reference variable type:
                        Compile-time type - determined by the declared type
                        Runtime type - determined by the actual object type
                > Through the object call field, the data in the memory to be called has been determined at compile time,
                     Therefore, there is no rewriting of fields. In polymorphism, there is no polymorphism for fields.
                 > The method must be pushed onto the stack at runtime, so it is only at this time that it is possible to know which method is called .
                 > You can use the instanceof keyword to determine the object type
                 > Features of polymorphism: At runtime, subclass methods are called.
                 > The benefits of polymorphism: unified behavior, easy coding. Improve code reuse and maintainability and scalability.

5. this and super

       In ordinary methods , this and super are implicitly passed as parameters, that is, the current object reference and the direct parent object reference ;

    this always points to the object on which the method is being called;
       In constructors, this is often used to initialize parameters
     Calling other constructors through this, or calling the superclass constructor through super, must be placed on the first line
       Methods overridden by subclasses can be called through super
       If there is a static method in the subclass method that is the same as that in the parent class, then this phenomenon is hidden and not overridden .
        Therefore, in the case of polymorphism, when the parent class refers to calling the corresponding static method, if both of them have the same static method, they should be called carefully.


Guess you like

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