搜尋
首頁Javajava教程Java程式設計思路方法的總結
Java程式設計思路方法的總結Jul 17, 2017 pm 04:17 PM
java總結筆記

  總覺得書中太囉嗦,看完總結後方便日後回憶,本來想偷懶網上找別人的總結,無奈找不到好的,只好自食其力,盡量總結得最好。

 

物件導論

看到物件導論覺得這本書

 

目錄:

1.1 抽象過程
1.2 每個對象都有一個介面
1.3 每個物件都提供服務
1.4 被隱藏的具體實作
1.5 復用具體實作
1.6 繼承
1.7 伴隨多型的可互換物件
1.8 單一繼承結構
1.9 容器
1.10 物件的建立與生命期
1.11 例外處理:處理錯誤
1.12 並發程式設計
1.13 Java與Internet
1.14 總結


覺得看完終於要精通Java了,然而本章只是介紹開發方法概述在內的OOP的基本概念,了解對象的重要性。


1.1 抽象過程

#透過其他語言的缺點來說明面向對象語言的好。

彙編語言是對底層機器的輕微抽象、命令式語言(如C、BASIC)是對彙編語言的一種抽象,彙編語言直接控制電腦的硬件,命令式語言則基於電腦結構解決問題。 OOP語言基於問題的結構解決問題,不會受限於任何特定類型的問題。

1.2 每個物件都有一個介面

#介面:確定了對某一特定物件所能發出的請求     物件:型別名稱

看文字描述已經上升到哲學問題,從下面例子很好理解。

Light lt = new Light(); //对象lt.on;//接口向对象发出请求

 

1.3 每個物件提供服務

好處:1、有助於提升軟體的內聚性  2、每個物件都可以很好的完成一項任務,但它並不試圖做更多的事情。

理解:設計一個音樂播放器,有歌詞顯示、播放,暫停、背景顯示(服務),這時不要只提供一個物件(它不試圖做更多的事情),可以提供三個對象,完成三個服務,三個對象提供三個服務完成一個音樂播放器(內聚性)。

1.4 被隱藏的具體實現

#從Github下載一個框架,我的目標是實現快速應用開發,框架只需提供我方法的呼叫即可,其他的隱藏了也不會影響我的呼叫

存取權:public > protected(套件+基底類別) > 套件存取權限(沒有關鍵字時預設) > private

#1.5 重複使用具體實作

複用指在一個類別中使用繼承或組合。

  • 繼承----is a 的關係     荔枝是水果

  • ##組合- ---has a 的關係   有一種睡覺的方式是趴著

#1.6 繼承

################################ ###從父類衍生出子類,子類能吸收父類的資料屬性和行為,並能擴展新的能力。 ###############1.7 伴隨多態的可互換物件############ ######
class Shape{ 
  draw();
  erase();
  move();
  getColor();
  setColor();
}
#######
void doSomething(Shape shape){
shape.erase();//...shape.draw();
}

Circle circle = new Circle(); //父类为ShapeTriangle triangle = new Triangle();  //父类为ShapeLine line = new Triangle();  //父类为ShapedoSomething(circle);
doSomething(triangle);
doSomething(line);
###

对doSomething的调用会自动地正确处理,而不管对象的确切类型(可互换对象)。

doSomething(Shape shape)的执行是指你是Shape类或者父类为Shape,而不是你是Circle类就执行这样,你是Triangle 类就执行那样。理解了可以去看设计模式之策略模式。

这里还涉及到向上转型,如下图:

 

1.8 单根继承结构

 1、所有类都继承自单一的基类

public class JianCheng extends Object {  
}
public class JianCheng {  public static void main(String[] args) {  
        JianCheng jiancheng= new JianCheng();  
        System.out.println(JianCheng instanceof Object);  
    }  
}

Output: true //ExplanationJianCheng class inherits by defaultObject

2. Ensure that all objects have certain functions

Object methods will be inherited by subclasses, such as: clone(), equals( Object obj), toString() and other methods.

3. Garbage collection becomes easy

The object is guaranteed to have its (Object) Type information, so you don't get stuck in an inability to determine the type of an object. This is important for system-level operations (such as exception handling).

1.9 Container

holds access to other objects References are called containers (collections), such as List (used to store sequences), Map (also known as associative array, used to establish associations between objects), Set (only one of each object type is held), and such as Queues, trees, stacks and more.

