JDK17新特性_jdk17免费多久-程序员宅基地

技术标签: java  面向对象编程  单元测试  

JDK17 (LTS)长期支持版本

JDK17 是继jdk11后的长期支持版本,中间 12到16都是非长期支持版本,17支持到 2029 年 9 月

由于了解到Oracle JDK17免费下载,可以免费商用,但是

1、JDK17确实可以免费商用,时间截止到2024年9月,共计3年。完整的许可协议在这里(NFTC,https://www.oracle.com/downloads/licenses/no-fee-license.html),我把权利和义务放到附录1。里面说的比较清楚,在符合美国进出口限制的情况下,开发者既可以在内部使用JDK17,也可以发布给客户使用。需要指出这个许可协议是通用的,并不针对JDK17,只有在JDK17的下载页中给出了说明(https://www.oracle.com/java/technologies/downloads/),内容如下。也就是说JDK17是Oracle Java中的一个特例,之前的版本维持原状。注意这个免费是没有订阅服务的,Oracle的订阅服务是要收费的,参见(2)。此外Oracle启动了LTS长期版本设计,目前看是3年(以后是2年),在下一个LTS版本出现后,前一个NFTC许可的LTS会至少保持1年。LTS最少8年(其中3年免费商用,5年收费商用)。在Oracle的FAQ中指出:JDK17之后的版本都遵守NFTC协议(免费),但是有时间期限,免费期之后会收费(OTN)。非NFTC协议的JDK,例如JDK18,6个月内可以免费。

简单来说,JDK17之后的版本可以免费分发和商用,但是仅有3年时间,3年后无法免费商用。看起来,这是一个套路:JDK用户持续下降,Oracle又不想放弃收费的机会。所以,这段时间内,我们可以用Oracle的jdk17,也可以继续opnejdk,不过这边还是继续openjdk吧

严格模式的浮点定义

Restore Always-Strict Floating-Point Semantics

恢复始终执行严格模式的浮点定义,修复25年前英特尔的浮点指令存在的一些问题;

在20世纪90年代末,改变平台默认浮点语义的动力来自原始Java语言和JVM语义之间的不良交互,以及流行x86体系结构的x87浮点协处理器指令集的一些不幸特性。在所有情况下(包括次正常的操作数和结果),匹配精确的浮点语义都需要大量额外的指令。在没有溢出或下溢的情况下匹配结果可以用更少的开销来实现,这大致是JavaSE1.2中引入的修订默认浮点语义所允许的。

但是,在奔腾4和从2001年开始的后续处理器中发布的SSE2(流SIMD扩展2)扩展可以以一种直接的方式支持严格的JVM浮点操作,而不会产生过多的开销。

由于Intel和AMD长期以来都支持SSE2和后来的扩展,允许自然支持严格的浮点语义,拥有一个不同于strict的默认浮点语义的技术动机不再存在。

JEP 356:增强型伪随机数发生器

Enhanced Pseudo-Random Number Generators

增加了伪随机数相关的类和接口来让开发者使用stream流进行操作,

  • RandomGenerator
  • RandomGeneratorFactory

之前的java.util.Random和java.util.concurrent.ThreadLocalRandom都是RandomGenerator接口的实现类。

RandomGenerator generator = RandomGeneratorFactory.all()
    .filter(RandomGeneratorFactory::isJumpable)
    .filter(factory -> factory.stateBits() > 128)
    .findAny()
    .map(RandomGeneratorFactory::create)
//  if you need a `JumpableGenerator`:
//  .map(JumpableGenerator.class::cast)
    .orElseThrow();

JEP 382: 新的macOS渲染管道

New macOS Rendering Pipeline

使用Apple Metal API为macOS新增了Java 2D internal rendering pipeline

macOS/AArch64端口

macOS/AArch64 Port

macOS 11.0现在支持AArch64体系结构。此JEP在JDK中实现了对macos-aarch64平台的支持。添加的功能之一是支持W^X(write xor execute)内存。它仅对macos-aarch64启用,并可以在某些时候扩展到其他平台。JDK可以在英特尔计算机上交叉编译,也可以在基于Apple M1的计算机上编译。

标记Applet API为废弃方便后续移除

Deprecate the Applet API for Removal

Deprecate, for removal, these classes and interfaces of the standard Java API:

  • java.applet.Applet
  • java.applet.AppletStub
  • java.applet.AppletContext
  • java.applet.AudioClip
  • javax.swing.JApplet
  • java.beans.AppletInitializer

Deprecate, for removal, any API elements that reference the above classes and interfaces, including methods and fields in:

  • java.beans.Beans
  • javax.swing.RepaintManager
  • javax.naming.Context

加强封装

Strongly Encapsulate JDK Internals

加强封装 JDK 的所有内部元素,但关键的内部 API(如 。不再可能通过单个命令线选项放松内部元素的强封装,就像 JDK 9 到 JDK 16 中可能的那样。sun.misc.Unsafe

对JDK内部的api进行更强的封装,是JEP 396: Strongly Encapsulate JDK Internals by Default的后续

JEP 406:switch的模式匹配(预览)

引入switch模式匹配的preview版本,instanceof的模式匹配在JDK14作为preview,在JDK15作为第二轮的preview,在JDK16转正

// Old code
if (o instanceof String) {
    
    String s = (String)o;
    ... use s ...
}

// New code
if (o instanceof String s) {
    
    ... use s ...
}

然后就有了

static String formatterPatternSwitch(Object o) {
    
    return switch (o) {
    
        case Integer i -> String.format("int %d", i);
        case Long l    -> String.format("long %d", l);
        case Double d  -> String.format("double %f", d);
        case String s  -> String.format("String %s", s);
        default        -> o.toString();
    };
}

移除Remote Method Invocation (RMI)

Remove RMI Activation

如题

JEP 409:密封类

Sealed Classes

密封类由JEP 360并在JDK 15中作为预览功能交付。它们再次被提出,并进行了改进,由JEP 397并在JDK 16中作为预览功能提供。现在,在JDK 17中,密封类正在最终确定,与JDK 16没有任何更改。

移除实验性的java版本的AOT及JIT Compiler

Remove the Experimental AOT and JIT Compiler

移除三个JDK模块:

  • jdk.aot — the tooljaotc
  • jdk.internal.vm.compiler — the Graal compiler
  • jdk.internal.vm.compiler.management — Graal’s MBean

保留这两个与gral相关的源文件,以便JVMCI模块(JEP 243)继续构建 :jdk.internal.vm.ci

  • src/jdk.internal.vm.compiler/share/classes/module-info.java
  • src/jdk.internal.vm.compiler.management/share/classes/module-info.java

移除与AOT编译相关的HotSpot代码:

  • src/hotspot/share/aot — dumps and loads AOT code

  • Additional code guarded by #if INCLUDE_AOT

最后,删除与Graal和AOT编译相关的makefile中的测试和代码。

后续要使用可以使用GraalVM

废弃Security Manager方便后续移除

Deprecate the Security Manager for Removal

如题

外部函数和内存API(孵化)

Foreign Function & Memory API (Incubator)

JDK14的JEP 370: Foreign-Memory Access API (Incubator)引入了Foreign-Memory Access API作为incubator,JDK15的JEP 383: Foreign-Memory Access API (Second Incubator)Foreign-Memory Access API作为第二轮incubator,JDK16的JEP 393: Foreign-Memory Access API (Third Incubator)作为第三轮,它引入了Foreign Linker API,JDK17引入Foreign Function & Memory API

引入一个API,Java程序可以通过该API与Java运行时之外的代码和数据互操作。通过有效地调用外部函数(即JVM外部的代码),并通过安全地访问外部内存(即不由JVM管理的内存),该API使Java程序能够调用本机库并处理本机数据,而不会有JNI的脆弱性和危险。

JEP 414:矢量API(二次孵化)

Vector API (Second Incubator)

JDK16引入了JEP 338: Vector API (Incubator)提供了jdk.incubator.vector来用于矢量计算,JDK17进行改进并作为第二轮的incubator

JEP 415:实现特定于上下文的反序列化过滤器

Context-Specific Deserialization Filters

对不受信任的数据进行反序列化是一种固有的危险活动,因为传入数据流的内容决定了创建的对象、其字段的值以及它们之间的引用。 在许多典型的使用中,流中的字节是从未知、不可信或未经身份验证的客户端接收的。 通过小心地构造流,对手可能会导致恶意执行任意类中的代码。 如果对象构造有改变状态或调用其他操作的副作用,这些操作可能会危及应用程序对象、库对象甚至Java运行时的完整性。 禁用反序列化攻击的关键是防止任意类的实例被反序列化,从而防止直接或间接地执行它们的方法。

API

/**
 * Return the JVM-wide deserialization filter factory.
 *
 * @return the JVM-wide serialization filter factory; non-null
 */
public static BinaryOperator<ObjectInputFilter> getSerialFilterFactory();

/**
 * Set the JVM-wide deserialization filter factory.
 *
 * The filter factory is a function of two parameters, the current filter
 * and the next filter, that returns the filter to be used for the stream.
 *
 * @param filterFactory the serialization filter factory to set as the
 * JVM-wide filter factory; not null
 */
public static void setSerialFilterFactory(BinaryOperator<ObjectInputFilter> filterFactory);

允许应用去配置指定上下文及动态选择的deserialization filters

public class FilterInThread implements BinaryOperator<ObjectInputFilter> {
    

    // ThreadLocal to hold the serial filter to be applied
    private final ThreadLocal<ObjectInputFilter> filterThreadLocal = new ThreadLocal<>();

    // Construct a FilterInThread deserialization filter factory.
    public FilterInThread() {
    }

    /**
     * The filter factory, which is invoked every time a new ObjectInputStream
     * is created.  If a per-stream filter is already set then it returns a
     * filter that combines the results of invoking each filter.
     *
     * @param curr the current filter on the stream
     * @param next a per stream filter
     * @return the selected filter
     */
    public ObjectInputFilter apply(ObjectInputFilter curr, ObjectInputFilter next) {
    
        if (curr == null) {
    
            // Called from the OIS constructor or perhaps OIS.setObjectInputFilter with no current filter
            var filter = filterThreadLocal.get();
            if (filter != null) {
    
                // Prepend a filter to assert that all classes have been Allowed or Rejected
                filter = ObjectInputFilter.Config.rejectUndecidedClass(filter);
            }
            if (next != null) {
    
                // Prepend the next filter to the thread filter, if any
                // Initially this is the static JVM-wide filter passed from the OIS constructor
                // Append the filter to reject all UNDECIDED results
                filter = ObjectInputFilter.Config.merge(next, filter);
                filter = ObjectInputFilter.Config.rejectUndecidedClass(filter);
            }
            return filter;
        } else {
    
            // Called from OIS.setObjectInputFilter with a current filter and a stream-specific filter.
            // The curr filter already incorporates the thread filter and static JVM-wide filter
            // and rejection of undecided classes
            // If there is a stream-specific filter prepend it and a filter to recheck for undecided
            if (next != null) {
    
                next = ObjectInputFilter.Config.merge(next, curr);
                next = ObjectInputFilter.Config.rejectUndecidedClass(next);
                return next;
            }
            return curr;
        }
    }

    /**
     * Apply the filter and invoke the runnable.
     *
     * @param filter the serial filter to apply to every deserialization in the thread
     * @param runnable a Runnable to invoke
     */
    public void doWithSerialFilter(ObjectInputFilter filter, Runnable runnable) {
    
        var prevFilter = filterThreadLocal.get();
        try {
    
            filterThreadLocal.set(filter);
            runnable.run();
        } finally {
    
            filterThreadLocal.set(prevFilter);
        }
    }
}

// Create a FilterInThread filter factory and set
    var filterInThread = new FilterInThread();
    ObjectInputFilter.Config.setSerialFilterFactory(filterInThread);

    // Create a filter to allow example.* classes and reject all others
    var filter = ObjectInputFilter.Config.createFilter("example.*;java.base/*;!*");
    filterInThread.doWithSerialFilter(filter, () -> {
    
          byte[] bytes = ...;
          var o = deserializeObject(bytes);
    });

其他参考

JDK 17 (java.net)

Java SE Development Kit 17, 17.0.1 Release Notes (oracle.com)

Java Downloads | Oracle

Java 17 and IntelliJ IDEA | The IntelliJ IDEA Blog (jetbrains.com)

Deprecated List (Java SE 17)

博客

Java17的新特性 - SegmentFault 思否

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/y965588107/article/details/121516332

智能推荐

c# 调用c++ lib静态库_c#调用lib-程序员宅基地

文章浏览阅读2w次,点赞7次,收藏51次。四个步骤1.创建C++ Win32项目动态库dll 2.在Win32项目动态库中添加 外部依赖项 lib头文件和lib库3.导出C接口4.c#调用c++动态库开始你的表演...①创建一个空白的解决方案,在解决方案中添加 Visual C++ , Win32 项目空白解决方案的创建:添加Visual C++ , Win32 项目这......_c#调用lib

deepin/ubuntu安装苹方字体-程序员宅基地

文章浏览阅读4.6k次。苹方字体是苹果系统上的黑体,挺好看的。注重颜值的网站都会使用,例如知乎:font-family: -apple-system, BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, Source Han Sans SC, Noto Sans CJK SC, W..._ubuntu pingfang

html表单常见操作汇总_html表单的处理程序有那些-程序员宅基地

文章浏览阅读159次。表单表单概述表单标签表单域按钮控件demo表单标签表单标签基本语法结构<form action="处理数据程序的url地址“ method=”get|post“ name="表单名称”></form><!--action,当提交表单时,向何处发送表单中的数据,地址可以是相对地址也可以是绝对地址--><!--method将表单中的数据传送给服务器处理,get方式直接显示在url地址中,数据可以被缓存,且长度有限制;而post方式数据隐藏传输,_html表单的处理程序有那些

PHP设置谷歌验证器(Google Authenticator)实现操作二步验证_php otp 验证器-程序员宅基地

文章浏览阅读1.2k次。使用说明:开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码。实现Google Authenticator功能需要服务器端和客户端的支持。服务器端负责密钥的生成、验证一次性密码是否正确。客户端记录密钥后生成一次性密码。下载谷歌验证类库文件放到项目合适位置(我这边放在项目Vender下面)https://github.com/PHPGangsta/GoogleAuthenticatorPHP代码示例://引入谷_php otp 验证器

【Python】matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距-程序员宅基地

文章浏览阅读4.3k次,点赞5次,收藏11次。matplotlib.plot画图横坐标混乱及间隔处理_matplotlib更改横轴间距

docker — 容器存储_docker 保存容器-程序员宅基地

文章浏览阅读2.2k次。①Storage driver 处理各镜像层及容器层的处理细节,实现了多层数据的堆叠,为用户 提供了多层数据合并后的统一视图②所有 Storage driver 都使用可堆叠图像层和写时复制(CoW)策略③docker info 命令可查看当系统上的 storage driver主要用于测试目的,不建议用于生成环境。_docker 保存容器

随便推点

网络拓扑结构_网络拓扑csdn-程序员宅基地

文章浏览阅读834次,点赞27次,收藏13次。网络拓扑结构是指计算机网络中各组件(如计算机、服务器、打印机、路由器、交换机等设备)及其连接线路在物理布局或逻辑构型上的排列形式。这种布局不仅描述了设备间的实际物理连接方式,也决定了数据在网络中流动的路径和方式。不同的网络拓扑结构影响着网络的性能、可靠性、可扩展性及管理维护的难易程度。_网络拓扑csdn

JS重写Date函数,兼容IOS系统_date.prototype 将所有 ios-程序员宅基地

文章浏览阅读1.8k次,点赞5次,收藏8次。IOS系统Date的坑要创建一个指定时间的new Date对象时,通常的做法是:new Date("2020-09-21 11:11:00")这行代码在 PC 端和安卓端都是正常的,而在 iOS 端则会提示 Invalid Date 无效日期。在IOS年月日中间的横岗许换成斜杠,也就是new Date("2020/09/21 11:11:00")通常为了兼容IOS的这个坑,需要做一些额外的特殊处理,笔者在开发的时候经常会忘了兼容IOS系统。所以就想试着重写Date函数,一劳永逸,避免每次ne_date.prototype 将所有 ios

如何将EXCEL表导入plsql数据库中-程序员宅基地

文章浏览阅读5.3k次。方法一:用PLSQL Developer工具。 1 在PLSQL Developer的sql window里输入select * from test for update; 2 按F8执行 3 打开锁, 再按一下加号. 鼠标点到第一列的列头,使全列成选中状态,然后粘贴,最后commit提交即可。(前提..._excel导入pl/sql

Git常用命令速查手册-程序员宅基地

文章浏览阅读83次。Git常用命令速查手册1、初始化仓库git init2、将文件添加到仓库git add 文件名 # 将工作区的某个文件添加到暂存区 git add -u # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,不处理untracked的文件git add -A # 添加所有被tracked文件中被修改或删除的文件信息到暂存区,包括untracked的文件...

分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120-程序员宅基地

文章浏览阅读202次。分享119个ASP.NET源码总有一个是你想要的_千博二手车源码v2023 build 1120

【C++缺省函数】 空类默认产生的6个类成员函数_空类默认产生哪些类成员函数-程序员宅基地

文章浏览阅读1.8k次。版权声明:转载请注明出处 http://blog.csdn.net/irean_lau。目录(?)[+]1、缺省构造函数。2、缺省拷贝构造函数。3、 缺省析构函数。4、缺省赋值运算符。5、缺省取址运算符。6、 缺省取址运算符 const。[cpp] view plain copy_空类默认产生哪些类成员函数

推荐文章

热门文章

相关标签