」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > Java Has Arrived What&#s New ?

Java Has Arrived What&#s New ?

發佈於2024-11-08
瀏覽:248

Java Has Arrived What

Java 23 has officially been released! It’s a non-LTS (Long Term Support) release. Even though it’s a short-lived version, Java 23 comes packed with exciting improvements, bug fixes, and also removed features and options that you may need to pay attention to.

Let’s dive into what’s new and how it builds on features from previous versions like JDK 21 and JDK 22.

Scoped Values: Building on JDK 22 and JDK 21 Previews

One of the most anticipated features in JDK 23 is Scoped Values (Preview). This feature, which was also previewed in both JDK 22 and JDK 21, simplifies the way methods share immutable data across threads and child threads. In previous Java versions, handling thread-local data could be cumbersome and memory-hungry. Scoped values change that by offering a more efficient, lower-overhead alternative.

What’s different in JDK 23? The ScopedValue.callWhere() method now uses a new functional interface, which makes it easier for the compiler to infer whether a checked exception might be thrown. This also led to the removal of the ScopedValue.getWhere() method, further streamlining the API.

This is a continuation of the improvements we saw in earlier releases, and it’s exciting to see scoped values evolving toward becoming a permanent feature.

Structured Concurrency: A Third Preview

Java’s concurrency model has always been powerful but tricky to manage. Enter Structured Concurrency (Preview), which first appeared in JDK 21 and has now reached its third preview in JDK 23. The idea here is to make concurrent programming more intuitive by grouping related tasks running in different threads into a single unit of work. This simplifies error handling and improves the reliability of cancellation processes.

In JDK 23, structured concurrency remains in preview, but it continues to make concurrency code easier to reason about and less error-prone. If you’ve worked with the preview in JDK 21 or JDK 22, you’ll appreciate how this feature has matured. It’s now better equipped to deal with common concurrency issues like thread leaks, making it easier to write reliable multithreaded code.

Flexible Constructor Bodies: Evolving Since JDK 22

Another welcome addition is Flexible Constructor Bodies (Preview). First previewed in JDK 22 as “statements before super()”, this feature allows developers to write initialization code before invoking the superclass constructor. This seemingly small change can make constructor logic much clearer and prevent unnecessary object creation when validation or other setup logic fails.

In JDK 22, this feature was introduced to give developers more control over constructor logic, and the second preview in JDK 23 continues to refine that capability. By moving initialization logic ahead of the superclass invocation, developers can avoid messy auxiliary static methods and intermediate constructors that previously cluttered codebases.

Implicitly Declared Classes: Third Time’s a Charm

For those teaching Java or writing quick scripts, Implicitly Declared Classes and Instance Methods have been a game-changer since their introduction in JDK 21. This feature allows beginners to write simplified Java programs without needing to understand complex language features from the start.

In JDK 23, this feature gets some additional upgrades. Now, implicitly declared classes can automatically import three static methods for simple text I/O, and they will also import all public top-level classes and interfaces of the java.base module on demand. These enhancements help make the learning curve even smoother for newcomers.

Module Import Declarations: A New Preview

One of the fresh preview features in JDK 23 is Module Import Declarations. This feature allows you to import all packages exported by a module with a single statement, simplifying the reuse of modular libraries. It’s especially useful for beginners who no longer need to memorize where packages are located in the hierarchy, and it reduces the clutter caused by multiple type-import-on-demand declarations.

While this is a brand-new feature in JDK 23, it shows great promise in making Java’s module system more accessible, particularly for those who are new to modular programming.

Markdown Documentation Comments: A New Era for Javadoc

Let’s be honest—writing JavaDoc with HTML and the @ tags can be painful. In JDK 23, the Markdown Documentation Comments (Preview) feature allows developers to write API documentation using Markdown, making it easier to create readable, well-formatted comments.

While this is a new feature in JDK 23, it’s something that should have been added years ago. Markdown is widely used in developer communities, and bringing it to JavaDoc will make writing and maintaining documentation far easier.

Z Garbage Collector (ZGC): Generational Mode by Default

If you’ve been working with the Z Garbage Collector (ZGC) since its introduction in JDK 15, you’ll be excited to know that in JDK 23, ZGC now defaults to generational mode (JEP 474). This switch improves application performance by focusing on frequent collection of short-lived objects. While non-generational ZGC is deprecated in this release, it’s a clear sign that the generational approach is the future of garbage collection in Java.

If you’re running on JDK 22 or earlier, moving to JDK 23 should bring noticeable performance improvements without much effort on your part.

Vector API: Still Incubating, But More Powerful

The Vector API, introduced in JDK 16, allows developers to perform vector computations that compile to optimal vector instructions at runtime. The API continues to evolve, and in JDK 23, we’re seeing the Eighth Incubator. This API is still incubating, meaning it’s not yet a finalized feature, but it’s inching closer to maturity.

