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

'Cannot find symbol' when sorting a stream of files using compareToIgnoreCase (JShell)

Using JShell of java 13.0.1 on Debian Stretch: import static java.nio.file.Files.*; var hm=Path.of(System.getProperty("user.home")); void p(String s) {System.out.println(s);} list(hm).sorted((a,b)->a.compareTo(b)).forEach(x ->…
ngong
  • 754
  • 1
  • 8
  • 23
0
votes
1 answer

How to access a Java class in the default package from jshell?

I am unable to access Java classes in the default package from jshell. I cannot import since the default package has no name and when I try to reference the name then I have an error: jshell> Test.test(); | Error: | cannot find symbol | …
Pierre Thibault
  • 1,895
  • 2
  • 19
  • 22
0
votes
0 answers

Does jshell scripts support schebang?

I noticed that you can easilly use schebang with Java files as described in JEP-330 http://openjdk.java.net/jeps/330#Shebang_files. I would like to achieve the same but for JShell scripts #!/usr/bin/jshell System.out.println("hello"); However…
Aleksander Lech
  • 1,105
  • 12
  • 16
0
votes
1 answer

jshell : Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable

I run this /edit command in jshell java-11,When throw the exception. Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable. I'm using Debian 9.0 operating System. Exception…
Ng Sharma
  • 2,072
  • 8
  • 27
  • 49
0
votes
1 answer

How Jshell works without semicolon at end of line

I'm new for java 9 and just practicing some snippet of code on jshell jshell> System.out.println("hello"); hello jshell> System.out.println("hello") hello In the both the cases I'm getting output of hello but jshell works without semicolon at…
app
  • 733
  • 5
  • 15
  • 27
0
votes
1 answer

JShell - prevent enter key to execute Java statement or How to set statement delimiter

I'm practicing Java APIs in JShell prompt(feature added as part of Java 9). Is there a way to customize or set custom statement terminator (generally ; in java). Because as soon as I hit ENTER key, the Java statement got executed in JShell…
Sriram M
  • 482
  • 3
  • 12
0
votes
1 answer

I have stored all the jar file into specific folder. How to configure specific folder to Jshell classpath ?

I have stored all the jar file into specific folder and I have added specific folder to Jshell classpath. I am unable to import packages in jshell after adding classpath. It is working fine If I have mentioned all the jar file name in classpath. I…
poovaraj
  • 609
  • 1
  • 6
  • 10
0
votes
1 answer

Not able to start spring boot application using jshell

I am trying to start a spring boot jar executable for my project from jshell but it throws an exception and does not start. Commands that I am running: ./jshell --class-path myapp-0.0.1-SNAPSHOT.jar Once jshell starts I…
hithacker
  • 151
  • 7
0
votes
1 answer

Java Shell line input on Windows

The Java Shell REPL's line input on Windows doesn't behave the way line input behaves in most other Windows console applications: The Ctrl+Left Arrow key combination does not go to the start of the previous line. The End-of-File character is Ctrl+D…
DodgyCodeException
  • 5,963
  • 3
  • 21
  • 42
0
votes
1 answer

How (or in which file) does JShell store its configuration settings?

The doc says: Remember that the startup scripts are loaded into the current session only when the state is reset. The contents of the script is stored, not a reference to the…
nawK
  • 693
  • 1
  • 7
  • 13
0
votes
0 answers

How to get reference to the current running Jshell

I have a file in which I wrote some vars. I want to parse this variables on an runtime application which is opened with the JShell to this instance of Jshell. FileWithVars.XYZ float x = 5f; String s = "TestString"; Currently I load this file with…
0
votes
2 answers

Exit jshell in java9 version

I recently upgraded to java9 and I am using the Jshell option which java provides. I find it intuitive but I am not able to close the Jshell window, can someone suggest some command for the same.
Mike
  • 35
  • 6
-1
votes
1 answer

What is the difference between "int x = (int) x" and "x = (int) x" in java if I assign "double x = 2.3"?

if I assign "double x = 2.3", what is the difference between "int x = (int) x" and "x = (int) x" ? I'm new to java and use python before, in python, if I execute "x = 2.3; x = int(x); print(x)", x is 2. java: python:
njulhy
  • 67
  • 1
  • 4
-1
votes
4 answers

Why is the Jshell not executing Methods cotaining Enum fields?

I have a simple Class. Zelle is a simple Enum. public class Main { public void getZelle (){ System.out.println(Zelle.RED); } public static void test(){ System.out.println(Zelle.Empty); } public static void…
lz01
  • 47
  • 7
-1
votes
1 answer

IntelliJ IDEA jshell_console still reports error after rebuilding the project

I'm new to Java. I wrote some simple code that converts integer to binary. I want to test if the code works in the jshell_console so that i won't need a "main" every time. At first, I forgot to use "public" when I declared the class in my source…
CDawn
  • 13
  • 3
1 2 3
13
14