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
1
vote
1 answer

How to escape space in folder in JShell /env command in Windows

I am trying to set the external classpath in Java 11 JShell using /env --class-path command in windows OS. When the folder does not have space, it is working fine as shown below. But when the folder is having space, it is giving error as shown…
Siddarth
  • 351
  • 2
  • 6
  • 20
1
vote
0 answers

Unable to locate a Java Runtime that supports jshell

Currently getting an error when I run jshell or jenv shell on macos monterey. jshell jshell The operation couldn’t be completed. Unable to locate a Java Runtime that supports jshell. Please visit http://www.java.com for information on…
MicFin
  • 2,431
  • 4
  • 32
  • 59
1
vote
1 answer

jshell use external dependency from Maven repository

I'd like to use JShell to launch a Class which is contained in a Maven repository: io.undertow undertow-core 2.2.16.Final Looking at the docs, I…
Carla
  • 3,064
  • 8
  • 36
  • 65
1
vote
1 answer

How to use jdk.compiler module in jshell

my jdk version is 17 and i want use com.sun.tools.javac.file.JavacFileManager class, My startup parameters are $ jshell --add-modules jdk.compiler then i typed import com.sun.tools.javac.file.JavacFileManager; I got a error like this: | Error: | …
ght ggg
  • 39
  • 4
1
vote
0 answers

execute eval string jshell beanshell

In most of scripting/interpreting programming languages such as python or JavaScript, there is/are a/some method(s) to execute a string in runtime just like a code. For example: eval("int i=5;"); those could have run the eval method inside the…
Maj
  • 29
  • 4
1
vote
1 answer

Java downcasting with two different subclasses

I am learning Java and have been playing with up and downcasting in my command prompt using the classes I defined in Eclipse. I am working with three classes that I included here, and my question is at the bottom: public class Animal { public…
Tech320
  • 39
  • 5
1
vote
0 answers

Java 16.0.1, Jshell.... no text visible when entering commands in CMD

I have Java 16.0.1 installed on my windows 10 laptop. I am going into the command prompt and launching jshell. This starts correctly and displays the correct version. However, anything i type is not visible on the command prompt. If i press CNTR+C…
P Patel
  • 11
  • 1
1
vote
1 answer

JShell throws StringIndexOutOfBoundsException on startup

I'm trying to start a jshell on Debian 10 buster. I've downloaded jdk-16_linux-x64_bin.tar.gz from Oracle and unpacked it into 'jdk-16' in my home directory. I've set the PATH and JAVA_HOME: ~$ export PATH=~/jdk-16/bin:$PATH ~$ export…
Alex Sveshnikov
  • 4,214
  • 1
  • 10
  • 26
1
vote
0 answers

In JShell, how to load Java code from a string?

I have implemented a method that generates Java code: public static String generate() { ... } It returns Java code as a String, i.e. I might get "public class X { public static String x() { return \"x\"; } }" as a value returned by generate. Now,…
Lorenz Leutgeb
  • 474
  • 6
  • 12
1
vote
0 answers

Is it possible to emply Jshell whithin org-babel

In the Jshell, we could interact with codes as: jshell> 60 * 60 $1 ==> 3600 However, the arithmetic expression should be encapsulated in class when using org-babel. #+begin_src java :classname Expression :results output :exports both public…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
1
vote
1 answer

How to use regex from JShell?

I'm able to get output using .java files as below, and, while, yes, JShell can load class files, I'm more interested in using it as a sort of scripting REPL as below. How can I generate similar output using the JShell console? simple regex…
1
vote
1 answer

Google Colab with Java (using JShell)

I`m trying Java on GoogleColab using JShell. I could run it, but input fields is not visible(abc -> dot dot dot). Do you know how to solve it ? My scripts are; import os #importing os to set environment variable def install_java(): …
1
vote
1 answer

Jshell is not Printing properly with println method

why Jshell is considering r , s as string when used without brackets ? PS C:\Users\saiko\OneDrive\Learning\java> Jshell …
1
vote
2 answers

java JShell kill java process

Created a sample.jsh file with below code while(true){} Now i ran below command jshell sample.jsh It internally creates 2 process one is jshell process and another one is java process and java process is taking 100% cpu utilization. How to kill…
trinath
  • 433
  • 1
  • 5
  • 19
1
vote
0 answers

Command execution elapsed time in jshell

I looked for an option to have jshell report the execution time of a command, but I could not find any. Then my question is what is the best way to have elapsed time reported when submitting a command for execution in jshell? Example To check the…
Marco Torchiano
  • 712
  • 7
  • 21