For performance-critical applications, particularly those dealing with large datasets, the Vector API can provide massive speedups. If you’ve worked with it in previous incubations (like JDK 22), you’ll find that it’s even more stable now, but it’s still waiting for the final pieces to fall into place (likely tied to Project Valhalla).

Stream Gatherers: Second Preview

JDK 22 introduced Stream Gatherers (Preview), a feature that adds flexibility to the Stream API by allowing custom intermediate operations. In JDK 23, it’s back for a second preview. If you love using streams to process data, you’ll appreciate this feature’s ability to transform data pipelines in ways that were previously difficult to achieve.

Stream gatherers extend the power of streams, allowing developers to handle more complex scenarios with ease, particularly when working with infinite streams or custom transformations.

Class-File API: Second Preview

If you’re building tools that manipulate Java class files, the Class-File API (Preview) in JDK 23 is for you. First introduced in JDK 22, this API provides a standard way to parse and generate class files without needing third-party libraries like ASM. The second preview in JDK 23 refines this API, making it more streamlined and easier to work with.

For tool developers, this is a big deal. No more scrambling to update libraries every time the JVM spec changes—Java now has a first-party solution.

Wrapping Up: Should You Upgrade?

Java 23 may not be an LTS release, but it’s packed with exciting features that build on what JDK 21 and JDK 22 introduced. From scoped values and structured concurrency to a better garbage collector and improvements to streams and constructors, this release pushes Java development forward.

