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

How to Call user-defined Lambda Function in Java

In this tutorial, I saw an example of a user-defined lambda function. Function toLowerCase = (var input) -> input.toLowerCase(); What I am wondering is how can I call this function? I tried it in jshell but am unable to. I can…
richie
  • 21
  • 2
1
vote
1 answer

JShell language encoding in DOS/Windows

I'm encountering the issue of having jshell not displaying non-english letters on MS-Windows. On Linux and Mac jshell behaves correctly. In a DOS window, I try to enter Greek letters, e.g.: jshell> var s = "Γειά" but I can only see jshell> var s…
hawk
  • 11
  • 2
1
vote
1 answer

why does jshell return empty String using StackWalker

Is it an Error? I would at least expect an Exception instead of empty String for: jshell> ((Supplier)(()->StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE).getCallerClass().getName())).get()+"invisible"; $1 ==> "" using…
jukzi
  • 984
  • 5
  • 14
1
vote
1 answer

How to create JShell programmatically when SecurityManager is set

I want to create JShell programmatically when the security manager is set before. However, this causes an access control exception. Without the security manager set the code works correctly. I thought that the Java platform modules have all…
appsofteng
  • 152
  • 5
1
vote
2 answers

how to set classpath for spring project in jshell

I'm learning to use spring framework and I can't seem to find a tool similar to Django shell_plus. I'd like to be in a java repl in which I have access to all my classes, dependencies and etc. I've googled and found j-shell and spring-shell but…
andrew
  • 13
  • 1
  • 7
1
vote
1 answer

Getting "Error on input: java.io.IOException: Resource temporarily unavailable" when pressing Tab in jshell

So I was fiddling some code in jshell, but it started crashing when I pressed Tab. int[] a = new int[]{1, 2, 5, 0, -1} In my next statement, when I type A-r-r-a, then (Tab) to autocomplete to Array and get options, it crashes with Error on input:…
youneverknow
  • 137
  • 2
  • 8
1
vote
2 answers

Could not initialize JShell in Apache NetBeans IDE 10.0

I have installed OpenJDK 11 (version 11.0.2) on macOS Mojave (version 10.14.2) following these steps. Then I tried to launch a JShell session in Apache NetBeans IDE 10.0, but I'm getting this error: | Could not initialize JShell: Launching JShell…
Boris
  • 22,667
  • 16
  • 50
  • 71
1
vote
0 answers

java.xml.bind no more exists in the JDK/11

I'm new here and I do apologize in advance if I do here something wrong. I tried to use JShell in IntelliJ 2018.2.5 with Java 11.0.1 but it doesn't work. Everything work just fine in command prompt and basically my problem is exactly the same as…
novice
  • 41
  • 4
1
vote
0 answers

JShell evaluation doesn't print anything in Idea 2018.2

I'm trying to use the new JShell from IntelliJ 2018.2 and although nothing seems to go wrong, the console isn't printing anything. I'm using the following super simple snippet: String test = "asdf"; System.out.println(test); And get the following…
PentaKon
  • 4,139
  • 5
  • 43
  • 80
1
vote
0 answers

jshell (Java 9 shell) integration does not respond in SublimeREPL

I have tried to integrate the jshell Java 9 REPL into SublimeREPL as described in this documentation. I have set up the files correctly: When I run the REPL from Sublime, I get the initial output generated by the REPL, so I know it is able to…
1
vote
0 answers

Is this possible to run independent Java REPLs from single JVM?

Is this possible to have multiple JShell instances in a single JVM whilst keeping them independent? Like each instance having separate classpath/class definitions even if their names are the same? I want to create multiple REPLs but avoid creating a…
Marcin
  • 4,080
  • 1
  • 27
  • 54
1
vote
1 answer

how to use Jshell meta-commands in intellij idea

When I use /var,the Intellij idea's jshell console show me as follows: ERROR: illegal start of expression Rejected /var
jessey
  • 455
  • 1
  • 3
  • 12
1
vote
2 answers

jshell finishes silently if the user tries to source a script with some error

Follow these steps to reproduce: Create a '.jsh' script with some kind of error(missing import, syntax error etc) open a jshell /open the erroneous script The /open command will finish silently. The elements declared in that script won't be in the…
saga
  • 1,933
  • 2
  • 17
  • 44
1
vote
3 answers

JShell Edit Pad Not Executing / Running Code Snippets

I am very new to jshell and Java and am having an issue with the jshell edit pad not accepting or transferring code snippets to jshell. When I enter the code snippet below and press "Accept" and "Exit" nothing is happening. No error messages are…
1
vote
3 answers

The program 'jshell' is currently not installed when trying to run jshell on Ubuntu

I have downloaded and "manually" installed JDK 10 for Linux 64bit edition (for Ubuntu 16.04), Oracle Java SE Development Kit (note: I wanted to download the Java9 JDK but this is no longer supported and I was referred to the Java 10 SE Development…
robbie70
  • 1,515
  • 4
  • 21
  • 30