# Java 隨手記 ###### tags: `Java` `OOP` ## 雜項: * C like language but without C pointer. * Standard Edition(SE) * Java, JDBC...etc * Make out: Java App. * Enterprise Edition(EE) * Servlet、JSP、framework ...etc * Make out: Java Web App. * [Object-oriented programming (OOP)](https://hackmd.io/@lWS61UOJTMqj5_qsZv5VtA/S1HAFFOU9): * 抽象 Abstraction * 封裝 Encapsulation * 多型 Polymorphism * 繼承 Inheritance * Java檔案名稱必須與class名稱一致 * 函式庫 [API (Application Programming Interface)] * 又稱 Library、Framework、SDK * Basic API: * Java.lang (Java langauge) * Java.util * Java.io * API for window interface: * Java.awt * Java.awt.event * Java.swing * [JDBC](https://hackmd.io/@lWS61UOJTMqj5_qsZv5VtA/Hkze5YuL9) * 變數 * Camel Case: 小寫開頭,有後字則後字大寫開頭 * CONSTANT 常數使用全大寫 ## 八大基本資料型別 * 整數 * byte (1 Byte) 0 * short (2 Byte) 0 * int (4 Byte) 0 * long (8 Byte) 0L * 浮點數 * float (4 Byte) 0.0f * double (8 Byte) 0.0 * 字元 * char (2 Byte) * boolean (1 Byte) * 晉升 Promotion * 等號右邊資料型別較小者,右邊自動晉升 ``` double = 1 ``` * 轉換 Casting * 用()強制轉換型別 ``` double a = 10.5 int y = (int) a ``` ## 基本語法 * if-else ``` if (condition 1) { statement 1; } else if (condition 2){ statement 2; } else { statement 3; } ``` * switch-case ``` switch (expression){ case value1: statement 1; break; case value2: statement 2; break; default: statement 3; } ``` * for loop ``` for (initialValue; condition; initialValue++){ statement } ``` * for each ``` for (initialValue : Array){ statement } ``` * while loop ``` while (condition){ statement } ``` * do while loop ``` do{ statement }while (condition) ``` ## 記憶體 * Stack區 * 基本型別變數(紀錄值) * 物件變數(紀錄物件所在的記憶體位置) * Heap區 * 物件 * String pool * Metaspace * 類別的定義 * 全域變數 ## 基本物件 * String (p64) * java.lang.String * Array (p67) * java.util * Object (p112) * java.lang.Object * 為所有類別的父類別,在Object上的方法適用於所有物件 * Date (p138) * java.util.Date * Wrapper classes (p127) * 將基本型別轉為物件 ## 方法 * static 類別成員 (p74) * static 方法 (p76) * **Overloading** (p79) * 方法名稱相同,但參數的個數或型態不同 ## Modifier 修飾子 * Access Control Modifier (p99) * public、protected、no modifier、private * final (p100) * static final (用以定義系統常數) * **abstract** (p101) ## Interface 介面 * 介面中全部都是抽象方法,且沒有建構方法 * 介面只有功能上、規格上的宣告 * 介面上定義的常數都是static final * 變數名稱一律大寫,用底線區隔不同字 * implement 實作 (p108) * extends 繼承 (p107) ## Exception * Throwable (p117) * Error * Exception * try - catch ``` try { statement; }catch(Exception_type ex){ statement when exception happened; }finally{ statement that must done; } ``` * 多重catch (p118) * Exception中屬於子類別的要放前面catch * throws * try with resource (p140) * Java 7 以後支援 * AutoCloseable介面: 定義close() ``` try (resource_Objects){ statement; } catch (Exception_type ex){ statement when exception happened; } ``` * ()中的 Resource_Objects 在執行完try{}區塊後 會自動執行close()方法 ## Collection 集合 * ArrayList (p126) * Iterable & Iterator (p128) * Set & HashSet (p129) * Map & HashMap (p133) * keySet() ## Generic 泛型 * 型態參數化(Parameterized types) ``` List<Product> list = new ArrayList<Product>() ``` * 限制集合中為特定型態的物件 ## Stream io * 處理byte: * FileInputStream * BufferedInputStream * BufferedOutputStream * FileOutputStream * 處理文字: * FileInputStream * InputStreamReader * BufferedReader * BufferedWriter * OutputStreamWriter * FileOutputStream ### [作業存放區](https://github.com/JenCHuang/JavaSt/tree/master/JavaHW)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up