编程技术是改变世界的力量。
本站
当前位置:网站首页 > 后端语言 > 正文

Java17的新特性 java17下载32位

gowuye 2024-04-03 16:13 10 浏览 0 评论

Java语言特性系列

Java5的新特性 Java6的新特性 Java7的新特性 Java8的新特性 Java9的新特性 Java10的新特性 Java11的新特性 Java12的新特性 Java13的新特性 Java14的新特性 Java15的新特性 Java16的新特性 Java17的新特性 Java18的新特性

本文主要讲述一下Java17的新特性

版本号

java -version
openjdk version "17" 2021-09-14
OpenJDK Runtime Environment (build 17+35-2724)
OpenJDK 64-Bit Server VM (build 17+35-2724, mixed mode, sharing)

从version信息可以看出是build 17+35

特性列表

JEP 306: Restore Always-Strict Floating-Point Semantics

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

JEP 356: Enhanced Pseudo-Random Number Generators

引入RandomGenerator及RandomGeneratorFactory提供更好的随机数生成

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: New macOS Rendering Pipeline

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

JEP 391: macOS/AArch64 Port

迁移JDK到macOS/AArch64

JEP 398: Deprecate the Applet API for Removal

标记Applet API为废弃方便后续移除,具体如下

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

JEP 403: Strongly Encapsulate JDK Internals

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

JEP 406: Pattern Matching for switch (Preview)

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

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();
    };
}

JEP 407: Remove RMI Activation

移除Remote Method Invocation (RMI),它在JDK15的JEP 385被废弃

JEP 409: Sealed Classes

Sealed Classes在JDK15作为preview引入,在JDK16作为第二轮preview,在JDK17转正

package com.example.geometry;

public abstract sealed class Shape
    permits Circle, Rectangle, Square, WeirdShape { ... }

public final class Circle extends Shape { ... }

public sealed class Rectangle extends Shape 
    permits TransparentRectangle, FilledRectangle { ... }
public final class TransparentRectangle extends Rectangle { ... }
public final class FilledRectangle extends Rectangle { ... }

public final class Square extends Shape { ... }

public non-sealed class WeirdShape extends Shape { ... }

JEP 410: Remove the Experimental AOT and JIT Compiler

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

jdk.aot — the jaotc tool
jdk.internal.vm.compiler — the Graal compiler
jdk.internal.vm.compiler.management — Graal's MBean

后续要使用可以使用GraalVM

JEP 411: Deprecate the Security Manager for Removal

废弃java1.0引入的Security Manager方便后续移除

JEP 412: 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

JEP 414: Vector API (Second Incubator)

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

JEP 415: Context-Specific Deserialization Filters

允许应用去配置指定上下文及动态选择的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);
    });

细项解读

上面列出的是大方面的特性,除此之外还有一些api的更新及废弃,主要见JDK 17 Release Notes,这里举几个例子。

添加项

  • DatagramSocket Can Be Used Directly to Join Multicast Groups (JDK-8237352)

更新了java.net.DatagramSocket用于支持joining multicast groups

  • Console Charset API (JDK-8264208)

java.io.Console新增了方法用于返回console的charset

  • JDK Flight Recorder Event for Deserialization (JDK-8261160)

JDK Flight Recorder新增了jfr.Deserialization实现

  • Unified Logging Supports Asynchronous Log Flushing (JDK-8229517)

引入了-Xlog:async参数用于异步日志,以及-XX:AsyncLogBufferSize=<bytes>用于控制buffer的大小

移除项

  • Removal of sun.misc.Unsafe::defineAnonymousClass (JDK-8243287)

移除sun.misc.Unsafe::defineAnonymousClass方法

废弃项

  • Deprecate 3DES and RC4 in Kerberos (JDK-8139348)

废弃了Kerberos的des3-hmac-sha1及rc4-hmac这两个encryption types

  • Deprecate the Socket Implementation Factory Mechanism (JDK-8235139)

废弃了如下几个工厂

static void ServerSocket.setSocketFactory(SocketImplFactory fac)
static void Socket.setSocketImplFactory?(SocketImplFactory fac)
static void DatagramSocket.setDatagramSocketImplFactory?(DatagramSocketImplFactory fac)

已知问题

  • TreeMap.computeIfAbsent Mishandles Existing Entries Whose Values Are null (JDK-8259622)

TreeMap.computeIfAbsent方法针对null的处理与规范有偏差

  • Segmentation Fault Error on 9th and 10th Generation Intel? Core? Processors (JDK-8263710)

当运行在9th and 10th Generation Intel? Core? Processors时会有Segmentation Fault Error

其他事项

  • Updated List of Capabilities Provided by JDK RPMs (JDK-8263575)

xml-commons-api, jaxp_parser_impl, 以及java-fonts已经从OracleJDK/OracleJRE RPMs移除

  • New Implementation of java.nio.channels.Selector on Microsoft Windows (JDK-8266369)

对windows的java.nio.channels.Selector API采用了更具可扩展的方式实现,原来的实现没有被移除,可以使用-Djava.nio.channels.spi.SelectorProvider=sun.nio.ch.WindowsSelectorProvider来继续使用

  • Parallel GC Enables Adaptive Parallel Reference Processing by Default (JDK-8204686)

针对Parallel GC默认开启了-XX:ParallelRefProcEnabled

  • URLClassLoader No Longer Throws Undocumented IllegalArgumentException From getResources and findResources (JDK-8262277)

URLClassLoader的getResources、findResources不再抛出文档未定义的IllegalArgumentException

小结

