My Android Learning note (still Java)

Source: Internet
Author: User
Tags control characters

Object oriented
* is a programming model that thinks abstract
* Complex problems are broken down into individual small problems, solving complex problems by solving each small problem individually.

Class
* Understood as "drawings"
* Abstract of things, algorithms, logic, concepts
* Encapsulation (encapsulates related data, code into a class component)

Object (instance)
* Understood as "product" created from "drawings"
* Each object occupies a separate memory space, saving its own property data
* Each object can independently control the code that allows him to execute the specified method

Reference
* Understood as "remote control"
* Reference variable holds the memory address of an object
By reference, you can find the storage space for this object and call its members
* Special value for reference type: null
null empty;
Memory address that does not reference a

Construction method
* Special method to execute when creating a new instance
New Soldier ()
New Flashlight ()
New Car ()
New Dog ()
New Point ()
* A class, must have a construction method
* If you do not define a constructor method,
When the compiler compiles the code,
The default constructor method is added
Class A {
Public A () {
}
}
* Constructor Method overloading
Class A {
Public A () {
}
Public A (int i) {
}
Public A (int i, String s) {
}
}
* Call between construction methods
This (...)
Reduce code Duplication

This
* Two types of usage
* Reference current object, save memory address of current object
This.xxx
F (This)
A = this;
* Construct calls between methods
This (...)
*) must be the first line of code

Parameter passing in Java-pass value
  • The value in the base type variable is the value itself
    Main () {
    int a = 10;
    f (a);//Remove the value of a and pass the parameter variable A to the F () method
    Print (a);//Printing 10
    }
    ...
    void f (int a) {
    A = 100;
    }

  • The value in the reference type variable, which is the memory address
    Main () {
    Point A = new point (3,4);
    f (a); The value of//a is the memory address, and the memory address is passed to the F () method
    Print (a.x);
    Print (A.Y);
    }
    F (Point a) {///parameter A refers to the address of the same object above
    a.x = 30;
    A.Y = 40;
    }

    Heavy duty overload
    * Different parameters of the same name

    Inherited

  • Role: Code reuse, code reuse
  • Single Inheritance:
    *) Sub-class, only one parent class
    *) Parent class, can have multiple subclasses
    *) Subclass, multiple parent classes can be inherited from the compartment

  • overriding override
    Methods inherited from the parent class,
    Does not meet the needs of sub-categories,
    You can rewrite this method in a subclass
    *) When overriding a method,
    can be used super.xxx ()
    Calling the code of a parent-similar method

  • To create a child class object
    1) First create the parent class object, execute the parent class constructor method
    2) recreate the subclass object and execute the subclass construction method

    *) Two objects are bound together,
    Whole as a subclass object

    *) When a member is called,
    Find the subclass first, then find the parent class

  • When creating a subclass object, first execute the parent class construction method

    *) Default execution of the parent class without a parameter construction method
    Super ()

    *) manually calling the parent class has a parameter construct
    Super (parameter)

    Super

      • Two kinds of usage

        • When overridden, invokes the parent in a similar way
          Public String toString () {
          ...
          Super.tostring ()
          ...
          }
      • Manually calling the parent class construction method
        Super (parameter)
        *) must be the first line of code

    Polymorphic
    * Function: Consistent type
    * Type Conversion
    *) Upward transformation
    Subclass object, converted to parent class type

    *) Downward transformation
    has been converted to a subclass object of the parent type, and then to the subtype

    *instanceof
    Determine the type of an object
    True for the real type, and for the parent type, to be judged
    Share s = new Line ()
    s instanceof Line True
    s instanceof Share True

    Abstract class
    Role
    *) provide generic code for subclasses
    *) provides the definition of a generic method for subclasses

    * Abstract class is semi-finished class, not completed class
    * Abstract class cannot create instances, only instances of his subclasses can be created

    * Classes that contain abstract methods must be abstract classes
    Abstract class, does not necessarily contain abstract methods

    Final
    * Modifier variables, methods and classes
    * Variable: means that the value of the variable is immutable and becomes "solid"
    *) The value of the base type, which is the value itself is immutable
    *) The value of the reference type, which is the reference address is not mutable
    Final int a = 10; a=11//wrong

    Final Point A = new point (3.4);
    a.x = 30;
    A = new Point (1,5);
    A =null; wrong.

    * Method: Method cannot be overridden by quilt class

    * Class: Cannot be inherited

    Static (statically)
    * Static members belong to classes, not instances
    Class soldier{
    INT ID;
    }
    * Call a static member, which should be called using the class name
    Soldier S1 = new Soldier ();
    Soldier s2 = new Soldier ();
    The following code is easy to misunderstand
    S1.count = 1;
    S2.count = 2;
    Print (S1.count)

    Soldier count = 3;
    Print (Soldier.count);

    * When to use static
    *) Use principle: Can not be used.
    Static is "non-object-oriented" syntax
    *) Usage Scenarios:
    *) shared data between instances
    *) Tool method
    MATH.SQRT ()
    Integer.parrseint ()

    * Non-static members cannot be called in a static method
    Class a{
    public static void Main (string[] arges) {
    f ();//Wrong cannot call non-static member
    A a=new a ();
    A.F ();

       g();}   Static void g(){  }       Void f(){      }

    }

