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
6
votes
1 answer

error : java.lang.InternalError: Failed remote launch: com.sun.jdi.CommandLineLaunch

I have to do a project using jshell java 9 feature. But when i'm launching in intellij with java 9 i have this error : java.lang.InternalError: Failed remote launch: com.sun.jdi.CommandLineLaunch What could be causing this?
Damien Chesneau
  • 457
  • 2
  • 18
5
votes
2 answers

Where is JShell history stored?

Does anybody know where JShell history is stored (Java-11/Open JDK on Windows-10, but any config might be useful)? I've been looking around in $HOME ($USERPROFILE, $APPDATA, ...). Is it file based? JShell is JLine based, right? I indeed found…
jgran
  • 1,111
  • 2
  • 11
  • 21
5
votes
3 answers

How to take user input in jshell script?

Question: How to take user input in jshell script? or what I'm doing wrong? Note: I'm NOT looking how to pass arguments to jshell script. Example: For example script hello.java: Scanner in = new Scanner(System.in); System.out.print("Enter number…
my-
  • 604
  • 9
  • 17
5
votes
1 answer

JShell dollar variable name numbering

When I enter an expression in JShell (9.0.1) it comes back with: $22 -> Where does the 22 come from and what's happened to $1 to $21? (They are undefined.) I seem to vaguely remember (when I started with Java 9.0) that the variables started…
DodgyCodeException
  • 5,963
  • 3
  • 21
  • 42
5
votes
2 answers

Is there a way to modify module path and added modules of a programmatic JShell instance?

I'm trying to run some Java code at run-time through a JShell instance I created using the JShell API. To demonstrate my problem, I'm going to share my simple code. With my current setup I have a directory called lib that has the MySQL Java driver:…
5
votes
4 answers

jshell - unable to find printf

Why does my jshell instance (JDK Version 9-ea) unable to identify printf() statement ? Below is the error I observe, jshell> printf("Print number one - %d",1) | Error: | cannot find symbol | symbol: method printf(java.lang.String,int) | …
R K
  • 1,283
  • 1
  • 14
  • 41
5
votes
1 answer

Why can't I import sun packages?

I downloaded java 9 from https://jdk9.java.net and installed it on my Windows 10 machine. Java 9 has jshell, which I can use to evaluate and learn java programming. Some examples import sun packages, such as sun.audio.* etc. But, in jshell, every…
Germano Carella
  • 473
  • 6
  • 14
5
votes
1 answer

Unable to execute jshell from Mac Terminal

I am currently using java 1.8 on my Mac Sierra. java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode) Now I want to run "jshell" for executing…
Panchu
  • 1,219
  • 1
  • 9
  • 13
5
votes
1 answer

View classpath in jshell

JShell is a REPL for Java. To use additional classes outside the default JRE it contains a /classpath command to add a path to the current classpath. Is there however a way to view the current classpath within the JShell environment? Note that I'm…
Maarten Bodewes
  • 90,524
  • 13
  • 150
  • 263
4
votes
2 answers

Java 10: "No documentation found" for System.out.println(...)

On a debian 10, I install Java SE 10 using apt-get install openjdk-10-jdk openjdk-10-doc. I called jshell and wanted to get the documentation of System.out.println(...), but got an error : | Welcome to JShell -- Version…
Markus
  • 578
  • 6
  • 26
4
votes
2 answers

Different behaviour of same statement while executing on JShell

I was working on a problem to store reference of two classes within each other For Example: class A { B b; A(B b){ this.b = b;} } class B { A a; B(A a){ this.a = a;} } public static void main(String...s){ A a = new A(new B(null)); a.b.a =…
Aman Chhabra
  • 3,824
  • 1
  • 23
  • 39
4
votes
2 answers

How to run a java application with jshell?

How to run a java application with jshell? It should be able to specify classpath and call java command and pass some arguments like bash does,e.g, #!/bin/bash $ARGS=... $CLASSPATH=... java -cp $CLASSPATH $ARGS com.example.MyApp Update: I think a…
Leon
  • 3,124
  • 31
  • 36
4
votes
1 answer

How can I make JShell stop wrapping lines back on themselves?

I'm using JDK 9 build 179 on Windows 7. I've got the "Screen Buffer Size Width" property of my Windows 7 command shell, set to a large number because that's the way I roll. That works fine normally; when I'm simply using the Windows shell on its…
4
votes
1 answer

Method declared in JShell are lambdas?

I am a bit curious about how method ,declared in JShell is implemented under the hood . eg . int add(int x,int y){ return x+y; } is above declared method instance of BiFunction ? May be a stupid question but just for curiosity.
optional
  • 3,260
  • 5
  • 26
  • 47
4
votes
2 answers

Is there a way to remove imports in JShell?

I'm discovering JShell and I discovered the imports added in by default: jshell> /imports | import java.io.* | import java.math.* | import java.net.* | import java.nio.file.* | import java.util.* | import java.util.concurrent.* | …
Thibstars
  • 1,085
  • 1
  • 9
  • 30