Java9 - JShell(REPL)

Java9 - JShell(REPL) 首页 / Java入门教程 / Java9 - JShell(REPL)

REPL代表"Read-Eval-Print Loop"。使用JShell,java具有REPL函数。使用REPL,无涯教程可以对基于Java的逻辑进行编码和测试,而无需使用javac进行编译,并且可以直接查看计算输出。

运行JShell

打开命令提示符,然后键入jshell。

无涯教程网

$jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro
jshell>

查看JShell命令

jshell命令开始运行后,键入/help。

链接:https://www.learnfk.comhttps://www.learnfk.com/java/java9-repl.html

来源:LearnFk无涯教程网

jshell> /help
|  Type a Java language expression, statement, or declaration.
|  Or type one of the following commands:
|  /list [<name or id>|-all|-start]
|  list the source you have typed
|  /edit <name or id>
|  edit a source entry referenced by name or id
|  /drop <name or id>
|  delete a source entry referenced by name or id
|  /save [-all|-history|-start] <file>
|  Save snippet source to a file.
|  /open <file>
|  open a file as source input
|  /vars [<name or id>|-all|-start]
|  list the declared variables and their values
|  /methods [<name or id>|-all|-start]
|  list the declared methods and their signatures
|  /types [<name or id>|-all|-start]
|  list the declared types
|  /imports 
|  list the imported items

运行JShell命令

jshell命令开始运行后,键入/imports,然后查看使用的导入。

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.*
jshell>

JShell运行计算

尝试在JShell中运行简单的计算。

jshell> 3+1
$1 ==> 4
jshell> 13%7
$2 ==> 6
jshell> $2
$2 ==> 6
jshell>

JShell创建函数

创建一个函数doubled()以获取int并返回其doubled值。

jshell> int doubled(int i){ return i*2;}
|  created method doubled(int)
jshell> doubled(6)
$3 ==> 12
jshell>

退出JShell

输入/exit。

jshell> /exit
| Goodbye

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

从0打造音视频直播系统 -〔李超〕

RPC实战与核心原理 -〔何小锋〕

人人都用得上的写作课 -〔涵柏〕

Python自动化办公实战课 -〔尹会生〕

数据分析思维课 -〔郭炜〕

网络排查案例课 -〔杨胜辉〕

反爬虫兵法演绎20讲 -〔DS Hunter〕

超级访谈:对话玉伯 -〔玉伯〕

运维监控系统实战笔记 -〔秦晓辉〕

好记忆不如烂笔头。留下您的足迹吧 :)