java功能模块
Keeping up with the six-month cycle tradition, after the release of Java 13 on September 17, 2019, Java 14, another non-LTS version is scheduled to release on March 17, 2020.
遵循六个月的周期传统,在2019年9月17日发布Java 13 Java 14之后,计划在2020年3月17日发布另一个非LTS版本。
Java 14功能 (Java 14 Features)
Here’s the list of Java 14 features:
以下是Java 14功能的列表:
- Switch Expressions (Standard) – JEP 361 开关表达式(标准)– JEP 361
- Pattern Matching for instanceof (Preview) – JEP 305 instanceof的模式匹配(预览)– JEP 305
- Helpful NullPointerExceptions – JEP 358 有用的NullPointerExceptions – JEP 358
- Records (Preview) – JEP 359 记录(预览)– JEP 359
- Text Blocks (Second Preview) – JEP 368 文本块(第二预览)– JEP 368
- Packaging Tool (Incubator) – JEP 343 包装工具(培养箱)– JEP 343
- NUMA-Aware Memory Allocation for G1 – JEP 345 G1的NUMA感知内存分配– JEP 345
- JFR Event Streaming – JEP 349 JFR事件流– JEP 349
- Non-Volatile Mapped Byte Buffers – JEP 352 非易失性映射字节缓冲区– JEP 352
- ZGC on macOS – JEP 364 在macOS上使用ZGC – JEP 364
- ZGC on Windows – JEP 365 Windows上的ZGC – JEP 365
- Foreign-Memory Access API (Incubator) – JEP 370 外部存储器访问API(孵化器)– JEP 370
Mac OS上的Java 14安装设置 (Java 14 Installation Setup on Mac OS)
- To get started with Java 14, download the JDK from here. 要开始使用Java 14,请从此处下载JDK。
- Copy and extract the tar file in the
/Library/Java/JavaVirtualMachines
as shown below: 复制/解压缩tar文件到/Library/Java/JavaVirtualMachines
,如下所示:
$ cd /Library/Java/JavaVirtualMachines
$ sudo cp ~/Downloads/openjdk-14_osx-x64_bin.tar.gz /Library/Java/JavaVirtualMachines
$ sudo tar xzf openjdk-14_osx-x64_bin.tar.gz
$ sudo rm openjdk-14_osx-x64_bin.tar.gz
Once that’s done, open the bash_profile
using any text editor. I’m using vim ~/.bash_profile
. Set the path of Java14 to JAVA_HOME, save changes and do a source ~/.bash_profile
to reflect the changes.
完成后,使用任何文本编辑器打开bash_profile
。 我正在使用vim ~/.bash_profile
。 将Java14的路径设置为JAVA_HOME,保存更改并执行source ~/.bash_profile
以反映更改。
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-14.jdk/Contents/Home
Finally, you’re ready to compile and run programs using Java 14. We’ll be using JShell, an interactive REPL command-line tool for quickly testing the new Java 14 features.
最后,您准备使用Java 14编译和运行程序。我们将使用JShell (一种交互式REPL命令行工具),用于快速测试Java 14的新功能。
It’s important to note that many features released in Java 14 are in preview. This means that though they’re fully working right now, things may be modified in the future. Some could be made a standard or simply removed in the next release cycles. In order to test preview features, you need to explicitly set --enable-preview
when running the JShell or Java Progr