概述
在过去的几年中,Java通过不断的版本更新,持续引入了许多新的特性和改进,令Java语言屹立在编程语言之林。本文将介绍从Java 7到Java 22的主要新特性及改进,回顾Java语言演进的心路历程。
主要新特性及改进
Java版本 | 主要新特性及改进 |
---|---|
Java 22 | 1. Region Pinning for G1(G1垃圾收集器的区域固定) 2. Statements before super(…) (Preview)(super(…)之前的语句(预览)) 3. Foreign Function and Memory API(外部函数和内存API) 4. Unnamed Variables & Patterns(未命名变量和模式) 5. Class-File API (Preview)(类文件API(预览)) 6. String Templates (2nd Preview)(字符串模板(第二次预览)) 7. Vector API (7th Incubator)(矢量API(第七次孵化)) 8. Stream Gatherers (Preview)(流收集器(预览)) 9. Structured Concurrency (2nd Preview)(结构化并发(第二次预览)) 10. Implicitly Declared Classes and Instance Main Methods (2nd Preview)(隐式声明类和实例主方法(第二次预览)) 11. Scoped Values(作用域值) |
Java 21 (LTS) | 1. String Templates (Preview)(字符串模板(预览)) 2. Sequenced Collections(序列化集合) 3. Generational ZGC(代际ZGC) 4. Record Patterns(记录模式) 5. Pattern Matching for switch(switch的模式匹配) 6. Foreign Function & Memory API (Third Preview)(外部函数和内存API(第三次预览)) 7. Unnamed Patterns and Variables (Preview)(未命名模式和变量(预览)) 8. Virtual Threads(虚拟线程) 9. Scoped Values (Preview)(作用域值(预览)) 10. Vector API (6th Incubator)(矢量API(第六次孵化)) 11. Deprecate the Windows 32 bit x86 Port for Removal(准备移除Windows 32位x86端口) 12. Prepare to Disallow the Dynamic Loading of Agents(准备禁止动态加载代理) 13. Key Encapsulation Mechanism API(密钥封装机制API) 14. Structured Concurrency (Preview)(结构化并发(预览)) |
Java 20 | 1. Scoped Values (Incubator)(作用域值(孵化)) 2. Record Patterns (2nd Preview)(记录模式(第二次预览)) 3. Pattern Matching for switch (4th Preview)(switch的模式匹配(第四次预览)) 4. Foreign Function & Memory API (2nd Preview)(外部函数和内存API(第二次预览)) 5. Virtual Threads (2nd Preview)(虚拟线程(第二次预览)) 6. Structured Concurrency (2nd Incubator)(结构化并发(第二次孵化)) 7. Vector API (5th Incubator)(矢量API(第五次孵化)) |
Java 19 | 1. Record Patterns (Preview)(记录模式(预览)) 2. Linux/RISC-V Port(Linux/RISC-V端口) 3. Foreign Function & Memory API (Preview)(外部函数和内存API(预览)) 4. Virtual Threads (Preview)(虚拟线程(预览)) 5. Vector API (Fourth Incubator)(矢量API(第四次孵化)) 6. Pattern Matching for switch (Third Preview)(switch的模式匹配(第三次预览)) 7. Structured Concurrency (Incubator)(结构化并发(孵化)) |
Java 18 | 1. Deprecate Finalization for Removal(标记finalization为移除) 2. Internet Address Resolution SPI(互联网地址解析SPI) 3. Pattern Matching for switch (2nd Preview)(switch的模式匹配(第二次预览)) 4. Reimplementation of Core Reflection using Method Handles(使用方法句柄重新实现核心反射) 5. Small Simple Web Server(小型简单的Web服务器) 6. Foreign Memory API (2nd Incubator)(外部内存API(第二次孵化)) 7. Vector API (3rd Incubator)(矢量API(第三次孵化)) 8. UTF-8 as Standard Charset(默认字符集为UTF-8) 9. Code Snippets in JavaDoc via @snippet Tag(在JavaDoc中通过@snippet标签编写代码片段) |
Java 17 (LTS) | 1. Restore Always-Strict Floating-Point Semantics(恢复严格浮点语义) 2. Enhanced Pseudo-Random Number Generators(增强伪随机数生成器) 3. New MacOS Rendering Pipeline(新的MacOS渲染管道) 4. macOS/AArch64 Port(macOS/AArch64端口) 5. Deprecate Applet API for Removal(标记Applet API为移除) 6. Strongly Encapsulate JDK Internals(强封装JDK内部) 7. Pattern Matching for switch(switch的模式匹配) 8. Remove RMI Activation(移除RMI激活) 9. Sealed Classes(密封类) 10. Remove Experimental AOT and JIT Compiler(移除实验性的AOT和JIT编译器) 11. Deprecate SecurityManager for Removal(标记SecurityManager为移除) 12. Foreign Function and Memory API (Incubator)(外部函数和内存API(孵化)) 13. Vector API (2nd Incubator)(矢量API(第二次孵化)) 14. Context-Specific Deserialization Filters(上下文特定的反序列化过滤器) |
Java 16 | 1. Packaging Tool(打包工具) 2. Improvements to Java Stream API(Java Stream API的改进) 3. Java Records(Java记录) 4. Vector API (Incubator)(矢量API(孵化)) 5. ZGC Concurrent Thread-Stack Processing(ZGC并发线程堆栈处理) 6. Unix-Domain Socket Channels(Unix域套接字通道) 7. Foreign Linker API (Incubator)(外部链接器API(孵化)) 8. Foreign Memory Access API (3rd Incubator)(外部内存访问API(第三次孵化)) 9. Invoke Default Methods via Java Reflection Proxy(通过Java反射代理调用默认方法) 10. Pattern Matching for instanceof(instanceof的模式匹配) |
Java 15 | 1. Sealed Classes (Preview)(密封类(预览)) 2. Hidden Classes(隐藏类) 3. Edwards-Curve Digital Signature Algorithm (EdDSA)(Edwards曲线数字签名算法(EdDSA)) 4. Reimplement Legacy DatagramSocket API(重新实现旧的DatagramSocket API) 5. Pattern Matching for instanceof (2nd Preview)(instanceof的模式匹配(第二次预览)) 6. Records (2nd Preview)(记录(第二次预览)) 7. Foreign-Memory Access API (2nd Incubator)(外部内存访问API(第二次孵化)) 8. Text Blocks(文本块) 9. ZGC: Scalable Low-Latency Garbage Collector(ZGC:可扩展低延迟垃圾收集器) 10. Shenandoah: Low-Pause-Time Garbage Collector(Shenandoah:低暂停时间垃圾收集器) 11. Disable and Deprecate Biased Locking(禁用和弃用偏向锁) 12. Removed Nashorn JavaScript Engine(移除Nashorn JavaScript引擎) 13. Removed Solaris and Sparc Ports(移除Solaris和Sparc端口) 14. Deprecate RMI Activation for Removal(标记RMI激活为移除) |
Java 14 | 1. Records (Preview)(记录(预览)) 2. Text Blocks(文本块) 3. Switch Expressions(switch表达式) 4. Pattern Matching for instanceof(instanceof的模式匹配) 5. Non-Volatile Memory Mapped Byte Buffers(通过FileChannel API的非易失性内存映射字节缓冲区) 6. Foreign Memory Access API(外部内存访问API) 7. NUMA-Aware Memory Allocation for G1 GC(G1 GC的NUMA感知内存分配) 8. Java Flight Recorder: Event Streaming(Java Flight Recorder:事件流) 9. Packaging Tool(打包工具) 10. Port ZGC to MacOS and Windows(将ZGC移植到MacOS和Windows) 11. Remove Concurrent Mark and Sweep GC(移除并发标记和清除GC) 12. Remove pack200 / unpack200 Tools(移除pack200 / unpack200工具) 13. Deprecate Solaris/Sparc and Solaris/x64 Ports(标记Solaris/Sparc和Solaris/x64端口为弃用) |
Java 13 | 1. Switch Expressions(switch表达式) 2. Text Blocks(文本块) 3. Reimplementation of Legacy Socket API(重新实现旧的Socket API) 4. ZGC: Release Unused Memory Back to OS(ZGC:将未使用的内存释放回操作系统) |
Java 12 | 1. Shenandoah GC(Shenandoah GC) 2. Switch Expressions (Preview)(switch表达式(预览)) 3. JVM Constants API(JVM常量API) 4. Abortable Mixed Collections in G1(G1中的可中止混合集合) 5. Promptly Return Unused Committed Memory from G1(及时返回G1未使用的已提交内存) |
Java 11 (LTS) | 1. Removed Java EE and CORBA Modules(移除Java EE和CORBA模块) 2. HTTP Client (Standard)(标准化HTTP客户端) 3. var in Lambda Expressions(lambda表达式中的var关键字) 4. Elliptic Curve Cryptography(椭圆曲线密码协议) 5. Unicode 10(Unicode 10) 6. New Cryptographic Algorithms(新的加密算法) 7. Launch Single-File Source Code Programs(启动单文件源代码程序) 8. TLS 1.3 Support(支持TLS 1.3) 9. Deprecate Nashorn JavaScript Engine(标记Nashorn JavaScript引擎为弃用) |
Java 10 | 1. Local-Variable Type Inference(局部变量类型推断) 2. Parallel Full GC for G1(G1的并行完全垃圾收集) 3. Graal as Experimental JIT Compiler(作为实验性JIT编译器的Graal) |
Java 9 | 1. Java Modules(Java模块) 2. Java Reflection Module Class(Java反射模块类) 3. Try With Resources Enhancement(try-with-resources增强) 4. Compact Strings(紧凑字符串) 5. Java Microbenchmark Harness (JMH)(Java微基准测试工具(JMH)) |
Java 8 (LTS) | 1. Lambda Expressions(lambda表达式) 2. Streams API(Streams API) 3. JavaFX(JavaFX) 4. Nashorn JavaScript Engine(Nashorn JavaScript引擎) |
Java 7 | 1. Try with Resources(try-with-resources) 2. Catching Multiple Exceptions(捕获多个异常) 3. Fork/Join Framework(Fork/Join框架) 4. Strings in switch(switch中的字符串) 5. NIO 2.0(NIO 2.0) 6. Diamond Operator(菱形操作符) 7. Binary Literals(二进制字面量) 8. JVM Support for Dynamically-Typed Languages(JVM支持动态类型语言) |
参考资料
JDK Release Notes