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中文網其他相關文章!

熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Java 8引入了Stream API,提供了一種強大且表達力豐富的處理數據集合的方式。然而,使用Stream時,一個常見問題是:如何從forEach操作中中斷或返回? 傳統循環允許提前中斷或返回,但Stream的forEach方法並不直接支持這種方式。本文將解釋原因,並探討在Stream處理系統中實現提前終止的替代方法。 延伸閱讀: Java Stream API改進 理解Stream forEach forEach方法是一個終端操作,它對Stream中的每個元素執行一個操作。它的設計意圖是處

PHP是一種廣泛應用於服務器端的腳本語言,特別適合web開發。 1.PHP可以嵌入HTML,處理HTTP請求和響應,支持多種數據庫。 2.PHP用於生成動態網頁內容,處理表單數據,訪問數據庫等,具有強大的社區支持和開源資源。 3.PHP是解釋型語言,執行過程包括詞法分析、語法分析、編譯和執行。 4.PHP可以與MySQL結合用於用戶註冊系統等高級應用。 5.調試PHP時,可使用error_reporting()和var_dump()等函數。 6.優化PHP代碼可通過緩存機制、優化數據庫查詢和使用內置函數。 7

PHP和Python各有優勢,選擇應基於項目需求。 1.PHP適合web開發,語法簡單,執行效率高。 2.Python適用於數據科學和機器學習,語法簡潔,庫豐富。

PHP適合web開發,特別是在快速開發和處理動態內容方面表現出色,但不擅長數據科學和企業級應用。與Python相比,PHP在web開發中更具優勢,但在數據科學領域不如Python;與Java相比,PHP在企業級應用中表現較差,但在web開發中更靈活;與JavaScript相比,PHP在後端開發中更簡潔,但在前端開發中不如JavaScript。

PHP和Python各有優勢,適合不同場景。 1.PHP適用於web開發,提供內置web服務器和豐富函數庫。 2.Python適合數據科學和機器學習,語法簡潔且有強大標準庫。選擇時應根據項目需求決定。

膠囊是一種三維幾何圖形,由一個圓柱體和兩端各一個半球體組成。膠囊的體積可以通過將圓柱體的體積和兩端半球體的體積相加來計算。本教程將討論如何使用不同的方法在Java中計算給定膠囊的體積。 膠囊體積公式 膠囊體積的公式如下: 膠囊體積 = 圓柱體體積 兩個半球體體積 其中, r: 半球體的半徑。 h: 圓柱體的高度(不包括半球體)。 例子 1 輸入 半徑 = 5 單位 高度 = 10 單位 輸出 體積 = 1570.8 立方單位 解釋 使用公式計算體積: 體積 = π × r2 × h (4

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP成為許多網站首選技術棧的原因包括其易用性、強大社區支持和廣泛應用。 1)易於學習和使用,適合初學者。 2)擁有龐大的開發者社區,資源豐富。 3)廣泛應用於WordPress、Drupal等平台。 4)與Web服務器緊密集成,簡化開發部署。
