JAVA Development Foundation (Overview)

1.Java Features and Benefits

Perfect object-oriented design and development

Java is inherently object-oriented design language, the perfect realization of mainstream object-oriented technology to improve software reusability.

Cross-platform

Programs written in the Java language can not undergo any changes after compilation, you will be able to run on any hardware device conditions. This feature is often referred to as "compile once, run anywhere."

Memory garbage collection

In the C / C ++ and other languages, the programmer responsible for recycling unwanted memory.
Java language programmers to reclaim the lifting of the liability useless memory space. It provides a system-level threads to track the distribution of storage space. And the JVM idle, checks and releases those memory space can be released.
Automatic garbage collection during the Java program is running.

2.java basis

2.1 Method

method: Is used to solve the problem for a class of ordered combinations of the code, it is a functional module.

Dynamic binding: Automatically selects the correct method called dynamic binding during calls.

Rewrite (cover): Subclasses can override inherited from a parent class, so as to allow subclasses add or change the behavior of the parent class method. This method is called Rewrite, it is one of the characteristics of OOP.

Overload: As defined in the parent class name and return value, but different method parameters.

The difference between the coverage and overloaded methods
Here Insert Picture Description

2.2, with the object class

Class is mold features (attributes) and determines the object will have a behavior (Method)

Class is an abstract concept, is merely a template

The object is the one you can see and feel the specific entity

Objects having both the properties and characteristics of the two methods

Method : operation on the object.

Properties : Object having various features.

2.2.1, class, member variables modifiers

Modifiers word class
Here Insert Picture Description

Modified member variable of the word :( behind several unusual)

[public | protected | private ] [static] [final ] [transient ][volatile]

Here Insert Picture Description

Modifying word member methods (behind several less common)

[public | protected | private ] [static] [final ] [transient ][volatile]

Here Insert Picture Description
Class, member variables modifiers
Here Insert Picture Description

2.2.2、final

Constants : public static final int FEMALE = 1 ; // on behalf of women

final是最终修饰符,可以修饰类、属性和方法。它几乎和abstract是完全相反的概念:

final类不能被继承,没有子类,final类中的方法默认是final的。

final方法不能被子类的方法覆盖,但可以被继承。

final成员变量表示常量,只能被赋值一次,赋值后值不再改变。

final不能用于修饰构造方法

在Java 接口中声明的变量在编译时会自动加上static final的修饰符,即声明为常量,因而Java接口通常是存放常量的最佳地点。

2.3 面向对象语言三个重要特性:封装、继承、多态

2.3.1 封装

封装:将数据和对数据的操作封装在一起。

2.3.2 继承

继承:子类可以继承父类的属性和功能,即继承了父类具有的数据和数据上的操作,同时又可以增添子类独有的数据和数据上的操作。例如:“人类”自然继承了“哺乳类”的属性和功能,又同时增添了人类独有的属性和功能。

在继承中,一般常见的有那些技术

在继承中,一般常见的有:属性继承,属性隐藏,方法继承,方法覆盖,方法重载等技术。

2.3.3 多态

多态:不同的对象接受到相同的消息名或者说当不同的对象调用相同的名称的成员函数的函数时,可能引起不同的行为(执行不同的代码)。这种现象称为多态性。

有两种意义的多态:

一种是操作名称的多态,即有多个操作具有相同的名字,但这些操作所接受的消息类型必须不同。例如,让一个人执行“求面积”操作时,他可能会问你求什么面积,所谓操作名称的多态是指可以向操作传递不同消息,以便让对象根据相应的消息产生一定的行为。

另一种多态是和继承有关的多态,是指同一个操作被不同类型调用时可能产生不同的行为。
当不同的对象接受到相同的消息名(或者说当不同的对象调用相同的名称的成员函数)时,可能引起不同的行为(执行不同的的代码)。这种现象称为多态性.

多态包括编译时多态和运行时多态两种。

编译时多态和运行时多态的区别 。

编译时的多态:是指参数列表的不同, 来区分不同的函数, 在编译后, 就自动变成两个不同的函数名. 在运行时谈不上多态。

运行时多态:用到的是后期绑定的技术, 在程序运行前不知道,会调用那个方法, 而到运行时, 通过运算程序,动态的算出被调用的地址. 动态调用在继承的时候,方法名 参数列表完全相同时才出现运行时多态。

2.4、接口、抽象类

2.4.1、接口

接口(Interface)是对符合接口需求的类的一套规范。

接口:JAVA中的接口是一系列方法的声明,是一些方法特征的集合。一个接口只有方法的特征没有方法的实现。因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为。

接口主要作用是可以帮助实现类似于类的多重继承的功能。

2.4.2、抽象类

在面向对象的概念中,所有的对象都是通过类来描绘的,但是反过来,并不是所有的类都是用来描绘对象的,如果一个类中没有包含足够的信息来描绘一个具体的对象,这样的类就是抽象类。

抽象类除了不能实例化对象之外,类的其它功能依然存在,成员变量、成员方法和构造方法的访问方式和普通类一样

由于抽象类不能实例化对象,所以抽象类必须被继承,才能被使用。也是因为这个原因,通常在设计阶段决定要不要设计抽象类

父类包含了子类集合的常见的方法,但是由于父类本身是抽象的,所以不能使用这些方法。

2.4.3、接口和抽象类的区别

1.一个类可以implements多个接口,而只能extends一个抽象类

2. Part of a method of abstract class can implement, and the interface are abstract methods and properties of
interfaces and abstract classes and Differences
Here Insert Picture Description

2.5, OO thinking summary

Here Insert Picture Description

[Unfinished, continued]

Published 15 original articles · won praise 0 · Views 507

Guess you like

Origin blog.csdn.net/qq_36335126/article/details/100151837