Java SE 7 Released:First Major Update Since December 2006

Java 7 is generally available from today, the first release of the Java platform since Oracle's acquisition of Sun. The release includes a number of small but welcome changes to the language, incorporates a new file API and the Fork/Join Framework, and improves dynamic language support on the JVM.

自今天起Java7基本上就可以使用了,这是Oracle收购Sun以来的第一次Java平台上的发布。这次更新包括了为数不多的但是很受欢迎的变化,收编了新的文件API和Fork/Join框架(Fork/Join Framework包含在Java7并行库中,基于divide-and-conquer算法用于处理大数据量计算),并且改善了在JVM上对动态语言的支持。

For Java 7 language changes have been managed as part of Project Coin (JSR 334), a successor to JSR 201, designed to enhance the Java language with an assortment of small changes to improve productivity. Of particular note is the introduction of "try-with-resources". This is analogous to C#'s using statement but based on a form of the try statement. As a result, whilst the using statement only takes a single resource, try-with-resources is able to handle multiple resources within the scope of a given block.

Java7语言上的这些变化作为Project Coin(JSR 334)的一部分来管理,Project Coin(JSR 334)相对于JSR 201来说是一个成功的例子,被用来增强Java语言,通过对小的变化进行分类、整合来改善产品。特别值得一提的是引入了“try-with-resources”语句(称为ARM块<Automatic Resource Management>)。这很类似C#中的using语句但又是基于try语句的形式。不过,当使用using语句时,仅仅可以管理一个资源,而try-with-resource可以管理多个给定范围内的资源。

Two changes have been made to exception handling. First, multiple exception types can be named as being handled by a single catch block. The grammar of a catch clause of a try statement is extended to allow a series of exception types, separated by the "OR" operator symbol, "|", to be used in the declaration of the exception parameter. Second, if an exception parameter is not modified and if it is rethrown inside the catch block, you don't now have to add the exception to the method signature.

对于异常处理来说有两个变化。第一,多个被捕获的异常类型可以被指定在同一个catch块中。try语句的一个catch子句的语法被扩展为可以允许一系列的异常类型,多个异常类型之间用“或”操作符“|”分开,作为异常声明的参数。第二,如果一个异常参数没有被修改并且在catch块中重新被抛出,你现在不再被强制在方法声明中加入异常声明了。

Other language changes include:

1.Augmenting the switch statement to include Strings.
2.Support for binary literals and underscore separators in numbers to aid readability - for example long creditCardNumber = 1234_5678_9012_3456L;.
3.Simplified Varargs method invocation: A compiler change for warnings which are issued when a method combines varargs with non-reifiable array types. The change moves the warning from the call site to the method declaration.
4.Improved type inference for generic instance creation (< > or diamond): Uses limited type inference for class instance creation so that where parameter types need to be explicitly declared for a constructor, but they could be ascertained from the context, then they can be replaced with an empty set of type parameters.
Thus instead of writing:
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
You can write:
Map<String, List<String>> anagrams = new HashMap<>();

其他的语言层面上的变化包括:

1.扩大switch语句的功能,现在可以使用String了。
2.支持二进制字面形式的常量和以下划线分割数字的常量来增强可读性;举个例子long creditCardNumber = 1234_5678_9012_3456L;。
3.简化了可变参数方法的调用:编译器对可变参数的警告方式做了变化,过去备受争议的当一个方法联合可变参数和不可具体话的数组类型的警告问题,现在编译器把警告从调用处已到了方法定义的位置。
4.改进的为创建泛型实例设计的类型推断:使用有限的类型推断来处理类实例的创建,在构造器需要明确声明参数类型的场合,编译器能够根据上下文确定参数类型,所以它们只需用一个空的参数类型来代替即可。
以前我们这样写:
Map<String, List<String>> anagrams = new HashMap<String, List<String>>();
现在只需这样写:
Map<String, List<String>> anagrams = new HashMap<>();

Two major new APIs have been introduced. The first is JSR 203, which adds new APIs for file system access, scalable asynchronous I/O operations, socket-channel binding and configuration, and multicast datagrams. Of particular interest to enterprise developers is the addition of a true asynchronous IO API, important for high-end server applications that need low latency and high throughput across many connections. 203 also finally adds a real file system API to Java, providing support for some OS specific functions. You can, for example, create symbolic links on systems that support them. As such, it can be argued, 203 isn't strictly "write-once-run-anywhere", although it does provide a common API that works on all platforms, as well as the platform specific features.

