首页 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

1

2

3

4

5

6

7

8

<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 命令)。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

<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导入的包。

1

2

3

4

5

6

7

8

9

10

11

<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 进行算术计算

1

2

3

4

5

6

7

8

9

10

11

12

13

14

<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

1

2

<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

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

<🎜>:泡泡胶模拟器无穷大 - 如何获取和使用皇家钥匙
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系统,解释
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆树的耳语 - 如何解锁抓钩
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1666
14
CakePHP 教程
1425
52
Laravel 教程
1327
25
PHP教程
1273
29
C# 教程
1253
24
公司安全软件导致应用无法运行?如何排查和解决? 公司安全软件导致应用无法运行?如何排查和解决? Apr 19, 2025 pm 04:51 PM

公司安全软件导致部分应用无法正常运行的排查与解决方法许多公司为了保障内部网络安全,会部署安全软件。...

如何将姓名转换为数字以实现排序并保持群组中的一致性? 如何将姓名转换为数字以实现排序并保持群组中的一致性? Apr 19, 2025 pm 11:30 PM

将姓名转换为数字以实现排序的解决方案在许多应用场景中,用户可能需要在群组中进行排序,尤其是在一个用...

如何使用MapStruct简化系统对接中的字段映射问题? 如何使用MapStruct简化系统对接中的字段映射问题? Apr 19, 2025 pm 06:21 PM

系统对接中的字段映射处理在进行系统对接时,常常会遇到一个棘手的问题:如何将A系统的接口字段有效地映�...

如何优雅地获取实体类变量名构建数据库查询条件? 如何优雅地获取实体类变量名构建数据库查询条件? Apr 19, 2025 pm 11:42 PM

在使用MyBatis-Plus或其他ORM框架进行数据库操作时,经常需要根据实体类的属性名构造查询条件。如果每次都手动...

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初学者会遇到将一个对象转换成数组的�...

如何利用Redis缓存方案高效实现产品排行榜列表的需求? 如何利用Redis缓存方案高效实现产品排行榜列表的需求? Apr 19, 2025 pm 11:36 PM

Redis缓存方案如何实现产品排行榜列表的需求?在开发过程中,我们常常需要处理排行榜的需求,例如展示一个�...

电商平台SKU和SPU数据库设计:如何兼顾用户自定义属性和无属性商品? 电商平台SKU和SPU数据库设计:如何兼顾用户自定义属性和无属性商品? Apr 19, 2025 pm 11:27 PM

电商平台SKU和SPU表设计详解本文将探讨电商平台中SKU和SPU的数据库设计问题,特别是如何处理用户自定义销售属...

See all articles