java EE study concluded the third week (including mind mapping)

The third week (2.17-2.23)

Day11

Supplementary two-dimensional array

  • Create a two-dimensional array syntax

    • First statement, redistribution space

      • Data Type [] [] array name; Array = new name Data type [high dimensional length] [low dimensional length];
    • First statement and allocated space

      • Data Type [] [] = new Array name Data type [high dimensional length] [low dimensional length];
    • Statement and assignment (Traditional)

      • Data Type [] [] = new Array name Data type [high dimensional length] []; // irregular array, new low self-dimensional array
    • And the assignment statement (simplified)

      • Data Type [] array name = {{v1, v2, v3}, {v4, v5}, {v6, v7, v8, v9}}; // initialize display

Objects

  • The concept: all objective existence of things are objects, Everything Is an Object

    • Features: called property, usually nouns, what represents the object has
    • Behavior: The method is called, generally what do verb, represents the object
  • All objective existence of things are objects, Everything Is an Object

  • Any object, must have its own characteristics and behavior

  • Program, you must have and the reality of the same object to simulate the real world

    • Use objects in the program object that represents reality, and perform actions, then solve practical problems
  • Objects created:

    public class TestCreateObject{
    public static void main(String[] args){

    Dog myDog = new Dog();
    myDog.breed =“莎魔”;
    myDog.age=2;
    myDog.sex=“公”;
    myDog.fuColor=“白色”;
    System.out.println(myDog.breed+"\t"+myDog.age+"\t"+myDog.sex+"\t"+myDog.fuColor);

    myDog.eat();
    myDog.sleep();

    }

    }

    • Creation of objects

      • Open space objects in memory
      • Imparting an initial value for each attribute
      • The constructor is executed code
      • The address of the object assigned to the variable

