JShell是 Java 9 版本中引入的新概念。它为 Java 提供了REPL(Read-Eval-Print-Loop)能力。通过使用 JShell,我们可以测试基于 Java 的逻辑和表达式,而无需编译它。 REPL 充当即时反馈循环,对特定语言的生产力有很大影响。
第 1 步:打开命令提示符并输入 JShell。
<strong>Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved. C:\Users\User>JShell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell></strong>
第 2 步:JShell 命令窗口开始运行后,键入 /help(以查看 JShell 命令)。
<strong>jshell> /help | Type a Java language expression, statement, or declaration. | Or type one of the following commands: | /list [|-all|-start] | list the source you have typed | /edit | edit a source entry referenced by name or id | /drop | delete a source entry referenced by name or id | /save [-all|-history|-start] | Save snippet source to a file. | /open | open a file as source input | /vars [|-all|-start] | list the declared variables and their values | /methods [|-all|-start] | list the declared methods and their signatures | /types [|-all|-start] | list the declared types | /imports | list the imported items | /exit | exit jshell | /env [-class-path ] [-module-path ] [-add-modules < | view or change the evaluation context | /reset [-class-path ] [-module-path ] [-add-modules | reset jshell | /reload [-restore] [-quiet] [-class-path ] [-module-path | reset and replay relevant history -- current or previous ( | /history | history of what you have typed | /help [|] | get information about jshell | /set editor|start|feedback|mode|prompt|truncation|format ... | set jshell configuration information | /? [|] | get information about jshell | /! | re-run last snippet | / | re-run snippet by id | /- | re-run n-th previous snippet | | For more information type '/help' followed by the name of a | command or a subject. | For example '/help /list' or '/help intro'. | | Subjects: | | intro | an introduction to the jshell tool | shortcuts | a description of keystrokes for snippet and command comple | information access, and automatic code generation | context | the evaluation context options for /env /reload and /reset</strong>
第三步:在JShell命令窗口中输入 /imports,获取JShell导入的包。
<strong>jshell> /imports | import java.io.* | import java.math.* | import java.net.* | import java.nio.file.* | import java.util.* | import java.util.concurrent.* | import java.util.function.* | import java.util.prefs.* | import java.util.regex.* | import java.util.stream.*</strong>
第 4 步:在 JShell 中执行计算(尝试使用 JShell 进行算术计算)
<strong>jshell> 3+5 $1 ==> 8 jshell> 8-4 $2 ==> 4 jshell> 2*6 $3 ==> 12 jshell> 9%3 $4 ==> 0 jshell> 8/2 $5 ==> 4</strong>
第 5 步:要退出 JShell,请输入 /exit。
<strong>jshell> /exit | Goodbye</strong>
以上是Java 9中的JShell?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

新興技術對Java的平台獨立性既有威脅也有增強。 1)雲計算和容器化技術如Docker增強了Java的平台獨立性,但需要優化以適應不同雲環境。 2)WebAssembly通過GraalVM編譯Java代碼,擴展了其平台獨立性,但需與其他語言競爭性能。

不同JVM實現都能提供平台獨立性,但表現略有不同。 1.OracleHotSpot和OpenJDKJVM在平台獨立性上表現相似,但OpenJDK可能需額外配置。 2.IBMJ9JVM在特定操作系統上表現優化。 3.GraalVM支持多語言,需額外配置。 4.AzulZingJVM需特定平台調整。

平台獨立性通過在多種操作系統上運行同一套代碼,降低開發成本和縮短開發時間。具體表現為:1.減少開發時間,只需維護一套代碼;2.降低維護成本,統一測試流程;3.快速迭代和團隊協作,簡化部署過程。

Java'splatformindependencefacilitatescodereusebyallowingbytecodetorunonanyplatformwithaJVM.1)Developerscanwritecodeonceforconsistentbehavioracrossplatforms.2)Maintenanceisreducedascodedoesn'tneedrewriting.3)Librariesandframeworkscanbesharedacrossproj

要解決Java應用程序中的平台特定問題,可以採取以下步驟:1.使用Java的System類查看系統屬性以了解運行環境。 2.利用File類或java.nio.file包處理文件路徑。 3.根據操作系統條件加載本地庫。 4.使用VisualVM或JProfiler優化跨平台性能。 5.通過Docker容器化確保測試環境與生產環境一致。 6.利用GitHubActions在多個平台上進行自動化測試。這些方法有助於有效地解決Java應用程序中的平台特定問題。

類加載器通過統一的類文件格式、動態加載、雙親委派模型和平台無關的字節碼,確保Java程序在不同平台上的一致性和兼容性,實現平台獨立性。

Java編譯器生成的代碼是平台無關的,但最終執行的代碼是平台特定的。 1.Java源代碼編譯成平台無關的字節碼。 2.JVM將字節碼轉換為特定平台的機器碼,確保跨平台運行但性能可能不同。

多線程在現代編程中重要,因為它能提高程序的響應性和資源利用率,並處理複雜的並發任務。 JVM通過線程映射、調度機制和同步鎖機制,在不同操作系統上確保多線程的一致性和高效性。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。