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
0 answers

Using JShell to write application extensions

at the moment I use Beanshell to write application extensions. I just use BshMethod.invoke() to integrate it with the java application. Could this be done with JShell too? Load a script and execute a method in the script? Via a JShell API, not via…
Ickbinet
  • 277
  • 3
  • 12
1
vote
0 answers

How to integrate jshell with Spring Tool Suite or STS?

I have a project using the Jdk 9 library in STS or Spring Tool suite. Now what do i need to do to integrate or work with jshell from within the STS/eclipe?
KayV
  • 12,987
  • 11
  • 98
  • 148
1
vote
2 answers

How to run a single applications(JShell) on JDK 9, and all other on JDK 8?

I am trying to work with jshell of Java 9. So for that i installed the JDK 9 on my Mac, where i already had the JDK 8 installed. All my projects, workspaces, Hadoop, Spark and dependent APIs are using JDK 8. So for the current scenario, i can not…
KayV
  • 12,987
  • 11
  • 98
  • 148
1
vote
1 answer

Can i add jshell repl (java 9) to vscode's terminal panel?

New to vscode, search returns nothing. I'd like to add jshell to the terminal window. Is it possible?
hrs
  • 379
  • 4
  • 12
1
vote
2 answers

JShell possible lossy conversion from double to float

I was trying Java9 feature JShell. I'm not able to set a float value: jshell> float b = 3.5 Error: | incompatible types: possible lossy conversion from double to float | float b = 3.5; jshell> float x =2 x ==> 2.0
jos
  • 1,082
  • 5
  • 19
  • 45
1
vote
2 answers

JDK 9 jshell printf() special treatment?

I've been looking into JDK9 and i noticed that in jshell you don't have to prefix printf() with System.out.printf() i.e you can write printf("test") but you can't write println("test") Is this a feature of jshell only ? How you can achieve the same…
firephil
  • 830
  • 10
  • 18
1
vote
1 answer

Does jshell work with jmod files?

I followed some example and I created a simple jmod. I put jmod in my jmod folder not in java jmods folder. Now, I read that jshell can export modules, but I did understand. Can jshell work with jmods? Some example? In java jmods folder there are…
Germano Carella
  • 473
  • 6
  • 14
0
votes
0 answers

This simple sample runs in jshell but not in jbang. What could cause this difference?

I'm trying to get a simple jbang with dependency on class path sample working. When I run the exact same java file (except for bulleted differences below) via jshell under Java 17, passing the same class path, it succeeds. The function definition…
dudeNumber4
  • 4,217
  • 7
  • 40
  • 57
0
votes
2 answers

Cannot execute .jsh file on JShell

I'm a beginner at programming and practicing Java (using MacOS and jdk.17) but have been instructed to use JShell to deal with smaller/snippets of Java code. I installed JShell, opened a text editor to create and compile a file called Intro.jsh with…
0
votes
0 answers

Why jshell throw Exception at startup at windows when run `jshell` at my home directory?

When I run jshell 17 / 19 in windows powershell at my home dir, i.e. C:\Users\my_user_name, jshell throws exception as following. Jdk 19 installed with oracle win10 msi binary, path updated by $env:PATH='C:\Program…
djy
  • 737
  • 6
  • 14
0
votes
0 answers

JShell: Scanner nextLine() NoSuchElementException when using /open

When using JShell's /open command to open a Java file and run code, user input does not work with Scanner. It will always throw a NoSuchElementException when it reaches the nextLine() method. Does anyone know why this is, and is there a…
0
votes
1 answer

Windows WSL Ubuntu 22 doesn't recognise the upgraded Java version I installed on Windows

I'm a newbie and am confused over the setup for one of my cs courses. I originally have Java 8 in both Windows and Ubuntu, but then I realised that I need to use jshell for testing in Ubuntu as well, which is only available for Java 9 and…
HJ Wang
  • 21
  • 2
0
votes
0 answers

How to import jars from a directory for JShell in Mac OS terminal?

I'm wondering if there is a bug with Jshell. I have tried all forms of importing the commons lang jar into the classpath trying: 1 - This solution 2 - Also followed this solution too. I even launched jshell from the directory where the jar itself…
Dark Star1
  • 6,986
  • 16
  • 73
  • 121
0
votes
0 answers

How can i create a code in Jshell which can convert decimal into octal?

I'm having a problem with a task from uni and i cant seem to solve it myself.. here is a screen of the task I need to solve I have to create a code via java Jshell which can convert decimal into octal.. I tried watching videos and get some help on…
0
votes
0 answers

jshell - accessing the web behind corporate proxy

Is it possible to access the web behind a corporate proxy inside of jshell? Or to set environment variables inside of jshell in general? jshell does not seem to load the java environment variables that are set, like JDK_JAVA_OPTIONS, JAVA_OPTS, or…
theerrormagnet
  • 174
  • 2
  • 15