Java REPL & JShell

Java 11

JShell

Java Shell

https://www.infoq.com/articles/jshell-java-repl/

The Java Shell or JShell is an official Read-Evaluate-Print-Loop, or REPL as it's commonly called, introduced with Java 9.

It provides an interactive shell for quickly prototyping, debugging, and learning Java and Java APIs, all without the need for a public static void main or the need to compile your code before executing it.

And as an added plus, using JShell just got a whole lot less verbose (and more practical) with the advent of the var keyword in Java 10!

Last login: Sat Aug  1 12:20:36 on ttys006
➜ ~ jshell
| Welcome to JShell -- Version 11.0.2
| For an introduction type: /help intro 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
| /drop <name or id>
| delete a source entry
| /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 type declarations
| /imports
| list the imported items
| /exit [<integer-expression-snippet>]
| exit the jshell tool
| /env [-class-path <path>] [-module-path <path>] [-add-modules <modules>] ...
| view or change the evaluation context
| /reset [-class-path <path>] [-module-path <path>] [-add-modules <modules>]...
| reset the jshell tool
| /reload [-restore] [-quiet] [-class-path <path>] [-module-path <path>]...
| reset and replay relevant history -- current or previous (-restore)
| /history [-all]
| history of what you have typed
| /help [<command>|<subject>]
| get information about using the jshell tool
| /set editor|start|feedback|mode|prompt|truncation|format ...
| set configuration information
| /? [<command>|<subject>]
| get information about using the jshell tool
| /!
| rerun last snippet -- see /help rerun
| /<id>
| rerun snippets by ID or ID range -- see /help rerun
| /-<n>
| rerun n-th previous snippet -- see /help rerun
|
| 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
| id
| a description of snippet IDs and how use them
| shortcuts
| a description of keystrokes for snippet and command completion,
| information access, and automatic code generation
| context
| a description of the evaluation context options for /env /reload and /reset
| rerun
| a description of ways to re-evaluate previously entered snippets jshell> /exit
| Goodbye

online REPL

OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)

https://java-repl.xgqfrms.repl.run

https://repl.it/@xgqfrms/java-repl#HelloWorld.java

 javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . HelloWorld.java Main.java

 java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main

Hello world!

demos

️ 创建文件 HelloWorld.java 的文件名必须要与类名保持一致

// HelloWorld.java

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}

注:String args[] 与 String[] args 都可以执行,但推荐使用 String[] args,这样可以避免歧义和误读。

$ javac --version
# javac 11.0.2 $ javac HelloWorld.java
$ java HelloWorld
# Hello World

refs

https://www.runoob.com/java/java-tutorial.html



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


