jdk7 jdk8 变化

1 二进制变量的表示,支持将整数类型用二进制来表示,用0b开头
byte aByte = (byte) 0b00100001;
2 数字类型的下划线表示 更友好的表示方式,不过要注意下划线添加的一些标准。 不能开头或结尾
3 Switch语句支持String类型。
4 Try-with-resource语句: 多个try
try (
java.util.zip.ZipFile zf =
new java.util.zip.ZipFile(zipFileName);
java.io.BufferedWriter writer =
java.nio.file.Files.newBufferedWriter(outputFilePath, charset)
) {
// Enumerate each entry
for (java.util.Enumeration entries =
zf.entries(); entries.hasMoreElements();) {
// Get the entry name and write it to the output file
String newLine = System.getProperty("line.separator");
String zipEntryName =
((java.util.zip.ZipEntry)entries.nextElement()).getName() +
newLine;
writer.write(zipEntryName, 0, zipEntryName.length());
}
}
BufferedWriter和ZipFile对象的close方法都会自动按声明的相反顺序调用。

try (Statement stmt = con.createStatement()) {
5 多个catch
catch(IOException | SQLException | Exception ex){


jdk8
1 接口的默认和静态方法:
Java 8允许我们给接口添加一个非抽象的方法实现
public interface JDK8Interface {

// static修饰符定义静态方法
static void staticMethod() {
System.out.println("接口中的静态方法");
}
2 Lambda 表达式:(例如: (x, y) -> { return x + y; } ;λ
public int add(int x, int y) {
return x + y;
}
变为 (int x, int y) -> x + y;

c -> { return c.size(); }

3 方法与构造函数引用::
通过Person::new创建一个指向Person构造函数的引用。 请注意构造方法没有参数
静态方法:User::collide
类实例User::repair

4 支持多重注解
5 日期函数和 Base64
提供了新的java.time包,可以用来替代
java.util.Date和java.util.Calendar。一般会用到Clock、LocaleDate、LocalTime、LocaleDateTime、ZonedDateTime、

6 CurrentHashMap做了升级--重要

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值