两个主要的新API被引进。第一个是JSR 203,它添加了新的文件系统API,可扩展的异步I/O操作,socket-channel绑定和配置和组播数据电报。特别让企业级开发人员感兴趣的是增加的真正意义上的异步I/O API,这对于那些处理大量连接并且要求极少的等待时间和很高的生产量的高端服务器来说是很重要的。203最终也加入了真正的文件系统API到Java,对一些操作系统特出的功能提供了支持。举个例子来说,你可以在系统中支持它们创建一个符号链接。就其本身而论,它是可以引发争议的,尽管它确实提供了一个共同的API在所有平台上运行良好,就像平台所具有的特性,但203不是严格意义上的“write-once-run-anywhere”。

The second new API is the Fork/Join Framework (part of JSR 166), originally planned for Java 5. This provides a mechanism for developers to decompose problems into tasks that can then be executed in parallel across arbitrary numbers of processor cores.

第二个新API是Fork/Join框架(JSR 166的一部分),最初计划在Java5中添加。它提供了一个全新的机制,帮助开发者将问题分解为多个任务,它们可以在任意数量的处理器中并行的执行。

Elsewhere the platform sees new networking and security features, and expanded support for internationalisation including Unicode 6.0 support.

在别的地方,这个平台可以看到新的网络、安全特性和扩展的对国际化的支持包括Unicode6.0。

Finally, Java SE 7 marks the first new bytecode instruction since the beginning of Java, with the InvokeDynamic keyword. InvokeDynamic adds one more invocation mode, and one more linking mode, which can be programmed to user-definable specifications. It is specifically intended to support efficient and flexible execution of method invocations in the absence of static type information, which results in substantial performance improvements for dynamic languages, such as JRuby and Jython, which target the JVM.

最后,JavaSE7标示了自Java创立以来第一个新的字节码指令,附带新增的InvokeDynamic关键字。invokeDynamic又添加了一个调用模式,一个连接模式,这对于用户自定义的规范,可以以编程方式实现。它特别倾向于支持在无静态类型信息的情况下高效的、灵活的执行方法的调用,其结果是对于动态语言来说有了可观的性能提升,例如JRuby,Jython这些面向JVM的动态语言。

Whilst the new features are welcome, in many ways the most important thing about this release is that fact that it has been shipped at all. The long-running disagreement between Sun and the Apache Software Foundation, as well perhaps as leadership and resourcing problems in the final days of Sun, resulted in an unusually long hiatus between releases. As Mark Reinhold remarked in a recent interview:

虽然新特性很受欢迎,但在很多方面最重要的是它可以顺利实现发布。Sun和Apache基金会之间存在长期持续的意见分歧,以及在Sun的倒闭之前在领导之争和资源问题之争导致了发布的长期裂缝。Mark Reinhold在最近的一次访问中这样评论:

... for both business and political reasons Java kind of went into hibernation mode for a little while there. But we're back, and we're going to ship 7. It's not a revolutionary release, it's an evolutionary release, but it's got some really good stuff in it.

...对于商业和政见原因,Java有点像是进入了休眠模式。但是我们回来了,并且我们将立顶Java7。他并不是一个革命性的发布,而是一个渐进的发布,但是它确实囊括了一些好的东西。

Developers interested in getting started with the Java SE 7 release can leverage the NetBeans IDE 7.0, or IntelliJ IDEA 10.5, which support the latest features of the Java SE 7 platform. Eclipse Indigo also has beta level support for Java 7 available, and Oracle JDeveloper support for JDK 7 is intended for a release later this year.

对JavaSE7迫不及待开始体验的开发者可以使用NetBeans IDE 7.0,或者IntelliJ IDEA 10.5,它们都支持JavaSE7最新的特性。Eclipse Indigo也已经有了支持Java7的beta版本,Oracle支持JDK7的JDeveloper的发布似乎要等到年内的晚些时间。

翻译不周之处,敬请大家指正。

原文地址:http://www.infoq.com/news/2011/07/javase7-ga

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值