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

Does JShell compiles statements or directly executes them?

Reading "Learning Java" by O'Reilly and getting familiar with how does the JDK work, I have come upon JShell. However, I'm not quite sure I understand how this REPL works deep down. Does it compile each statement into bytecode and thereafter…
Kaloyan
  • 41
  • 1
  • 6
0
votes
1 answer

How do I stop the output from being printed in jshell

How do I stop the output being printed? I don't want it to be like this i=15 $1==15 I just want it to be processed without the output being printed I tried looking everywhere and trying new lines of code and searching online and I couldn't find…
person_tm
  • 1
  • 1
0
votes
1 answer

JShell Error when initialize a list: "Expression expected"

I am an absolute Java newbie and just got started learning Java. I came across this JShell functionality within IntelliJ where one can write some quick code without writing any class constructs. But the problem which annoys me for quite some time is…
codeedoc
  • 454
  • 2
  • 7
  • 16
0
votes
2 answers

Can't press enter in jshell on Linux-terminal

I'm using Xubuntu. When I start jshell in the terminal, I doesn't recognize when I press the enter key. Every other key gets detected normaly. Any suggestions how to fix that?
Sandmann
  • 49
  • 6
0
votes
0 answers

Jshell displays mess code when invoke it from Powershell

I am working in Win10 build 19041 with "jshell 16.0.1”, when try to invoke interactive Jshell from command line, it display as: ~ λ jshell | ???? JShell -- ?? 16.0.1 | ????????, ???: /help intro What's the problem about the mess codes of "????"…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
0
votes
1 answer

Set Output Stream of specific JShell

I have a code : public class App { public static void main(String[] args) { System.out.println("Hello World from main!"); JShell shell = JShell.builder().build(); shell.eval("System.out.println(\"Hello World from…
Jaysmito Mukherjee
  • 1,467
  • 2
  • 10
  • 29
0
votes
2 answers

Installed Java 11, opened Jshell, command typed is not shown and hitting enter does not do anything

I uninstalled Java 8, installed Java 11 configured environment path. Opened command prompt in administrator mode, typed jshell which opened jshell and shows following text: C:\WINDOWS\system32>jshell | Welcome to JShell -- Version 11.0.10 | For an…
0
votes
1 answer

jshell classpath in Windows

I have a list of JARS in a directory and I need to add then to JShell classpath. I was trying to avoid typing each individual JAR file name and using wildcard "*" by CLASSPATH environment variable. But in Windows 10, apparently, jshell is not taking…
SRaj
  • 1,168
  • 1
  • 14
  • 36
0
votes
0 answers

Why using System.loadLibrary() doesn't seem to work on jshell command prompt?

Consider the simplest possible example of using JNI consisting of a C file #include #include #include JNIEXPORT void JNICALL Java_org_example_hi_sayHi(JNIEnv*, jobject) { puts("hi from native code"); …
VZ.
  • 21,740
  • 3
  • 39
  • 42
0
votes
0 answers

Problem with jshell on intellij IDEA on the terminal

I have a problem with jshell on intellij IDEA on the terminal for type curly braces, when I select alt gr + shift and the brackets, the terminal don't create a curly brackets but say, press tab again to see all possible complections, I have an…
0
votes
0 answers

Keyboard shortcut in Jshell to assign an expression to a local variable?

For example, I want to type something like below in Jshell new Random().nextInt() and then use a keyboard shortcut to generate a local variable with the correct return type. int x = new Random().nextInt() Is there any in-built or user-defined…
0
votes
0 answers

How do I parse a String as Java code at runtime and run it for a simple expression, without creating a security problem?

Presume the following input: String code = "availableProcessorCount / 4 * 3"; // This is a Java expression And this is my application: int availableProcessorCount = Runtime.getRuntime().availableProcessors(); int result = runJavaCode(code,…
Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
0
votes
0 answers

Disable jshell tab completion

I want to know if it is possible to disable tab completion in jshell, looking in jshell --help, it has characteristics for feedback --feedback Specify the initial feedback mode. The mode may be predefined (silent,…
anquegi
  • 11,125
  • 4
  • 51
  • 67
0
votes
1 answer

(Mac) jshell cannot find runtime environment

I am trying to use jshell to learn basic Java behavior. When I use terminal to navigate to the directory where jshell is located: cd /Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/bin And then type jshell into the command prompt, I…
0
votes
0 answers

JShell zsh: unknown file attribute: 5

Recently I found this git. But when I'm trying to execute it with jshell -J-cp -J./lib/chartsy-jshell.jar --execution rmi:host(localhost),port(52099) it says zsh: unknown file attribute: 5. So I don't understand how to run it.
Tatonka_q
  • 1
  • 1
  • 1