JAVA seventh day

The first part: oop concepts of object-oriented programming ideas

    Leader:

      Object (Object-Orientation, referred OO) is a system for modeling / programming ideas

      OO: Object-oriented programming is a set of ideas, methods, principles, patterns, solutions for the integration of the programming mode.

      OO thinking throughout the entire software development process, such as requirements analysis, design, programming, testing, upgrades and so on.

 

      Knowledge of shorthand: Object-oriented is the relationship between the class and the class to consider the needs, programming ... and so on.

 

        1, oop explained: programming in accordance with the object-oriented thinking

    2, a clear demand:

        2.1: Problem Domain: current business scope.

            Problem areas: schools

            Requirements: roll call

        2.2: core tasks: the main function

 

    eg: get (5,10] random number, object-oriented ideas to consider.

 

        Math.random();

        0.0-->1.0

        Math.random*5+5;

        Math.random * + minimum difference;

   

        Random r = new Random();

        r.nextInt(n);

        A random number 0-n

   

    3, object-oriented programming features: abstraction, encapsulation, inheritance, polymorphism

 

Part II: four basic features of object-oriented programming abstraction

    1, abstract: ignore the details of an object or entity

        And only concerned with the process of its essential characteristics.

}

        [Abstract is to get the class (template)]

         

    2, abstract need to address two things:

        2.1: abstract Xxx property

        2.2: abstract Xxx behavior

   

 

    3, after the completion of the abstract is to get the class -> Templates All Xxx

 

Concept classes and objects: a third portion

1, class

1.1: Everything can be abstracted:

    Entity and conceptual problem domain can be obtained the corresponding abstract class.

 

1.2: class is valid: java class is in a complex data type

 

1.3: Class action:

    1.3.1: Data Description: Attribute

    1.3.2: operational data: Method

  

Knowledge shorthand: class member variables using the description data (no specific value), using a method of operating data.

 

 

1.4: metadata categories: data description data, because the data in the form of an object in the field of object-oriented, so that the object class is an abstract description of a total of properties and methods.

 

2, Object

   Has all the properties and methods in the class,

   Property values ​​may be different,

   Method implementation can not be exactly the same,

  

   A group of individuals with the same attributes and behavior -> Object

 

   2.1: The class is a template, the template object is a self-generated.

    2.2: the role of the individual:

    This individual, you can call [his] [method] operating data.

    This individual may be assigned to the member variables and values ​​[].

 

    Special objects: only used to store data associated relationship

               The method of operation is no data javaBean

    Special objects: data only for operating

           service only method;

    Special objects: is used to interact with the database

           dao

   

 

    Section: the object is a unit that can be used in the program,

     Object also contains a lot of data,

     So, run java program is mutual interaction of various objects.

 

Part IV: define and use the class attributes and methods

1, property

1.1: declared in the class attribute:

Syntax: modifier type variable name

       Modifier type variable name = value;

eg: private String name = "小明";

    public int age;

    protected boolean isonline;

 

    public public, can access

    protected protection: only subclasses can access

    private private: Only the current inner class can use

    Do not write Default: accessible in the current package

 

Note: the class member variables can not give an initial value, there will be defaults.

2, method

2.1: Statement: class method declaration:

Syntax: modifier return type method name (parameter list)

    [Throws Exception Type] {

 

    // body of code

    // If the return type is not void there must

    return of a data return type;

}

Parameter List: used to declare variables,

     I variable declaration can be used in the current method

     [No assignment]

 

 

 

 

 

 

    eg:

    public void show(int age){

        syso ( "Bob" + age + "years old");

    }

    Explanation: The current method of returning void so the code does not return statement body

    int age This form of the method parameters, scope local to the current method.

2.2: Use: class method (call).

    Syntax: Object method name (parameter list corresponding to the type);

eg:

= New class object class name ();

Object name .show (10); // ①

So when the execution ① will show the code to perform the method.

When an incoming call the method 10 is the actual parameters.

Note: The object invoked method, this method is only part of the object can be called to.

 

Knowledge shorthand: method parameter is declared formal parameters

        When an incoming call the method parameter is the actual parameters.

Guess you like

Origin www.cnblogs.com/zjw19971001/p/11278442.html