jdk1.5
1.自動(dòng)裝箱與拆箱(享元設(shè)計(jì)模式)
2.類型安全枚舉(參看)
3.靜態(tài)導(dǎo)入 (參看)
4.可變參數(shù)(Varargs)(參看)
5.內(nèi)省(Introspector)(參看)
6.泛型(Generic) (參看)
7.For-Each循環(huán)
8.元數(shù)據(jù)(注解)(參看)
jdk1.6
1.Web服務(wù)元數(shù)據(jù)(參看)
2.腳本語言支持 (參看)
3.JTable的排序和過濾(完整代碼示例)
4.更簡單,更強(qiáng)大的JAX-WS (參看)
5.輕量級(jí)Http Server (參看)
6.嵌入式數(shù)據(jù)庫 Derby (參看)
jdk1.7
1.switch中可以使用字串了。
2.運(yùn)用List<String> tempList = new ArrayList<>(); 即泛型實(shí)例化類型自動(dòng)推斷鸳址。
3.自定義自動(dòng)關(guān)閉類
以下是jdk7 api中的接口,(不過注釋太長扇住,刪掉了close()方法的一部分注釋)
/**
* A resource that must be closed when it is no longer needed.
*
* @author Josh Bloch
* @since 1.7
*/
public interface AutoCloseable {
/**
* Closes this resource, relinquishing any underlying resources.
* This method is invoked automatically on objects managed by the
* {@code try}-with-resources statement.
*
*/
void close() throws Exception;
}
只要實(shí)現(xiàn)該接口凤优,在該類對(duì)象銷毀時(shí)自動(dòng)調(diào)用close方法,你可以在close方法關(guān)閉你想關(guān)閉的資源,例子如下
class TryClose implements AutoCloseable {
@Override
public void close() throw Exception {
System.out.println(" Custom close method …
close resources ");
}
}
//請(qǐng)看jdk自帶類BufferedReader如何實(shí)現(xiàn)close方法(當(dāng)然還有很多類似類型的類)
public void close() throws IOException {
synchronized (lock) {
if (in == null)
return;
in.close();
in = null;
cb = null;
}
}
4.數(shù)字字面量下劃線支持
例如:int one_million = 1_000_000;
5.二進(jìn)制字面量
例如:int binary = 0b1001_1001;
6.Swing組件增強(qiáng)(JLayer,Nimbus Look Feel...)(參看)
7.捕獲多個(gè)異常類型和重新拋出異常與改進(jìn)類型檢查
- jdk7之前:
try {
......
} catch(ClassNotFoundException ex) {
ex.printStackTrace();
} catch(SQLException ex) {
ex.printStackTrace();
}
- jdk7例子如下
try {
......
} catch(ClassNotFoundException|SQLException ex){
ex.printStackTrace();
}
8.改進(jìn)的編譯器警告和錯(cuò)誤使用可變參數(shù)方法的非Reifiable形式參數(shù)
當(dāng)程序員試圖使用一個(gè)不可具體化的可變參數(shù)并調(diào)用一個(gè)varargs (可變)方法時(shí)谎痢,編輯器會(huì)生成一個(gè)“非安全操作”的警告。
9.java2D的增強(qiáng)(參看)
jdk1.8
- 允許在接口中有默認(rèn)方法實(shí)現(xiàn)(參看)
- Lambda表達(dá)式(參看)
- 函數(shù)式接口(參看)
- 方法和構(gòu)造函數(shù)引用(參看)
- Lambda的范圍(參看)
- 內(nèi)置函數(shù)式接口(參看)
- Streams
在新的類java.util.stream
包提供了一個(gè)流API來支持函數(shù)式的運(yùn)算元素的流卷雕。
該流API被集成到集合API节猿,它使上集合批量操作,例如連續(xù)或平行地圖漫雕,減少變換滨嘱。 - Parallel Streams
流操作可以是順序的,也可以是并行的浸间。順序操作通過單線程執(zhí)行太雨,而并行操作則通過多線程執(zhí)行。
并行操作提高運(yùn)行效率魁蒜。 - Map(參看)
map是不支持流操作的囊扳。而更新后的map現(xiàn)在則支持多種實(shí)用的新方法,來完成常規(guī)的任務(wù)兜看。 - 時(shí)間日期API(參看)
- Annotations(參看)
以上資料還不齊全锥咸,持續(xù)更新