class:

  • Concept: defines the object should have the characteristics and behavior of the class is a template object

  • Class definition:

    example

    class Dog {public
    String Breed; // brand
    int age; // Age
    String sex; // gender
    String furColor; // fur

    public void eat(){
    System.outy.println(“Eating …”);
    }
    public void sleep(){

    System.out.println(“Sleeping…”);
    }

    }

    • Defined properties

      • Properties: The variable represents, also known as instance variables
      • Syntax: data type attribute name;
      • Inside the outer class, method: Location
    • Defined methods

      • Method: represented by a function, also known example of a method
      • Syntax: public return type method name (parameter) {// Method body}
      • Writing is no longer static

Contact classes and objects

  • Class: defines the object should have the characteristics and behavior of the class is a template object
  • Object: has a plurality of characteristics and behavior of entities, objects are instances of classes

The difference between local variables and instance variables

  • Local variables

    • Among the structures or methods: define the location
    • Default: no default
    • Range: from the definition of its ends to the structure containing
    • Naming conflicts: does not allow duplicate names
  • Member variables

    • Inside the outer class, method
    • Default: literals (the same array)
    • Use: This class of effective
    • Naming conflicts: can the same name and local variables, local variables priority

Examples of the method: Example Method object comprising two parts: implement a method for method declarations and

  • Method statement: what do representatives of objects

    • Composition: Modifier return type method name (parameter list)
  • Implementation of the method: how do representatives of objects: how to achieve the object corresponding function

    • Composition: []

Overloaded methods: the same kind of behavior objects may exist a variety of process implementation

  • Overload: a class name defined in the same manner a plurality of
  • Requirements: The method with the same name list of different parameters (type, number, sequence) and returns modifier, regardless of the value types return
  • When calling overloaded methods with the need to find a way to matching the passed arguments methods
  • Benefits: Use shielded difference, flexible and convenient

Code is wrong tune

  • Method name and parameter list two methods are the same, just not the same parameter name, compile error
  • Note: The only difference parameter name, does not constitute a method of overload

Constructor: Special method of the class, primarily used for creating objects

  • Feature

    • Exactly the same name and class name
    • No return value type
    • When you create an object. Can trigger a call to the constructor, the call can not be manually period
  • Note: If no constructor defined in the class, the compiler provides a default constructor with no arguments

Overloaded constructor: constructor can also be overloaded, overloading rules to follow

Constructor for the property assignment:

  • Create an object at the same time, the value passed in the constructor

Day12

Keyword

  • this

    • Class is a template that can serve all objects of this class is the default reference to this class, represents the current instance; when class service at the time of an object, this points to the object

    • Use a: this first usage: Call instance properties, instance methods. As this.name, this.sayHi ()

    • When an instance of the same name and local variables, local variables priority;. At this time, To access the instance variables, this prefix is ​​necessary to increase the same name does not exist, this may be omitted

    • Usage of Two: this second Usage: call other constructor in this class. As this () this (argument)

      • In the constructor call of other configurations of the present methods, can be configured logic code reuse method
      • Note: this (): call the no-argument constructor this (argument): There argument constructor method call: to be the first line in the constructor
      • There configuration parameters received argument passed directly to the structure assignment with a reference
  • super keyword

    • In a subclass to inherit from the parent class attributes and methods, but the presence of the same name (the shielding property, the method coverage) can be accessed directly, if the parent class property or method, it is necessary to distinguish between, before the special access

    • Usage: The method used in the form of super thereby completing the access to the parent class multiplexed in the sub-class, the additional function code and then superimposed to form the new features

    • super access attributes: a parent-child class attribute of the same name does not exist in covering relation, while the presence of two spaces (parent subclass shielding properties) need to use different prefixes for access

    • super call the superclass constructor with no arguments

      • super () indicates call the parent class constructor with no arguments. If you do not write. Implicitly present in the constructor of a subclass of the first line
    • Note: If the subclass constructors, no display definition super () or super (arguments) provides the default super () constructor method of the same sub-class, super () the this () can not coexist

  • instanceof keyword

    • Before the downward transition, should be determined in reference to the real object type, to ensure the accuracy of the type of conversion
    • Syntax: reference instanceof; type // Returns boolean type

Three characteristics

  • Package

    • In the external object for property assignment object, there may be data entry illegal
    • Permissions hidden objects as possible internal implementation details, and access control object modification: Concepts
    • Access modifiers: private (private may be modified property, visible only in this category)
  • Common Access Method

    • Public access methods to ensure proper data entry

      • Naming conventions

        Naming conventions:

        Assignment setXXX () // method parameters to achieve the assignment

        Value: getXXX () // implemented using the method returns a value ranging

  • inherit

    • One kind gift between classes or obtaining properties and behavior of

    • Abstract parent class: class in the same or a similar group, the extracted features and the common behavior defined in the parent class, reuse

    • Syntax: class subclasses of the parent class {} // extends the definition of subclass inherits the parent class display

    • Application: After generating off inheritance, the subclass can use the properties and methods of the parent class, a subclass can be defined specific attributes and methods

    • The succession created:

      • In creating an object has a continuing relationship, the building will first build subclass object parent object

      • By a common parent class content, unique content overlay subclass of it, into a complete sub-class object

      • Creation process

        • When building subclass object, first build parent class object
        • 1, 2 allocated space, build the parent object 3, 4 initialization properties, execute the code constructor
    • Benefits: only improves reusability of code, but also improves the scalability of the code

    • Note: java as single inheritance, a class can have only one direct parent, but can have multiple class inheritance, attributes and methods step by step superposition

    • Not inherit

      • Constructor: constructor class, this class is only responsible for creating an object, can not be inherited
      • private and modified properties: one of the access modifiers, visible only in this category
      • At the same time a parent-child class is not in the package, default attributes and the modified method: accessing one kind of modifier can be seen only with the package
  • Access modifier

    • private

      • This class is accessible. The same package. Unusual buns class, can not access other
    • default

      • This class, the same package can access. Unusual buns class, can not access other
    • protected

      • This class, with the package, buns extraordinary access class. Others can not access
    • public

      • This class, with package, extraordinary buns class, others can access
  • Cover Method

    • The method of covering the principles of

      • The method name, parameter list, the type of the return value must be the same parent
      • Access modifier may be the same or wider than the parent class the parent class
    • The method of execution coverage

      • Subclasses override the parent class method, the method preferentially executed after the call coverage subclass
  • Polymorphism

    example:

    Parent class reference
    (reference types) Animal a = new Dog () ; subclass object (object type)

    • concept:

      • Parent class objects to sub-class, thereby generating a variety of forms
    • Both having a direct or indirect inheritance, the parent class reference subclass object may point, i.e. polymorphic form

    • Parent class reference properties and methods can only be called the father declared, you can not call the child class's unique attributes and methods

    • Polymorphic application

      • Overloaded methods can solve the problem of receiving different object parameters, but the disadvantage is also obvious
      • A scene: As a method of using the parent class parameter achieve polymorphism, a method more general type parameters
      • Scene 2: using the parent class method returns a value as to achieve polymorphism, a method can return different subclass object
    • Upcast (packing

      • Parent class references stored real subclass object, called the upward transition (i.e., the core concept of polymorphism)
      • Note: Only the properties and methods Animal declared in callable
    • Downcast (unpacking)

      • The parent class references in the real subclass object itself strong back subclass type, called downcast
      • Note: Only converted back to a subclass of true type, before calling the subclass unique properties and methods
    • Abnormal type conversion

      • When the downward transition, if the parent class of the referenced subclass object and target types do not match, the type of translation exception occurs

Day13

Three modifiers

  • Application abstract class: abstract modified class, which is not new target

    • Modified abstract class, called an abstract class. An abstract class means incomplete class, not concrete classes, abstract class object can not exist independently, that is not new target

    • effect:

      • It can be inherited by subclasses, providing common properties and methods
      • It can be declared as reference, mandatory use of polymorphism
    • Experience: abstract superclass, as part of the subclass, the subclass dependence and the presence of the object, by the common parent class + subclass unique composition of complete sub-class object

    • Abstract methods: ({} part of) the abstract methods are intended to be modified, called an abstract method declarations only method, there is no way to achieve an incomplete manner, in an abstract class must contain

    • After generating inheritance, the subclass must override all the abstract methods in the parent class, abstract class or subclass or

    • to sum up

      abstract modification classes, objects can not be new, but the statement quoted
      abstract modification methods: only the method declaration, there is no way to achieve. (To be included in an abstract class)
      abstract class may not have abstract methods, but there are abstract methods must be abstract class
      after the subclass inherits the abstract class, must cover all of the parent class abstract method, or subclass or abstract class

  • static

    • Examples of attributes: instance attributes of each object is held by each independent space (more than), unilaterally modify the object, without affecting other objects

    • Static properties: static property is held in common by the entire class shared space (a), any object modification will affect other objects

    • Static state

      • Static properties and methods can be modified
      • Called static properties (class properties), the static method (class methods)
      • Static class members are full members of all shared objects
      • Only one, not because create multiple objects to produce multiple copies of the whole class
      • Instead of creating objects, can be directly accessed by the class name
    • Static method

      • Known static method

        • Arrays.copyOf()
        • Arrays.sort()
        • Math.random()
        • Math.sqrt();
        • Are directly using the class name calling
    • Static characteristics

      • Static method allows direct access to static members
      • Static methods can not directly access non-static member
      • Static methods are not allowed in this or super keyword
      • Static methods can continue and can not be rewritten, no polymorphism
    • Static code block

      public class TestStaticBlock(){
      public static void main(Stirng[] args){

      MyClass.method();

      }
      ]
      class MyClass{

      static String sField = "static properties";

      static {

      System.out.println (sField);
      System.out.println ( "static block");

      ]

      public static void method(){

      }

      }

      • When the class is loaded, the trigger performing a static code block (only once). Execution position: static properties after initialization. Role: to assign the static properties, or behavior necessary initialization
    • to sum up

  • final

    • Concept: The final, can not be changed

    • final content can be modified:

      • Class (final class)

        • final modified class, which can not be inherited
        • Note: String, Math, System are final modified class can not be inherited
      • Methods (final method)

        • final modification method: This method can not be overridden
        • Intended for the final approach does not support subclass modified form of coverage
      • Variables (final variables)

        • final modification of variables: This variable value can not be changed (constant)
        • Examples constant is no longer provide a default value, the initial value must be manually assigned. Assignment time: display initialization, dynamic code block constructor
        • Note: If an instance constructor constants assignment. We must ensure that all construction methods can correct their assignment
      • Static const

        • Static const no longer provide default values, you must manually assign an initial value. The timing of the assignment: display initialization, static code block
      • The object literal

        • final modification of the basic types: Value immutable
        • final modified reference types: Address immutable
      • to sum up

Dyl4

Modifiers

ABC e-commerce system

Day15

Knowledge-week summary

ABC E-commerce system code

Learning Mind Map

Here Insert Picture Description

Published 32 original articles · won praise 9 · views 3147

Guess you like

Origin blog.csdn.net/weixin_43501566/article/details/104634118