202 questions
0
votes
0
answers
45
views
Jshell unable to locate a file that it has
I have a jshell in Vscode that opens multiple files which are important for each other , I have the snowflakefractal which extends fractal , when do /open it opens everything fine no errors , but when ...
1
vote
1
answer
273
views
Stackblitz "Failed to run start command"
Today I wanted to continue working on my Github reposiroty via Stackblitz and ran into some issues. For some reason I'm not able to start the terminal process to start the live server. I need it to ...
1
vote
1
answer
66
views
Java jdk.jshell.CompletenessAnalyzer
How do you use jdk.jshell.CompletenessAnalyzer ? this class is not public !
I want to implement my own shell with jshell with my own custom commands like /bin/bash .
how can implement auto completion ?...
0
votes
2
answers
70
views
Why does adding println() at end of printf function not print out the new variable set in Jshell?
When you don't add println():
jshell> System.out.printf("5 * 2 = %d & 8 * 10 = %d", 5*2, 8*10)
5 * 2 = 10 & 8 * 10 = 80$9 ==> java.io.PrintStream@68de145
jshell>
when you ...
1
vote
2
answers
127
views
jshell always exits with zero status code
I use Linux and have noticed that jshell always exits with code 0 even if the java expression is invalid:
$ echo "invalid java expression" | jshell -
Error:
';' expected
invalid java ...
-2
votes
1
answer
65
views
What are rules in casting primitive types in expressions in Java? [duplicate]
I'm trying to figure out why some castings work and why others do not. Can you explain to me why some of these examples work and others don't?
Setup:
I'm using jshell.
byte one = 1;
one ==> 1
...
0
votes
2
answers
660
views
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 ...
1
vote
0
answers
267
views
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:...
0
votes
1
answer
465
views
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, ...
2
votes
0
answers
100
views
Add local variable to JShell evaluation context
I'm using jdk.jshell.JShell to evaluate Java code programmatically and I'd like to add a local variable to the active evaluation context, so the value is useable in the shell.
I'm instantiating the ...
3
votes
2
answers
272
views
How to use Lombok in jshell?
How I can use Lombok annotation in JShell?
I tried
* jshell --class-path lombok.jar
jshell> import lombok.*
jshell> @Data class Person { String name; String address; }
| created class Person
...
2
votes
1
answer
68
views
Why does jshell show this number?
I am learning java and this logic makes me feel confused.
Isn't here i=20(+1)+20(+1)?
Why 41 instead of 42?
jshell> int i = 20
i ==> 20
jshell> i=i++ + i++
i ==> 41
See this code run at ...
1
vote
1
answer
153
views
How to escape space in folder in JShell /env command in Windows
I am trying to set the external classpath in Java 11 JShell using /env --class-path command in windows OS. When the folder does not have space, it is working fine as shown below.
But when the folder ...
2
votes
1
answer
112
views
What is Java module jdk.editpad?
The JDK ships with a module jdk.editpad that exports no services or packages. The Javadoc describes this module as:
Provides the implementation of the edit pad service used by jdk.jshell.
But if you ...
0
votes
0
answers
127
views
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 ...
-1
votes
1
answer
182
views
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 =...
-1
votes
4
answers
472
views
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(...
10
votes
1
answer
387
views
In Java, what does the / (i.e., forward slash) mean in object references like $Lambda$15/0x00000008000a9440@32e6e9c3)?
In JShell, if I do this:
interface Foo { String foo(); }
(Foo) () -> "hi"
I get
| created interface Foo
$2 ==> $Lambda$15/0x00000008000a9440@32e6e9c3
From the research below, I know ...
1
vote
0
answers
351
views
Unable to locate a Java Runtime that supports jshell
Currently getting an error when I run jshell or jenv shell on macos monterey.
jshell
jshell
The operation couldn’t be completed. Unable to locate a Java Runtime that supports jshell. Please ...
0
votes
1
answer
83
views
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 ...
1
vote
1
answer
623
views
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 ...
1
vote
1
answer
423
views
jshell use external dependency from Maven repository
I'd like to use JShell to launch a Class which is contained in a Maven repository:
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId&...
2
votes
0
answers
88
views
Why does JShell have an echo in my shell demo?
I am writing a simple shell demo that highlights a problem I am having with JShell. When I pass JShell as an argument to /bin/zsh -c it works fine except for the fact that my Process echoes back ...
2
votes
0
answers
111
views
Java Jshell keyboard macros
I have been reading the Oracle Jshell User Guide, one feature of Jshell Hotkeys escapes my grasp, the so called keyboard macro function, by definition it sounds quite useful, you should be able to ...
4
votes
0
answers
231
views
How to set lineeditor to vi-mode in JShell
How to set lineeditor to vi-mode in JShell?
The setting set editing-mode vi is in both $HOME/.inputrc and $HOME/.jline.rc, but it seems like Jshell does not respect any of them.
0
votes
2
answers
1k
views
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?
1
vote
1
answer
612
views
How to use jdk.compiler module in jshell
my jdk version is 17 and i want use com.sun.tools.javac.file.JavacFileManager class, My startup parameters are
$ jshell --add-modules jdk.compiler
then i typed
import com.sun.tools.javac.file....
1
vote
0
answers
149
views
execute eval string jshell beanshell
In most of scripting/interpreting programming languages such as python or JavaScript, there is/are a/some method(s) to execute a string in runtime just like a code.
For example: eval("int i=5;&...
2
votes
1
answer
95
views
Why jshell allows non-final free variables in lambda expressions?
In a .java file, following will not compile:
class Test {
public static void main(String[] args) {
int x = 0;
Runnable r = () -> System.out.println(x);
r.run();
...
2
votes
2
answers
582
views
Unexpected Type Error when using Unary Operator --
I am learning Java and am experimenting with the unary operators --expr, expr--, and -expr.
In class, I was told that --3 should evaluate to 3. I wanted to test this concept in the following ...
1
vote
1
answer
319
views
Java downcasting with two different subclasses
I am learning Java and have been playing with up and downcasting in my command prompt using the classes I defined in Eclipse. I am working with three classes that I included here, and my question is ...
0
votes
0
answers
74
views
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 ...
1
vote
0
answers
80
views
Java 16.0.1, Jshell.... no text visible when entering commands in CMD
I have Java 16.0.1 installed on my windows 10 laptop.
I am going into the command prompt and launching jshell. This starts correctly and displays the correct version.
However, anything i type is not ...
1
vote
1
answer
162
views
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();
...
3
votes
1
answer
229
views
What other than java.lang packages are imported automatically in the JShell?
I've observed that in the JShell session, not only package "java.lang", but quite a few other packages (that are not imported automatically in the Java class files, e.g. LinkedList, Math and ...
0
votes
2
answers
971
views
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>...
1
vote
1
answer
315
views
JShell throws StringIndexOutOfBoundsException on startup
I'm trying to start a jshell on Debian 10 buster. I've downloaded jdk-16_linux-x64_bin.tar.gz from Oracle and unpacked it into 'jdk-16' in my home directory. I've set the PATH and JAVA_HOME:
~$ export ...
-2
votes
1
answer
398
views
How to get the value passed to a variable?
I am trying to evaluate a code snippet that has variables initialised to a value. Is there a way to get the field values using java? For the below code:
public void testArea(){
int length = 5;
...
2
votes
1
answer
112
views
Cursor movement keys not working properly in jshell on macOS terminal
In the following start to a snippet I had typed some nonsense asd that I then hit backspace to overwrite:
jshell> void asd$<3$<3>
As can be seen instead of backspace I got $<3 . Right ...
0
votes
1
answer
423
views
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 ...
0
votes
0
answers
243
views
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 <jni.h>
#include <stdio.h>
#include <syslog.h>
JNIEXPORT void JNICALL Java_org_example_hi_sayHi(...
3
votes
1
answer
876
views
In JShell, How to evaluate whole java code?
I'm using the JShell API to run Java code. However, I got an error when I run a whole code.
For example:
import jdk.jshell.JShell;
var code= """
void hello(){
...
4
votes
0
answers
267
views
JShell no longer prints output on next line after JDK update
Before updating JDK, any output in JShell would be automatically printed onto the next line. However, after updating, all the outputs are immediately printed onto the same line. This makes it ...
1
vote
0
answers
125
views
In JShell, how to load Java code from a string?
I have implemented a method that generates Java code:
public static String generate() { ... }
It returns Java code as a String, i.e. I might get
"public class X { public static String x() { ...
-3
votes
4
answers
67
views
I'm trying to print out prime number but not sure what's wrong with my code
My code
void printPrimes (int max) {
boolean prime;
for (int n = 2; n < max; n++){
prime = true;
double maxF;
maxF = Math.sqrt(n);
for (int f = 2; f < ...
1
vote
0
answers
127
views
Is it possible to emply Jshell whithin org-babel
In the Jshell, we could interact with codes as:
jshell> 60 * 60
$1 ==> 3600
However, the arithmetic expression should be encapsulated in class when using org-babel.
#+begin_src java :classname ...
3
votes
1
answer
143
views
Run echo example from Jshell [duplicate]
I read such a command line arguments example:
public class Echo {
public static void main (String[] args) {
for (String s: args) {
System.out.println(s);
}
}
}
It ...
-2
votes
2
answers
3k
views
How do you load an external file in JShell?
JShell is the interactive REPL command line for Java.
If I have a Java class with some methods that I would like to play around with interactively in a .java file, how do I load that file in?
Let's ...
0
votes
0
answers
287
views
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 ...
2
votes
0
answers
752
views
Getting JShell UnresolvedReferenceException when trying to use methods from external library in the image created with JLink tool
I created an application using the JShell API and I'm loading some external libraries using the method addToClasspathand I'm using JavaFX for the GUI, additionally I'm loading some snippets from ...