Java REPL & JShell的更多相关文章

  1. Java中jshell脚本

    1.当所编写的代码量少时,倘若要按照步骤会显得繁琐,可直接用JDk当中的jshell,进入cmd,输入jshell,即进入jshell脚本交互模式.省去繁琐的定义类,main方法,可直接输出Syste ...

  2. Java 11 正式发布,这 8 个逆天新特性教你写出更牛逼的代码

    美国时间 09 月 25 日,Oralce 正式发布了 Java 11,这是据 Java 8 以后支持的首个长期版本. 为什么说是长期版本,看下面的官方发布的支持路线图表. 可以看出 Java 8 扩 ...

  3. Java 11 这 8 个逆天新特性教你写出更牛逼的代码!

    美国时间2018年 09 月 25 日,Oralce 正式发布了 Java 11,这是据 Java 8 以后支持的首个长期版本. 为什么说是长期版本,看下面的官方发布的支持路线图表. 可以看出 Jav ...

  4. Java9新特性

    转载:http://blog.csdn.net/qq_32524177/article/details/77014757 写在前面的话:Java9来了,搜索了很多关于Java9的新特性,但文献不多,特 ...

  5. Java9最受期待的5大新特性

    虽然Java9要等到明年才正式发布,但是现在网上已经有了各种各样的有关Java9新特性的文章了,今天小编也将为大家分享除了通常猜测之外的一些很值得期待的5个新特性. 1.Java + REPL = j ...

  6. 5分钟学会Java9-Java11的七大新特性

    现在Java有多元化的发展趋势,既有JS又有C++还有C#的影子,不学习那是不行滴. 来来来,花5分钟看看Java9-Java11的七大新特性,还有代码样例. Java11 发布了,然而很多公司还在用 ...

  7. Java基础教程——Jshell

    Jshell 从java9开始,java提供Jshell工具,可以输入代码片段并马上看到运行结果. 对于简单的Java语句测试,不需要新建文件,编译,运行了 Microsoft Windows [版本 ...

  8. Java 9 揭秘(11. Java Shell)

    Tips 做一个终身学习的人. 在本章节中,主要介绍以下内容: 什么是Java shell JShell工具和JShell API是什么 如何配置JShell工具 如何使用JShell工具对Java代 ...

  9. Java 9 中的 9 个新特性你知道吗

    摘要: Java 8 发布三年多之后,即将快到2017年7月下一个版本发布的日期了. 你可能已经听说过 Java 9 的模块系统,但是这个新版本还有许多其它的更新. 这里有九个令人兴奋的新功能将与 J ...

随机推荐

  1. (转载)微软数据挖掘算法:Microsoft顺序分析和聚类分析算法(8)

    前言 本篇文章继续我们的微软挖掘系列算法总结,前几篇文章已经将相关的主要算法做了详细的介绍,我为了展示方便,特地的整理了一个目录提纲篇:大数据时代:深入浅出微软数据挖掘算法总结连载,有兴趣的童鞋可以点 ...

  2. FlightGear 从输出所省略的额外重寻址溢出

    2020-12-27 在龙芯Fedora28上编译 FlightGear 2019.1.1 时遇到 从输出所省略的额外重寻址溢出 错误,错误信息如下: [ 98%] Linking CXX execu ...

  3. jackson学习之五:JsonInclude注解

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  4. (十二)整合 Shiro 框架,实现用户权限管理

    整合 Shiro 框架,实现用户权限管理 1.Shiro简介 1.1 基础概念 1.2 核心角色 1.3 核心理念 2.SpringBoot整合Shiro 2.1 核心依赖 2.2 Shiro核心配置 ...

  5. Mycat 配置文件解析

    Mycat 配置文件解析 一.server.xml 二.schema.xml 2.1 schema.xml文件中配置的参数解释 2.1.1 DataHost 2.1.2 DataNode 2.1.3 ...

  6. 浅聊TCP的三次握手和四次挥手

    三次握手: 首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资源.Client端接收到ACK报文后也向Server段发生ACK报文,并分配资源,这样TCP连 ...

  7. MacOS Big Sur开HiDPI

    我自己的环境: 开启hidpi的目的是为了让显示更加细腻,代价是缩小了显示范围. 自己在网上看了很多帖子,也尝试了几种,有些方法已经不再适合Big Sur系统了,所以本文提供一种可用的,在Big Su ...

  8. OpenCV4.4.0 安装测试 Installation & Examination (Ubuntu18.04, Ubuntu 20.04)

    OpenCV4.4.0 安装测试 Installation & Examination (Ubuntu18.04, Ubuntu 20.04) 单纯简单的 OpenCV 安装配置方法,在这个地 ...

  9. 从问题入手,深入了解JavaScript中原型与原型链

    从问题入手,深入了解JavaScript中原型与原型链 前言 开篇之前,我想提出3个问题: 新建一个不添加任何属性的对象为何能调用toString方法? 如何让拥有相同构造函数的不同对象都具备相同的行 ...

  10. C# 如何复制(拷贝)Label控件上的文本【新方法】

    Label控件在目前是无法直接调用成员函数来复制其文本内容.其实网络上有很多热心程序员网民解答过这个问题,百度上也可以搜索到,不过大多数人建议使用 TextBox 并把边框调整为不可见(运行时文本框看 ...