Comparison between ArrayList and LinkedList, the former is the shape of an array, randomly accessing elements has a small overhead, but insertion and deletion operations have a high overhead. The latter is in the shape of a linked list, insertion and deletion operations are easy to operate.

1.10 Object Creation and Lifetime

Understanding The difference between objects placed on the stack and the heap

  • Allocation and release between stack-- are given priority Position,sacrifice flexibility, becausemust know the exact number, lifetime and type of objects.

  • ##Heap--dynamically created objects in the memory pool at runtime Know the number, lifetime and type of objects. Dynamic management requires a lot of time to allocate storage space in the heap, but creating storage space and releasing storage space is very convenient.

#Java adopts By using the new keyword to create an object using dynamic memory allocation, the compiler can determine how long the object will survive and automatically destroy it through the "garbage collector mechanism".

##1.11 Exception handling: handling errors

Exception is an object that is thrown from the error location and is caught by a specific type of error exception handler, through try--catch or throw. Exception handling is like another path that is executed when an error occurs, parallel to the normal execution path of the program.

If the Java code does not write the correct exception handling code, you will get a compile-time error message. For example: IOException, ClassCastException (class conversion exception), NullPointerException (null pointer exception), etc.


1.12 Concurrent ProgrammingProcess multiple processes at the same time The idea of ​​tasks is to run in multiple threads.


There is a hidden danger in synchronous multi-threaded operation, shared resources. A originally wanted to use a=Love You, but a certain thread led to a=hate you and then A used it, so A's confession will definitely fail.

1.14 Summary


##The first chapter is all theoretical knowledge, and many knowledge points are obviously easy However, the long explanation makes it difficult to understand. There is some practical information but it is mixed with too much fluff.

以上是Java程式設計思路方法的總結的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
带你搞懂Java结构化数据处理开源库SPL带你搞懂Java结构化数据处理开源库SPLMay 24, 2022 pm 01:34 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于结构化数据处理开源库SPL的相关问题,下面就一起来看一下java下理想的结构化数据处理类库,希望对大家有帮助。

Java集合框架之PriorityQueue优先级队列Java集合框架之PriorityQueue优先级队列Jun 09, 2022 am 11:47 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于PriorityQueue优先级队列的相关知识,Java集合框架中提供了PriorityQueue和PriorityBlockingQueue两种类型的优先级队列,PriorityQueue是线程不安全的,PriorityBlockingQueue是线程安全的,下面一起来看一下,希望对大家有帮助。

完全掌握Java锁(图文解析)完全掌握Java锁(图文解析)Jun 14, 2022 am 11:47 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于java锁的相关问题,包括了独占锁、悲观锁、乐观锁、共享锁等等内容,下面一起来看一下,希望对大家有帮助。

一起聊聊Java多线程之线程安全问题一起聊聊Java多线程之线程安全问题Apr 21, 2022 pm 06:17 PM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于多线程的相关问题,包括了线程安装、线程加锁与线程不安全的原因、线程安全的标准类等等内容,希望对大家有帮助。

Java基础归纳之枚举Java基础归纳之枚举May 26, 2022 am 11:50 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于枚举的相关问题,包括了枚举的基本操作、集合类对枚举的支持等等内容,下面一起来看一下,希望对大家有帮助。

详细解析Java的this和super关键字详细解析Java的this和super关键字Apr 30, 2022 am 09:00 AM

本篇文章给大家带来了关于Java的相关知识,其中主要介绍了关于关键字中this和super的相关问题,以及他们的一些区别,下面一起来看一下,希望对大家有帮助。

Java数据结构之AVL树详解Java数据结构之AVL树详解Jun 01, 2022 am 11:39 AM

本篇文章给大家带来了关于java的相关知识,其中主要介绍了关于平衡二叉树(AVL树)的相关知识,AVL树本质上是带了平衡功能的二叉查找树,下面一起来看一下,希望对大家有帮助。

一文掌握Java8新特性Stream流的概念和使用一文掌握Java8新特性Stream流的概念和使用Jun 23, 2022 pm 12:03 PM

本篇文章给大家带来了关于Java的相关知识,其中主要整理了Stream流的概念和使用的相关问题,包括了Stream流的概念、Stream流的获取、Stream流的常用方法等等内容,下面一起来看一下,希望对大家有帮助。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中