版本聲明 本文轉載於:https://dev.to/isaactony/java-23-has-arrived-whats-new-9-minute-read-i61?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 使用 JavaScript 進行網頁抓取和代理設定的初學者指南
    使用 JavaScript 進行網頁抓取和代理設定的初學者指南
    使用JavaScript程式碼模擬使用者操作,以取得所需資訊。包括模擬使用者開啟網頁、點擊連結、輸入關鍵字等操作,並從網頁中提取所需資訊。 Javascript網頁抓取的核心原理 使用JavaScript程式碼模擬使用者操作來取得所需資訊。包括模擬使用者開啟網頁、點擊連結、輸入關鍵...
    程式設計 發佈於2024-11-09
  • 在 Android 上運行 Llama:使用 Ollama 的逐步指南
    在 Android 上運行 Llama:使用 Ollama 的逐步指南
    Llama 3.2 最近在 Meta 開發者大會上推出,展示了令人印象深刻的多模式功能以及針對使用高通和聯發科技硬體的行動裝置進行最佳化的版本。這項突破使開發人員能夠在行動裝置上運行 Llama 3.2 等強大的 AI 模型,為更高效、私密和響應迅速的 AI 應用程式鋪平道路。 Meta 發布了 ...
    程式設計 發佈於2024-11-09
  • 如何在 Python 中格式化字串以將它們對齊直列?
    如何在 Python 中格式化字串以將它們對齊直列?
    以固定寬度列印字串列印字串時,將它們對齊成直列可以增強可讀性。在 Python 中使用 format 或 f-string 提供了實現此目的的便捷方法。 使用 str.format()str.format() 提供了一個簡單的填充方法字串。其語法包括佔位符 {},後跟格式化表達式。對於左對齊,請使用...
    程式設計 發佈於2024-11-09
  • 為什麼微服務比單體架構重要
    為什麼微服務比單體架構重要
    在當今快節奏的技術環境中,企業需要可擴展且靈活的解決方案來快速適應不斷變化的需求。與傳統的整體方法相比,這就是微服務架構的亮點。 1.什麼是單體架構? 單體架構是一個單一的、統一的系統,其中所有元件都是互連和相互依賴的。這意味著對系統的任何更改或更新都需要重新建置和重新部署整個應用...
    程式設計 發佈於2024-11-09
  • 如何在 PHP 中存取物件屬性:了解語法和錯誤解決方案
    如何在 PHP 中存取物件屬性:了解語法和錯誤解決方案
    瞭解 PHP 物件屬性存取在 PHP 中,存取物件屬性對於處理複雜的資料結構至關重要。屬性保存與物件關聯的信息,使我們能夠管理和操作該數據。 存取物件屬性有兩種常用語法:1。 $property1此語法直接透過名稱存取特定屬性。它用於分配或檢索各個屬性的值。但是,這種方法要求您事先知道確切的屬性名稱...
    程式設計 發佈於2024-11-09
  • PDO如何防止SQL注入並取代轉義單引號?
    PDO如何防止SQL注入並取代轉義單引號?
    PDO防止SQL注入的方法如果你已經從mysql函式庫過渡到PDO,你可能想知道如何取代real_escape_string來轉義發往資料庫的字串中的單引號的函數。雖然向每個字串添加斜杠可能看起來很麻煩,但 PDO 提供了一種更有效的替代方案。 PDO 準備的強大功能為了防止 SQL 注入,PDO ...
    程式設計 發佈於2024-11-09
  • 透過「專案:使用互斥體同步多執行緒列印」課程釋放您的編碼潛力
    透過「專案:使用互斥體同步多執行緒列印」課程釋放您的編碼潛力
    您準備好深入多執行緒程式設計的世界並學習如何使用互斥體來同步字串的列印了嗎? LabEx 提供的項目:使用互斥體同步多執行緒列印課程就是您的最佳選擇。 在這個基於專案的綜合課程中,您將踏上了解互斥體在協調多執行緒執行方面的重要性的旅程。您將首先修改現有的「混沌打字機」程序,確保字串以正確的順序列印...
    程式設計 發佈於2024-11-09
  • 為什麼我在 MySQL 中收到「\'create_date\'時間戳欄位的預設值無效」錯誤?
    為什麼我在 MySQL 中收到「\'create_date\'時間戳欄位的預設值無效」錯誤?
    “create_date”時間戳字段的預設值無效建立帶有時間戳列的表並指定預設值“0000-”時00-00 00:00:00',可能會出現錯誤,指示「'create_date'的預設值無效」。這個錯誤是由 MySQL 的 SQL 模式 - NO_ZERO_DATE 所造成的。...
    程式設計 發佈於2024-11-09
  • 儘管出現「頁面已移動」錯誤,如何使用 cURL 檢索頁面內容?
    儘管出現「頁面已移動」錯誤,如何使用 cURL 檢索頁面內容?
    使用 cURL 檢索頁面內容在此上下文中,您試圖使用 cURL 抓取 Google 搜尋結果頁面的內容。儘管嘗試設定使用者代理程式和各種選項,但您仍無法成功檢索頁面內容。重定向或“頁面移動”錯誤繼續困擾著您。 據信此問題可能源自於查詢字串中特殊字元的編碼。為了緩解這種情況,需要更改 PHP 程式碼。...
    程式設計 發佈於2024-11-09
  • 如何使用 JPA 和 Hibernate 以 UTC 格式儲存日期/時間?
    如何使用 JPA 和 Hibernate 以 UTC 格式儲存日期/時間?
    使用JPA 和Hibernate 在UTC 時區儲存日期/時間在JPA/ 中處理日期和時間時擔心時區差異休眠應用程式?本文探討如何在 UTC (GMT) 時區有效儲存和檢索時態數據,確保跨不同時區進行一致且準確的處理。 考慮以下附註的 JPA 實體:public class Event { ...
    程式設計 發佈於2024-11-09
  • 如何使用 CSS 建立動態擴充的文字輸入欄位?
    如何使用 CSS 建立動態擴充的文字輸入欄位?
    透過 CSS 增強文字輸入回應能力製作 Web 表單時,控製文字輸入欄位的大小至關重要。 CSS 提供了一種簡單的方法來定義其初始尺寸。但是,如果您希望輸入隨著使用者鍵入而動態擴展並達到最大寬度,該怎麼辦?本文深入研究了僅 CSS 和基於 HTML 的技術來實現此行為。 CSS 和內容可編輯利用 C...
    程式設計 發佈於2024-11-09
  • 關於 Javascript Promise 的有趣事實
    關於 Javascript Promise 的有趣事實
    Promise 始終是異步的 Promise 的回呼總是在同步程式碼之後執行 const promise = Promise.resolve(); promise.then(() => console.log('async')); console.log('sync');...
    程式設計 發佈於2024-11-09
  • LightFlow:Go 的任務編排框架
    LightFlow:Go 的任務編排框架
    我發展了 LightFlow,一個任務編排框架,旨在簡化 Go 中複雜工作流程的管理。它專注於執行時序並減少對外部設定檔的需求。 主要特點: 獨立上下文:每個步驟都通過獨立上下文鏈接,僅允許訪問相關數據。 可合併流程:您可以靈活組合任務流程,以便在不同流程中重複使用。 檢查點恢...
    程式設計 發佈於2024-11-09
  • 使用 HTML、CSS 和 JavaScript 建立簡單的連結檢查器工具
    使用 HTML、CSS 和 JavaScript 建立簡單的連結檢查器工具
    使用 HTML、CSS 和 JavaScript 建立簡單的連結檢查器工具 作為...
    程式設計 發佈於2024-11-09
  • ## 為什麼 GetSystemTimeAdjustment 並不總是反映 Windows 7 上的真實時間調整?
    ## 為什麼 GetSystemTimeAdjustment 並不總是反映 Windows 7 上的真實時間調整?
    Windows 7 計時函數:了解GetSystemTimeAdjustment如您所觀察到的,在Windows 7 上使用GetSystemTimeAdjustment 函數的結果可能會令人費解。為了更好地理解,讓我們解決您的問題:問題1:假設的正確性您的假設總體上是正確的。如果系統時間定期同步,...
    程式設計 發佈於2024-11-09

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3