针对这些新特性汇总以下: html
1、针对java编程语言(Java Programming Language) java
1.lambda表达式:一种新的语言特性,可以把函数做为方法的参数或将代码做为数据。lambda表达式使你在表示函数接口(具备单个方法的接口)的实例更加紧凑。 程序员
public class Calculator { interface IntegerMath { int operation(int a, int b); } public int operateBinary(int a, int b, IntegerMath op) { return op.operation(a, b); } public static void main(String... args) { Calculator myApp = new Calculator(); IntegerMath addition = (a, b) -> a + b; IntegerMath subtraction = (a, b) -> a - b; System.out.println("40 + 2 = " + myApp.operateBinary(40, 2, addition)); System.out.println("20 - 10 = " + myApp.operateBinary(20, 10, subtraction)); } }
2.方法引用 是lambda表达式的一个简化写法,所引用的方法实际上是lambda表达式的方法体实现,这样使代码更容易阅读 算法
myDeck.shuffle(); myDeck.sort(Comparator.comparing(Card::getRank).thenComparing( Comparator.comparing(Card::getSuit))); System.out.println("Sorted by rank, then by suit " + "with static and default methods"); System.out.println(myDeck.deckToString());
详细代码参见《默认方法的概念与代码解析》http://my.oschina.net/cloudcoder/blog/215594 express
3.默认方法:Java 8引入default method,或者叫virtual extension method,目的是为了让接口能够过后添加新方法而无需强迫全部实现该接口的类都提供新方法的实现。也就是说它的主要使用场景可能会涉及代码演进。 编程
默认方法使您可以添加新的功能到你现有库的接口中,并确保与采用老版本接口编写的代码的二进制兼容性. 数组
4.重复注解:容许在同一声明或类型(类,属性,或方法)的使用中屡次使用同一个注解@Repeatable(Authorities.class) public @interface Authority { String role(); } public @interface Authorities { Authority[] value(); } public class RepeatAnnotationUseNewVersion { @Authority(role="Admin") @Authority(role="Manager") public void doSomeThing(){ } }
5.类型注解:在java 8以前,注解只能是在声明的地方所使用,好比类,方法,属性;java 8里面,注解能够应用在任何地方。 安全
类型注解被用来支持在Java的程序中作强类型检查。配合插件式的check framework,能够在编译的时候检测出runtime error,以提升代码质量 并发
6.改善了类型推断 oracle
private List<Card> entireDeck= new ArrayList<>();
7.方法参数反射
2、针对集合(Collections)Stream API的目的是利用多核技术可将大数据经过多核并行处理,提升数据的处理效率
public static void testInt(Integer... numbers) { List<Integer> l = Arrays.asList(numbers); List<Integer> r = l.stream() .map(e -> new Integer(e)) .filter(e -> e > 2) .distinct() .collect(Collectors.toList()); System.out.println("testInt result is: " + r); }
调用:testInt(2, 3, 4, 2, 3, 5, 1);
2.针对有Key Collisions的HashMaps的性能改进
3、Compact Profiles目前提供了三种Compact Profiles,分别是compact一、compact二、compact3,他们的关系是compact1<compact2<compact3。每一个compact profiles包括低版本的profiles(compact2 is a superset of compact1 即compact2是compact1的超集,The full SE API is a superset of the compact3 profiles 而the full SE API又是compact3的超集)
在命令javac,jdeps命令中都增长了-profile参数
该特性也是为java9的模块化项目作准备。
详见:http://docs.oracle.com/javase/8/docs/technotes/guides/compactprofiles/compactprofiles.html
Full SE API | Beans | JNI | JAX-WS |
Preferences | Accessibility | IDL | |
RMI-IIOP | CORBA | Print Service | |
Sound | Swing | Java 2D | |
AWT | Drag and Drop | Input Methods | |
Image I/O | |||
compact3 | Security1 | JMX | |
XML JAXP2 | Management | Instrumentation | |
compact2 | JDBC | RMI | XML JAXP |
compact1 | Core (java.lang.*) | Security | Serialization |
Networking | Ref Objects | Regular Expressions | |
Date and Time | Input/Output | Collections | |
Logging | Concurrency | Reflection | |
JAR | ZIP | Versioning | |
Internationalization | JNDI | Override Mechanism | |
Extension Mechanism | Scripting |
使用不一样的compact profiles的编译后,占用的大体空间见下图:
4、安全性
这部分的内容较多,主要以下:主要是一些加密算法的支持,详细能够参见原文
5、JavaFX1.3D Graphics包括3D shapes, camera, lights, subscene, material, picking, and antialiasing等
2.WebView也提供了新的特性和功能改进
其余能够参见原文
六 工具(tools)8、部署
有两项,都是针对权限方面的限制
9、Date-Time Package 代码能够参考《默认方法的概念与代码解析》http://my.oschina.net/cloudcoder/blog/215594
10、Scripting
Nashorn Javascript Engine
11、java.lang and java.util Packages
5. The java.util.concurrent.locks.StampedLock class has been added to provide a capability-based lock with three modes for controlling read/write access.
十6、HotSpot
1. Hardware intrinsics were added to use Advanced Encryption Standard (AES). The UseAES and UseAESIntrinsics flags are available to enable the hardware-based AES intrinsics for Intel hardware. The hardware must be 2010 or newer Westmere hardware. For example, to enable hardware AES, use the following flags:
-XX:+UseAES -XX:+UseAESIntrinsics
To disable hardware AES use the following flags:
-XX:-UseAES -XX:-UseAESIntrinsics
支持基于硬件特性的AES,但硬件须要是2010年之后的设备或更新的Westmere硬件
2: Removal of PermGen.
移除了PermGen(内存的永久保存区域)
JDK8 HotSpot JVM 将移除永久区,使用本地内存来存储类元数据信息并称之为:元空间(Metaspace);这与Oracle JRockit 和IBM JVM’s很类似,以下图所示
默认状况下,类元数据只受可用的本地内存限制(容量取决因而32位或是64位操做系统的可用虚拟内存大小)。
新参数(MaxMetaspaceSize)用于限制本地内存分配给类元数据的大小。若是没有指定这个参数,元空间会在运行时根据须要动态调整。
3:Default Methods in the Java Programming Language are supported by the byte code instructions for method invocation.
支持java编程语言中的默认方法
详细参见原文
原文参见
http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html