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
7
votes
2 answers

Jshell crashes when i press BackSpace button in windows cmd

when I open windows cmd and type jshell , it works, but when I'm writing something . whenever I press the BackSpace key . for example if I want to delete a letter that is wrong . jshell crashes with bellow error , i'm using windows 10 , and…
Geco
  • 177
  • 1
  • 17
7
votes
2 answers

How to pass JVM options to jshell while starting it

I want to do the following : jshell -v -Duser.country=FR -Duser.language=fr So as to get for example a personalized Locale.getDefault().
HPH
  • 388
  • 2
  • 11
7
votes
1 answer

Disable JShell history

JShell by default enables a persistent history of everything typed, which can be recalled by pressing the up arrow. Where is the setting to turn this ❝feature❞ off? Also, how do I even clear the current history? Maybe I'm dumb but I can't figure out…
Boann
  • 48,794
  • 16
  • 117
  • 146
7
votes
8 answers

'jshell' is not recognized as an internal or external command

I am using the 'jshell command in my machine it is not recognised. But java command is working fine. is there any environment setup for jshell in jdk 10 C:\Users\Kannan λ jshell 'jshell' is not recognized as an internal or external command, operable…
Kannan Thangadurai
  • 1,117
  • 2
  • 17
  • 36
7
votes
1 answer

final variables are not functioning well in jshell

I am working with jshell of JDK9. I just created a final variable and assigned a value to it. And in the next line i just modified the value. And to my surprise, there was no error when modifying the final variables. Here is the code…
KayV
  • 12,987
  • 11
  • 98
  • 148
7
votes
1 answer

List all active methods in jshell

is there any command available that can print all newly created methods in current jshell session? Something similar to /list but only for methods
Niraj Sonawane
  • 10,225
  • 10
  • 75
  • 104
7
votes
1 answer

How to make javadoc documentation available in JShell?

I am using JShell to test a library for which I made classes, sources, and javadoc available through the class path like so: jshell --class-path library-javadoc.jar:library-sources.jar:library-jar-with-dependencies.jar Still, when double tab after…
Mario Boley
  • 341
  • 1
  • 8
7
votes
2 answers

Importing Package-Private Classes to JShell

I was playing around with JShell after the Java 9 release, and I tried importing a package I made. As the entire application I'm coding it for will be contained in that package, every class but one (which I haven't coded yet) is package-private. My…
Isaac Saffold
  • 1,116
  • 1
  • 11
  • 20
7
votes
1 answer

On Java 9 why is the output from System.getenv() incomplete in jshell?

I'm using Windows 10 and running the version of Java 9 released by Oracle yesterday. If I open a jshell and enter System.out.println(System.getenv()) the output is as expected, as shown in the lower portion of the screen shot below. However, if I…
skomisa
  • 16,436
  • 7
  • 61
  • 102
7
votes
1 answer

Access to "parent scope" in JShell

It seems, that JShell object created inside another JShell does not have access to parent's JShell scope. For instance: jshell> int x = 1; x ==> 1 jshell> x x ==> 1 jshell> jdk.jshell.JShell js = jdk.jshell.JShell.create(); js ==>…
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
7
votes
1 answer

Exit jshell with error code

How do I /exit a jshell session with a non-zero error code? /exit yields: Process finished with exit code 0 /exit 1 yields: Process finished with exit code 0 throw new Error("1") yields: java.lang.Error thrown: 1 at (#24:1)` and Process finished…
Sormuras
  • 8,491
  • 1
  • 38
  • 64
7
votes
1 answer

How to run a whole Java file added as a snippet in JShell?

I tried installing JDK 9 Early access version 172 to play around with JShell. When I tried to open a simple java file and execute it after adding it as a snippet, it just showed modified class Test and increased the snippet number. Can you please…
Kavitha Karunakaran
  • 1,340
  • 1
  • 17
  • 32
6
votes
1 answer

How do I get better performance out of JShell?

Background: Since Nashorn is being dropped in JDK15, I am looking for an alternative for an application I am working on. I am currently only using for the dynamic execution of some user-definable formatting snippets within a java swing desktop…
Skcussm
  • 658
  • 1
  • 5
  • 20
6
votes
2 answers

How to execute java jshell command as inline from shell or windows commandLine

Are there any way to execute java command on REPL (jshell) as inline command without launching it? E.g. Perl inline command $perl -e 'printf("%06d", 19)' 000019 I have to launch jshell to run any command: $jshell | Welcome to JShell -- Version…
Rahul Sharma
  • 5,614
  • 10
  • 57
  • 91
6
votes
1 answer

JShell is not working properly in jdk 9

While trying JShell in Fedora I tried to used snippet transformation shortcut as specified here , but I think It is not working It is showing Unexpected character after Shift-Tab. Use "i" for auto-import or "v" for variable creation. For more…
optional
  • 3,260
  • 5
  • 26
  • 47
1 2
3
13 14