[Java] Getting Started (03)

  This chapter can be said that Java is the most important, yes we all know, Java is an object-oriented programming, an object of this chapter is to talk with the class.

  

  1 Overview:

        A, object-oriented programming, referred to as (OOP) , Java is a fully object-oriented, must be familiar with OOP to be able to write Java programs.

      B, object-oriented program is composed of the objects, each object comprising a function part and a specific part of the user to realize hidden disclosed.

      C, program many objects from the standard library, there are some things custom.

      D, as long as the object is able to meet the requirements, do not have to be concerned about its features specific implementation process.

      E, the process-oriented programming, the algorithm is the first place, the data structure is the second place; of OOP reverses this order, the data in the first place, the algorithm in / operating data on the back .

    


  

  2, type:

    A, class (class) is constructed object template or blueprints.

     B, the class structure (Construct) procedure is called to create an object class instance (instance) .

       Principle C, OOP, allowing users to custom Java classes easier, that is: You can create another new class by extending a class.

     D, in Java, all classes are derived from a "magical wand superclass" Object.

     E, when expanding an existing category, the new class after having extended all the attributes and methods of the expanded classes.

       F, to the process of establishing another class by extending a class called inheritance (Inheritance ).

     G, the relationship between the classes:  

Relations between classes
relationship description
Dependent ( "uses-a")

A, dependence (dependence), i.e., "uses-a" relationship, one of the most obvious is the most common relationship.

B, if the object class method of operating a / A, another class A / B, we can say that the class / A dependent another class / B.

C, to minimize the interdependence of the class, modifications may reduce the number of class Bug as a result of emergence, which is called the minimum degree of coupling.

D, C above statement, is to reduce the interdependence of the class, in fact, low coupling argument.

Polymerization ( "has-a")

A, polymerization (aggregation), i.e. "has-a" relationship.

B, class A mean polymerization object contains a number of objects of class B

C, in Java's core technology, the authors suggested that we use the word polymerization, rather than association.

继承("is-a")

A, inheritance (inheritance), i.e. "is-a" relationship.

 

 


 

  

  3. Object:

    A, to use OOP, be sure to clear the object of three main features:  

          * Behavior (behavior) of an object - which operations can be applied to an object, or a method which may be applied to the object.

          * State of the object (State) - which method is applied when, how objects respond

          *    Object Identifier (the Identity) - How to identify the state has the same behavior with different objects

        B, the state of the object by calling the method to be implemented (if not through the method call can change state only that the destruction of the package).

      C, in order to use the object, you must first build object and specify an initial state; then the method of the target application.

      D, in Java, is to construct a new instance constructor (constructor); constructor is a special method, and is configured to initialize the object .

      E、想要构造一个对象,需要在构造器前面 加上 new 操作符/// 例如下面的 Date 类,我们要构造一个 Date 对象/// Date 就是构造器。

/// 构造器的名称 要跟类名一样。
Date dateObj = new Date();

/// JavaScript:
class 类名 {
///  constructor 是构造函数 / 也叫构造器,可能是 Java 习惯叫 构造器
   constructor() {}
}

 

      F、对象和对象变量之间 存在一个重要的区别,对象变量,它是未引用对象,只声明了的变量。不能使用类的方法。

      G、Java 中的对象变量,可以理解成 C++ 中的指针,大概意思就是,编程语言在 内存中 创建好一个对象,放在那里,然后变量名只是指向这一块内存的地址。

      H、所以 为什么上一章的 数组赋值 是浅拷贝。

      I、在 Java 中,最简单的类定义形式为:  

class ClassName 
{    
    field 1
    field 2
    ...
    
    /// 其中 constroctor 是 Java 中,类的构造函数,
    ///  这里不是有多个构造函数,而是一个方法重载的概念,我在下一章会说。
    constructor1
    constructor2
    ...
   /**
* A、Java 中的实例域,即,类的字段(属性),局部的,全局的。在实例化后变成了 对象的 属性或者字段,这个时候就叫做实例域
   *   对比了一下,应该在 constructor 中有 赋值的 类属性/字段,实例化后,带的属性,都叫实例域,因为在实例中能访问到。

* B、静态域,也叫 类域,应该就是上面 field 使用 static 定义后的属性。
* 意思准不准确不好说,我先这样认为先,后面更加清楚后,会修改,这里个人建议自己去查意思。
*/ method1 method2 ... }

 

Guess you like

Origin www.cnblogs.com/-xk94/p/12332822.html