首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

起草人带你剖析Java7.x新特性

2013-08-17 
笔者带你剖析Java7.x新特性前言?最近在ITeye上看见一些朋友正在激烈讨论关于Java7.x的一些语法结构,所以笔

笔者带你剖析Java7.x新特性

前言

?

最近在ITeye上看见一些朋友正在激烈讨论关于Java7.x的一些语法结构,所以笔者有些手痒,特此探寻了7.x(此篇博文笔者使用的是目前最新版本的JDK-7u15)的一些新特性分享给大家。虽然目前很多开发人员至今还在沿用Java4.x(笔者项目至今沿用4.x),但这并不是成为不前进的借口。想了解Java的发展,想探寻Java的未来,那么你务必需要时刻保持一颗永不落后的心。

?

?

?

当然笔者此篇博文并不代表官方观点,如果有朋友觉得笔者的话语是妙论,希望指正提出,笔者会在第一时间纠正博文内容。在此笔者先谢过各位利用宝贵的时间阅读此篇博文,最后笔者祝愿各位新年大吉,工作顺利。再次啰嗦一点,SSJ的系列博文,笔者将会在本周更新,希望大家体谅。

?

?

?

目录

?

一、自动资源管理;

?

二、“<>”类型推断运算符;

?

三、字面值下划线支持;

?

四、switch字面值支持;

?

五、声明二进制字面值;

?

六、catch表达式调整;

?

七、文件系统改变;

?

八、探讨Java I/O模型;

?

九、Swing Framework(JSR 296规范)支持;

?

十、JVM内核升级之Class Loader架构调整;

?

十一、JVM内核升级之Garbage Collector调整(时间仓促,后期讲解);

?

package com.test;import java.io.IOException;import java.nio.file.FileSystems;import java.nio.file.Path;import java.nio.file.Paths;import java.nio.file.StandardWatchEventKinds;import java.nio.file.WatchEvent;import java.nio.file.WatchEvent.Kind;import java.nio.file.WatchKey;import java.nio.file.WatchService;public class NIO2WatchService {//WatchService 是线程安全的,跟踪文件事件的服务,一般是用独立线程启动跟踪public void watchRNDir(Path path) throws IOException, InterruptedException {try (WatchService watchService = FileSystems.getDefault().newWatchService()) {//给path路径加上文件观察服务path.register(watchService, StandardWatchEventKinds.ENTRY_CREATE,StandardWatchEventKinds.ENTRY_MODIFY,StandardWatchEventKinds.ENTRY_DELETE);// start an infinite loopwhile (true) {// retrieve and remove the next watch keyfinal WatchKey key = watchService.take();// get list of pending events for the watch keyfor (WatchEvent<?> watchEvent : key.pollEvents()) {// get the kind of event (create, modify, delete)final Kind<?> kind = watchEvent.kind();// handle OVERFLOW eventif (kind == StandardWatchEventKinds.OVERFLOW) {continue;}//创建事件if(kind == StandardWatchEventKinds.ENTRY_CREATE){}//修改事件if(kind == StandardWatchEventKinds.ENTRY_MODIFY){}//删除事件if(kind == StandardWatchEventKinds.ENTRY_DELETE){}// get the filename for the eventfinal WatchEvent<Path> watchEventPath = (WatchEvent<Path>) watchEvent;final Path filename = watchEventPath.context();// print it outSystem.out.println(kind + " -> " + filename);}// reset the keyfboolean valid = key.reset();// exit loop if the key is not valid (if the directory was// deleted, forif (!valid) {break;}}}}/** * @param args */public static void main(String[] args) {final Path path = Paths.get("C://logs");NIO2WatchService watch = new NIO2WatchService();try {watch.watchRNDir(path);} catch (IOException | InterruptedException ex) {System.err.println(ex);}}}

?

?

?

http://gao-xianglong.iteye.com/blog/1819748

?

http://blog.csdn.net/zhongweijian/article/details/9258997

?

https://github.com/zhwj184/jdk7-8demo

?

热点排行