Questions tagged [jshell]

JShell is a Read–Eval–Print Loop (REPL) tool to evaluate declarations, statements, and expressions of the Java programming language, together with an API so that other applications can leverage this functionality.

The JShell provides a way to interactively evaluate declarations, statements, and expressions of the Java programming language within the JShell state.

The JShell state includes an evolving code and execution state. To facilitate rapid investigation and coding, statements and expressions need not occur within a method, expressions need not have side-effects, variables need not occur within a class, and methods need not occur within a class or interface.

Furthermore, JShell can be used to create and run scripts.

Goals

  • The JShell API and tool will provide a way to interactively evaluate declarations, statements, and expressions of the Java programming language within the JShell state. The JShell state includes an evolving code and execution state. To facilitate rapid investigation and coding, statements and expressions need not occur within a method, and variables and method need not occur within a class.

  • The JShell tool will be a command-line tool with features to ease interaction including: a history with editing, tab-completion, automatic addition of needed terminal semicolons, and configurable predefined imports and definitions.

Non-Goals

  • A new interactive language is not the goal: All accepted input must match grammar productions in the Java Language Specification (JLS). Further, within an appropriate surrounding context, all accepted input must be valid Java code (JShell will automatically provide that surrounding context -- the "wrapping"). That is, if X is an input that JShell accepts (as opposed to rejects with error) then there is an A and B such that AXB is a valid program in the Java programming language.

  • Out of scope are graphical interfaces and debugger support. The JShell API is intended to allow JShell functionality in IDEs and other tools, but the JShell tool is not intended to be an IDE.

201 questions
3
votes
1 answer

How to show version in jshell

On startup jshell shows the version: Welcome to JShell -- Version 14.0.1 But is there a way to retrieve the version programmatically?
peer
  • 4,171
  • 8
  • 42
  • 73
3
votes
0 answers

How to configure JShell in Intellij for a multimodule project?

How can I configure JShell in IntelliJ to work with our complex multi-module Maven project? I have set "Use classpath of: " to "". How should I setup the "Project settings > Libraries"? At the moment it lists all our Maven…
Koohoolinn
  • 1,427
  • 6
  • 20
  • 29
3
votes
1 answer

Is there any way to delete history in JShell?

In JShell, is there any way to remove a statement that you executed like it never happened? For example, suppose we have the following code. JShell shell = JShell.create(); shell.eval("int x = 5;"); shell.eval("x = 7;"); Is there something in…
Lindstorm
  • 890
  • 2
  • 7
  • 22
3
votes
1 answer

Jshell /env command not allowing to Set More than one Jar file in Classpath

Hi I am using JDK11 on windows 10 operating system and Jshell version I am using is 11.0.1. I am trying to execute the various Jshell commands and got stuck in execution of below commands I have a sample program which is using the classes from more…
Beast
  • 639
  • 2
  • 14
  • 29
3
votes
1 answer

Jshell error: java.lang.NullPointerException: charsetName

I'm trying to use JShell provided by JDK11 to run some simple command. But when I type: jshell>System.out.println("Hello World!"); It gives me the error: Exception in thread "main" java.lang.NullPointerException: charsetName at…
ZhengguanLi
  • 113
  • 1
  • 2
  • 8
3
votes
2 answers

I'd like to use `jshell` with JDK 8

I tried out the JDK 11 jshell recently and liked being able to interactively test out what's documented in core Java. My company is still tied to releasing with Java 8 though. So I thought I'd try and see if I can use the jshell to work with JDK…
dlamblin
  • 43,965
  • 20
  • 101
  • 140
3
votes
2 answers

Getting JShell Error: ';' expected for basic HelloWorld.java program

Only ever used IDEs for developing in Java and wanted to learn how to use JShell but I'm getting the following error for a basic hello world example and anything else I try. Don't understand where the ';' error is coming from. |javac…
3
votes
1 answer

JShell console in Android Studio

IntelliJ IDEA 2017.1 has a built-in JShell, which imports all the project's libraries etc. Is it possible to use this in Android Studio? (It is not in the Tools menu, as said in the blog post). UPDATE: Android still does not support Java 8…
serv-inc
  • 35,772
  • 9
  • 166
  • 188
3
votes
1 answer

Create custom feedback mode in jshell

As from the documentation of /set feedback in jshell, there are following built-in modes: verbose, normal, concise, and silent Is it possible to create a feedback mode with the functionality of both concise and silent? Or we can change any one of…
KayV
  • 12,987
  • 11
  • 98
  • 148
3
votes
1 answer

How to use selectors in /set truncation command in jshell?

I am using jshell and want to truncate the very big message displayed on jshell console. For this, i got the /set truncate command which says: If the values are too long, then they are truncated when displayed. Use the /set truncation command to…
KayV
  • 12,987
  • 11
  • 98
  • 148
3
votes
5 answers

How to set sublime as an external editor for jshell?

According to the jshell documentation: An alternative to editing at the command prompt is to use an external editor. This editor can be used to edit and create snippets, and is especially helpful for multiline snippets. You can configure JShell to…
KayV
  • 12,987
  • 11
  • 98
  • 148
3
votes
0 answers

Running Java 9 jshell in Eclipse

How can I run Java 9 jshell in Eclipse? I want to easily run simple snippets of code directly in Eclipse IDE. I already tried to run jshell as an 'External Tool' configuration in Eclipse but when typing a command I don't get any response back.
vladul
  • 124
  • 1
  • 7
3
votes
2 answers

JShell - How to add method to existing class without replacing this class?

tl;dr : How to add method to existing class without replacing this class? Description: When I run following command in JShell: public class TestClass {} following output is printed: created class TestClass Running this command once more gives…
hpopiolkiewicz
  • 3,281
  • 4
  • 24
  • 36
3
votes
1 answer

Error: cannot find symbol - on every command

Out of curiosity, I decided to play with JShell. Now, I'm going through these Examples And I can't figure out how to use it. I'm using the JDK 9 - 108 build and the simple Linux shell commands doesn't seem to work. I tried ls, cd, mkdir and all I…
Alex Weitz
  • 3,199
  • 4
  • 34
  • 57
3
votes
1 answer

How to stop infinite loop in JShell / Kulla?

JShell is a Java REPL that is scheduled to be released alongside Java 9; however, there is an open beta for it. If I create an infinite loop in JShell (Project Kulla) by typing: -> while(true) {} JShell will loop forever. Short of completely…
Daniel M.
  • 1,433
  • 13
  • 24