jshell

Is there an alternate way to launch remote jvm?

Deadly 提交于 2019-12-04 13:20:57
I am playing with the JDK9's JShell API. At present, the JShell API automatically launches the remote JVM internally. Instead of starting the process automatically, I want to separate the two process. Note: I understand I can change the VM options. But I want to see if the VM can even be run on a different machine. The default execution control eventually reaches this place in code . If I specify launch, it automatically uses com.sun.jdi.CommandLineLaunch connector, that actually launches the java program by definition. If I specify no-launch, it uses com.sun.jdi.SocketListen as I would expect

How to run a whole Java file added as a snippet in JShell?

拜拜、爱过 提交于 2019-12-04 12:09:48
问题 I tried installing JDK 9 Early access version 172 to play around with JShell. When I tried to open a simple java file and execute it after adding it as a snippet, it just showed modified class Test and increased the snippet number. Can you please help me realize where I went wrong? | Welcome to JShell -- Version 9-ea | For an introduction type: /help intro jshell> /open G:\kavitha\Test.java jshell> /list 1 : public class Test{ public static void main(String[] args){ int i = 1; int j = 2;

Importing Package-Private Classes to JShell

痴心易碎 提交于 2019-12-04 09:27:41
I was playing around with JShell after the Java 9 release, and I tried importing a package I made. As the entire application I'm coding it for will be contained in that package, every class but one (which I haven't coded yet) is package-private. My classpath is correct, but I still can't use any of the types declared in the package in JShell (it throws a "cannot find symbol" error). Do I need to make them public for them to be accessible, or is there some way I can test package-private classes ? Here's the exact code I tried. My current directory is C:\Users\Sylvaenn\OneDrive\Documents

In jshell-11, why does a redeclared reference variable that resets to null still have a type?

巧了我就是萌 提交于 2019-12-04 01:11:24
When redeclaring Integer 'a' in line 33, why does jshell show the reference variable as an instance of Integer (refer to lines 38 & 39)? After the redeclaration, line 34 shows that 'a' is set to null. When 'a' is declared in line 6 but not given a value, or reset to null in line 22, 'a' is not considered an instance of Integer. I would expect that when the reference variable is redeclared, since its value is null, that it would not be an instance of a type; however, that is not the case. 01: java-lava:~ cafedude$ jshell 02: | Welcome to JShell -- Version 11 03: | For an introduction type:

Multiline paste in jshell

若如初见. 提交于 2019-12-03 23:29:39
I was trying out jshell and couldn't find option to paste multiple line expressions. Is it even possible to paste multiple lines in jshell. Similar to what scala offers with paste mode . So if you have code like this: int c = 2; int j = 4; int x = 5; Copy and paste into jshell, only the first two statements are processed. But if you have code like this: int c = 2; int j = 4; int x = 5; And paste into jshell: jshell> int c = 2; int j = 4; int x = 5; c ==> 2 j ==> 4 x ==> 5 Even more lines of code like this: HashMap<Integer, Integer> map2 = new HashMap<>(); for (int i = 0; i < 15; ++i) { map2

How to execute java jshell command as inline from shell or windows commandLine

試著忘記壹切 提交于 2019-12-03 21:53:10
Are there any way to execute java command on REPL ( jshell ) as inline command without launching it? E.g. Perl inline command $perl -e 'printf("%06d", 19)' 000019 I have to launch jshell to run any command: $jshell | Welcome to JShell -- Version 9 | For an introduction type: /help intro jshell> String.format("%06d", 19) $1 ==> "000019" I found similar question here , but it's not feasible solution to create a separate jsh file for individual command. Another solution on same post is: echo "1+2"|jshell temp=`echo 'String.format("%06d", 19)'|jshell` echo $temp Ouch output | Welcome to JShell --

Different behaviour of same statement while executing on JShell

浪尽此生 提交于 2019-12-03 21:06:17
问题 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 = a; } Now if instead of above initialisation, if I use below statement: A a = new A(new B(a)); I got below error which is quite obvious: Main.java:19: error: variable a might not have been initialised A a = new A(new B(a)); But if I try the same on JShell, it

What is the use of C option in jshell

白昼怎懂夜的黑 提交于 2019-12-03 16:12:52
I have gone through the introduction to jshell guide and couldn't find description/examples about the -C option in jshell. $jshell --help -C<flag> Pass <flag> to the compiler. Use one -C for each compiler flag or flag argument You can use this option to make use of javac command line arguments for example consider this piece of code: String str = (String)"Hello" Starting jshell normally and using the same would result as: While at the same time you can enable compiler errors on warning( -Werror ) and make use of the -Xlint key cast while compiling to warn you of the explicit cast used in the

How to pass arguments to a jshell script?

最后都变了- 提交于 2019-12-03 11:36:15
问题 Question I am willing to pass arguments to a jshell script. For instance, I would have liked something like this: jshell myscript.jsh "some text" and then to have the string "some text" available in some variable inside the script. However, jshell only expects a list of files, therefore the answer is: File 'some text' for 'jshell' is not found. Is there any way to properly pass arguments to a jshell script? Workaround so far My only solution so far is to use an environment variable when

How to shutdown jshell at the end of the script?

六月ゝ 毕业季﹏ 提交于 2019-12-03 10:34:36
问题 How to instruct jshell to terminate at the end of the script similarly to interpreters of other languages like for example python3 or node ? Following command ./jshell -q /tmp/shell.java with script /tmp/shell.java System.out.println("Hello world"); prints Hello world jshell> and waits for further commands. I'd like it to stop immediately at the end of the file. I'm looking for something more elegant than System.exit(0); at the end of the script. 回答1: Inside the script, use the jshell command