* Static Initialization fast
Class a{
static{

}
}
*) for the first time in Class A, load Class A is, execute only once

Constant
*static final
* Naming habits: Full capitalization, underlined between words
Static final int max_value = 100;

Object creation Process
Class a{
INT v1 = 1;
Static int v2 = 2;
static{

}
Public A () {
.....
}
}

Class B extends a{
INT v3 = 3;
Static int v4 = 4;
static{

}
Public B () {
.....
}
}

b b = new B ();
* Class A and Class B for the first time
1. Load the parent class to allocate memory for the parent class static member variable
2. Loading subclasses, allocating memory for subclass static member variables
3. Perform the parent class static variable assignment operation and execute the static initialization block
4. Perform a subclass static variable assignment operation and execute a static initialization block

* Used again in Class A and Class B
5. Create the parent class object and allocate memory for the parent class non-static variable
6. Creating subclass objects, allocating memory for subclass non-static variables
7. Perform a non-static variable assignment operation on the parent class
8. Executing the parent class construction method
9. Performing sub-class non-static variable assignment operations
10. Implementing Subclass Construction Methods

Access control characters
* Control the access scope of members in classes and classes
Any kind of bun class
Public 0 0 0 0
Protected 0 0 0
[Default] 0 0
Private 0

*) How to select the Access control character
Principle: Use small range as far as possible
Public is a contract with other developers, and what is promised will remain constant.
Private hidden. facilitates the maintenance and modification of code without affecting other program components

Interface
* Function: Structural design tool, used to decouple
* Is the extreme abstract class
* Replace the class keyword with interface
* Replace extends keyword with implement
* The interface can only be defined
*) Public constants
*) Open abstract methods
*) exposed internal classes, internal interfaces

* A class can implement multiple interfaces at the same time
Class A implements b,c,d{
}
Class extends B implement c,d,e{
}
* Inheritance between interfaces
An interface that can integrate multiple other parent interfaces
Interface A extends b,c,d{
}

Inner class
* Defined inside a class, inside a method, within a local code block

* Non-static inner class
*) Non-static inner class, dependent on the existence of an external class instance
*) Static members cannot be defined in a non-static inner class
Class a{
Class inner{
}
}
A = new A ();
A.inner i = A.new Inner ();

* Static Inner class
Class a{
Static class inner{
}
}
A.inner i = new A.inner ();

* Local inner class
*) types that are not defined can only be used within a local code block
Class a{
Weapon F () {
Class Inner implements weapon{
}
Inner i = new Inner ();
Return i;
}
}

A = new A ();
Weapon w = A.F ();
W.kill ();

* Anonymous Inner class
Weapon W = new weapon () {...};
*) curly braces are anonymous classes
*) New Anonymous class instance
*) weapon is the parent type

My Android Learning note (still Java)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.