首頁 Java java教程 Java 9中的JShell?

Java 9中的JShell?

Sep 17, 2023 am 11:25 AM

Java 9中的JShell?

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 &#39;/help&#39; followed by the name of a
| command or a subject.
| For example &#39;/help /list&#39; or &#39;/help intro&#39;.
|
| 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中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

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

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

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

公司安全軟件導致應用無法運行?如何排查和解決? 公司安全軟件導致應用無法運行?如何排查和解決? Apr 19, 2025 pm 04:51 PM

公司安全軟件導致部分應用無法正常運行的排查與解決方法許多公司為了保障內部網絡安全,會部署安全軟件。 ...

如何使用MapStruct簡化系統對接中的字段映射問題? 如何使用MapStruct簡化系統對接中的字段映射問題? Apr 19, 2025 pm 06:21 PM

系統對接中的字段映射處理在進行系統對接時,常常會遇到一個棘手的問題:如何將A系統的接口字段有效地映�...

如何優雅地獲取實體類變量名構建數據庫查詢條件? 如何優雅地獲取實體類變量名構建數據庫查詢條件? Apr 19, 2025 pm 11:42 PM

在使用MyBatis-Plus或其他ORM框架進行數據庫操作時,經常需要根據實體類的屬性名構造查詢條件。如果每次都手動...

如何將姓名轉換為數字以實現排序並保持群組中的一致性? 如何將姓名轉換為數字以實現排序並保持群組中的一致性? Apr 19, 2025 pm 11:30 PM

將姓名轉換為數字以實現排序的解決方案在許多應用場景中,用戶可能需要在群組中進行排序,尤其是在一個用...

IntelliJ IDEA是如何在不輸出日誌的情況下識別Spring Boot項目的端口號的? IntelliJ IDEA是如何在不輸出日誌的情況下識別Spring Boot項目的端口號的? Apr 19, 2025 pm 11:45 PM

在使用IntelliJIDEAUltimate版本啟動Spring...

Java對像如何安全地轉換為數組? Java對像如何安全地轉換為數組? Apr 19, 2025 pm 11:33 PM

Java對象與數組的轉換:深入探討強制類型轉換的風險與正確方法很多Java初學者會遇到將一個對象轉換成數組的�...

電商平台SKU和SPU數據庫設計:如何兼顧用戶自定義屬性和無屬性商品? 電商平台SKU和SPU數據庫設計:如何兼顧用戶自定義屬性和無屬性商品? Apr 19, 2025 pm 11:27 PM

電商平台SKU和SPU表設計詳解本文將探討電商平台中SKU和SPU的數據庫設計問題,特別是如何處理用戶自定義銷售屬...

使用TKMyBatis進行數據庫查詢時,如何優雅地獲取實體類變量名構建查詢條件? 使用TKMyBatis進行數據庫查詢時,如何優雅地獲取實體類變量名構建查詢條件? Apr 19, 2025 pm 09:51 PM

在使用TKMyBatis進行數據庫查詢時,如何優雅地獲取實體類變量名以構建查詢條件,是一個常見的難題。本文將針...

See all articles