Java17主要有如下几个特性

  • JEP 306: Restore Always-Strict Floating-Point Semantics
  • JEP 356: Enhanced Pseudo-Random Number Generators
  • JEP 382: New macOS Rendering Pipeline
  • JEP 391: macOS/AArch64 Port
  • JEP 398: Deprecate the Applet API for Removal
  • JEP 403: Strongly Encapsulate JDK Internals
  • JEP 406: Pattern Matching for switch (Preview)
  • JEP 407: Remove RMI Activation
  • JEP 409: Sealed Classes
  • JEP 410: Remove the Experimental AOT and JIT Compiler
  • JEP 411: Deprecate the Security Manager for Removal
  • JEP 412: Foreign Function & Memory API (Incubator)
  • JEP 414: Vector API (Second Incubator)
  • JEP 415: Context-Specific Deserialization Filters

doc

  • JDK 17 Features
  • JDK 17 Release Notes
  • JDK 17 Release Notes
  • Java SE deprecated-list
  • The arrival of Java 17!
  • Java 17 and IntelliJ IDEA
  • Better Random Number Generation in Java 17

相关推荐

嵌入式C语言中常量的应用实例(嵌入式c语言中常量的应用实例是什么)

常量,我们都知道,就是数值保持不变的量。在C语言中,常量一旦初始化了,它的值将在整个程序运行周期内,不允许发生任何变化。常量与变量是相对的,我们实际项目中经常会用到它。定义常量的两种方式C语言中主要有...

C语言编程基础知识汇总学习,适合初学者!更新常量知识

(二)整型常量整型常量有3种形式:十进制整型常量、八进制整型常量和十六进制整型常量。(注意:c语言中没有直接表示二进制的整型常量,在c语言源程序中不会出现二进制。)书写方式如下:十进制整型常量:123...

【C语言】第二章第六节:字符串常量

第二章第六节:字符串常量。下表C语言中的常用转义字符。·字符形式功能:ASCIl码(十进制形式)。→\t水平制表(横向跳格:跳到下一个tab位置)。→\b退格8。→\r回车(不换行,光标移到本行行首)...

「GCTT 出品」Go 系列教程——5. 常量

这是我们Golang系列教程的第五篇。定义在Go语言中,术语”常量”用于表示固定的值。比如5、-89、IloveGo、67.89等等。看看下面的代码:varaint=50v...

每日C语言-常量指针、指针常量、指向常量的指针常量

一、常量指针1)什么是常量指针?通过该指针不可以修改其所指向存储单元中的值指针本身即地址可以被修改2)定义:类型说明符const*指针变量;类型说明符表示指针所指向存储单元中的值得数据类型指针...

C语言-符号常量、常变量、变量之我见

更新内容:新增音频。音频和文章一起更配oHello,大家好,又和大家见面了~~相信很多朋友们听了C语言的“符号常量”、“常变量”、“变量”后还是对这三者一脸懵逼吧。不管老师怎么歇斯底里地讲解,同学们迷...

零基础带你学习C语言:四:探索常量与变量

前言常量与变量学习;一:分析:short、float、long类型#include<stdio.h>intmain(){shortage=18;floatweight=12...

C语言中是如何定义常量的?那定义字符串呢?

常量有整型常量、浮点型常量、字符型常量及字符串常量。‘常量定义是指定义符号常量,用一个标识符来代表一个常量,通过宏定义预处理指令来实现。常量的定义:#definecount60这就定义了一个常量...

C语言符号常量的优点,会是那几点?

符号常量是一个常量,是不变量,所以,在编译的时候,就把符号常量出现的地方,替换为符号常量对应的常量。符号常量一般用户定义一个全局使用的数据,而且要改变该数据的时候,只需要改变符号常量的值,代码中引用符...

嵌入式开发- C语言数据类型-常量(c语言嵌入式是干嘛的)

基本数据类型的常量-掌握**整型常量:**常量是指在程序运行期间其数值不发生变化的数据。整型常量通常简称为整数整数可以是十进制数、八进制数、十六进制数八进制06334十六进制0xd1...

c语言解剖课:只读变量、常量、字面量傻傻分不清?

写在前面本篇主题的缘起,是因为一个计算机专业的大学生在和我讨论c语言问题时,说const常量如何如何,我说变量被const修饰了,还是变量,不是“常量”。他给了我一个截图:他说大模型都是这样回答的,变...

C/C++编程笔记:C数组、字符串常量和指针!三分钟弄懂它

想弄懂C语言中数组和指针的关系吗?这篇文章就占据你三分钟时间,看完你肯定会有收获!数组数组声明为数据类型名称[constant-size],并将一个数据类型的一个或多个实例分组到一个可寻址的位...

C语言入门到精通【第008讲】——C语言常量

C语言常量常量是固定值,在程序执行期间不会改变。这些固定的值,又叫做字面量。常量可以是任何的基本数据类型,比如整数常量、浮点常量、字符常量,或字符串字面值,也有枚举常量。常量就像是常规的变量,只不过常...

这是C语言无法修改得东西,C语言基础教程之常量解析

常量是指程序在执行期间不会改变的固定值。这些固定值也称为文字。常量可以是任何基本数据类型,如整数常量,浮点常量,字符常量或字符串文字,还有枚举常量。常量被视为常规变量,除了它们的值在定义后无法修改。整...

C语言中的单精度、双精度、常量等都有什么意思?

刚接触C语言时,对于常量,变量,浮点,单精度,双精度等问题的理解,大都很模糊不清,其实在程序运行过程中,其值不能改变的量称为常量。如12、0、-3为整型常量,4.6、-1.23为实型常量,'a'、'...

取消回复欢迎 发表评论: