More Related Content Similar to Introduction to JShell: the Java REPL Tool #jjug_ccc #ccc_ab4 (20) Introduction to JShell: the Java REPL Tool #jjug_ccc #ccc_ab422. #ccc_ab4 https://sli.do/
Java8Puzzler(デモ)
String s = Stream.of("Hello", "Fizz", "Buzz",
"JavaSE8")
.map(String::length)
.map(Integer::toString)
.collect(Collectors.joining(", "));
System.out.println(s);
(1): 5, 4, 4, 7,
(2): 5, 4, 4, 7
(3): [5, 4, 4, 7]
(4): コンパイルエラー
(5): 実行時エラー
25. #ccc_ab4 https://sli.do/
JShellのコマンド:/help
jshell> /help
| /list [all|start|<name or id>] -- list the source you have typed
| /edit <name or id> -- edit a source entry referenced by name or id
| /drop <name or id> -- delete a source entry referenced by name or id
| /save [all|history|start] <file> -- Save snippet source to a file.
| /open <file> -- open a file as source input
| /vars -- list the declared variables and their values
| /methods -- list the declared methods and their signatures
| /classes -- list the declared classes
| /imports -- list the imported items
| /exit -- exit jshell
| /reset -- reset jshell
| /reload [restore] [quiet] -- reset and replay relevant history -- current or previous (restore)
| /classpath <path> -- add a path to the classpath
| /history -- history of what you have typed
| /help [<command>|<subject>] -- get information about jshell
| /set editor|start|feedback|newmode|prompt|format ... -- set jshell configuration information
| /? [<command>|<subject>] -- get information about jshell
| /! -- re-run last snippet
| /<id> -- re-run snippet by id
| /-<n> -- re-run n-th previous snippet
|
| For more information type '/help' followed by the name of command or a subject.
| For example '/help /list' or '/help intro'. Subjects:
| intro -- an introduction to the jshell tool
| shortcuts -- a description of shortcuts
26. #ccc_ab4 https://sli.do/
JShellのコマンド:
/vars, /methods, /classes, /imports, /list
●
シグネチャや値,入力したソースコードなどを表示
jshell> /list all
s1 : import java.util.*;
s2 : import java.io.*;
s3 : import java.math.*;
s4 : import java.net.*;
s5 : import java.util.concurrent.*;
s6 : import java.util.prefs.*;
s7 : import java.util.regex.*;
s8 : void printf(String format, Object... args) {
System.out.printf(format, args); }
1 : int n = 100;
2 : System.out.println(n)
e1 : this is error
27. #ccc_ab4 https://sli.do/
JShellのコマンド:
/vars, /methods, /classes, /imports, /list
●
シグネチャや値,入力したソースコードなどを表示
jshell> /list all
s1 : import java.util.*;
s2 : import java.io.*;
s3 : import java.math.*;
s4 : import java.net.*;
s5 : import java.util.concurrent.*;
s6 : import java.util.prefs.*;
s7 : import java.util.regex.*;
s8 : void printf(String format, Object... args) {
System.out.printf(format, args); }
1 : int n = 100;
2 : System.out.println(n)
e1 : this is error
Startup
Error
42. #ccc_ab4 https://sli.do/
ヒミツのコマンド:/debug(デモ)
jshell> /debug
| Debugging on
jshell> int n=0
Compiling: int n = 0;
Kind: VARIABLE -- int n=0
compileAndLoad [Unit(n)]
++setCompilationInfo() Snippet:VariableKey(n)#1-
int n=0;
package REPL;
class $JShell$1 {
public static int n;
public static Object do_it$() throws Throwable
{
int n_ = 0;
return n = n_;
}
}
-- diags: []
setStatus() Snippet:VariableKey(n)#25-int n = 0;
- status: VALID
compileAndLoad ins = [Unit(n)] -- legit = [Unit(n)]
Compiler generating class REPL.$JShell$25
compileAndLoad [Unit(n)] -- deps: [] success:
true
recordCompilation: Snippet:VariableKey(n)#25-
int n = 0; -- status VALID, unresolved []
n ==> 0
43. #ccc_ab4 https://sli.do/
ヒミツのコマンド:/debug(デモ)
jshell> /debug
| Debugging on
jshell> int n=0
Compiling: int n = 0;
Kind: VARIABLE -- int n=0
compileAndLoad [Unit(n)]
++setCompilationInfo() Snippet:VariableKey(n)#1-
int n=0;
package REPL;
class $JShell$1 {
public static int n;
public static Object do_it$() throws Throwable
{
int n_ = 0;
return n = n_;
}
}
-- diags: []
setStatus() Snippet:VariableKey(n)#25-int n = 0;
- status: VALID
compileAndLoad ins = [Unit(n)] -- legit = [Unit(n)]
Compiler generating class REPL.$JShell$25
compileAndLoad [Unit(n)] -- deps: [] success:
true
recordCompilation: Snippet:VariableKey(n)#25-
int n = 0; -- status VALID, unresolved []
n ==> 0
入力を解析し,
種類を判別
対応する
Snippet作成
Snippet
に応じた
Wrap
コンパイル
依存性解析
46. #ccc_ab4 https://sli.do/
How to Contribute
1.JShellを試す!
–https://jdk9.java.net/download/
2.MLに参加!
–バグ報告,新機能要求,フィードバックを送る
3.ソースコードを落として開発!
–パッチをMLに
–Bitbucketなどで公開
Try! Join! Feedback! Develop!
50. #ccc_ab4 https://sli.do/
JavaFX on JShell
●JavaFXをJShellから使いたいけど・・・
jshell> new javafx.stage.Stage()
| java.lang.ExceptionInInitializerError thrown
| at Window.<init> (Window.java:1380)
| at Stage.<init> (Stage.java:239)
| at Stage.<init> (Stage.java:227)
| at (#1:1)
51. #ccc_ab4 https://sli.do/
JShell for JavaFX:jfxshell
●JavaFXを動かせるJShell作った
–jfxshell
–https://bitbucket.org/bitter_fox/jfxshell
–https://bitbucket.org/bitter_fox/jfxshell/downloads/jf
xshell.jar
●JavaFXの全パッケージimport済
53. #ccc_ab4 https://sli.do/
JShell with Maven
●https://github.com/kawasima/try-artifact
java -jar try-artifact-0.1.2.jar
jshell> /resolve org.apache.commons:commons-lang3:jar:3.4
| Path /home/HOGEHOGE/.m2/repository/org/apache/commons/commons-
lang3/3.4/commons-lang3-3.4.jar added to classpath
jshell> org.apache.commons.lang3.RandomStringUtils.randomAlphanumeric(30)
| Expression value is: "8D1ysKPGhHPLGpsducw0ch0SnSfixb"
| assigned to temporary variable $1 of type String
※今後利用方法が大幅に変更になる可能性があります
56. #ccc_ab4 https://sli.do/
JShell developped by
●Engineering
–Robert Field
–Jan Lahoda
●OpenJDK Committers
–Shinya Yoshida
–YOU?
●Testing
–AndreiEremeev
●Advisors/Cheerleaders/Reviewers
–Brian Goets
–Maurizio Cimadamore
–Joe Darcy
–Paul Sandoz
–Jonathan Gibbions
–MichelTrudeau
–Sundararajan Athijegannathan
–Remi Forax
–Arun Gupta
–Mani sarkar
–Daniel Daugherty
57. #ccc_ab4 https://sli.do/
Q&A on sli.do#ccc_ab4
●他のライブラリ(jar/maven)とかどう読みこませるの
ですか
–手元のライブラリは/classpathコマンド
–mavenセントラルリポジトリからは
kawasimaさんが拡張したtry-artifact
●
ファイルを読み込ませて実行させることはできますか?
–/openコマンド
●どこかで動いているJVMに接続して、内部変数のprintとかで
きますか?
–そういう機能はない
–実装上で解決しないといけない問題が多そう
58. #ccc_ab4 https://sli.do/
Q&A on sli.do#ccc_ab4
●
今ある一時変数の一覧とか出せますか?
–/varsで変数一覧は見れるけど,一時変数だけはできない
●
アノテーションとかも使用可能ですか?
–もちろん!利用可能です!
●src配下の参照が出来るようにするおまじないとかあります
か?
–/classpath srcでどうでしょうか
●static import とかも記述可能ですか?
–もちろん!
–import static hoge.Hoge.*
59. #ccc_ab4 https://sli.do/
Q&A on sli.do#ccc_ab4
●前方参照と同じように、 import も後回しにできますか?
–できます!
–ただ,前方参照は宣言においてのみなので,
入力と同時に実行するスニペットではエラー
●script で一気にimport や変数読むとか、できますか
–できます!
–起動時の場合はstartupのスライドを参照ください
–途中では,/openコマンド
60. #ccc_ab4 https://sli.do/
Q&A on sli.do#ccc_ab4
●
補完のカスタマイズとかできますか?
–補完のプラグインの様な仕組みはないです
–ですが,OSSなので,是非フォークしてください!
●
一度作ったクラスを消す方法とかあるのか?
–/dropコマンドで削除できます
●裏でコンパイルして別の JVM で実行しているということ
は,*.java やら *.class やらの一時ファイルがこっそり作られ
てるのでしょうか?
–作られています!
–オンメモリで作っているので,HDDは汚しません!
61. #ccc_ab4 https://sli.do/
Q&A on sli.do#ccc_ab4
●Shebangとして実行する事はできますか?
–できなくはないです
–ただし,#!行も実行されてしまう(エラーになる)ため,微妙・・・
●System.exit(0); はできますか?
–是非JDK9をインストールして,jshellで実際に試してみてくだ
さい!
–「System.exit(0)」は別プロセスのJVM上で動くので,別プロセスは終了します.
JShellToolは別プロセスが終了すると,「/reload restore」を実行します
「/reload restore」はリセットして再実行なのですが,なんか怪しい動作する(バグ?)
他にもOOMEなどの再起不能な状態になり,プロセスが終了した場合も,同様な動作をします
62. #ccc_ab4 https://sli.do/
Q&A on sli.do#ccc_ab4
●JShellのリリーススケジュールとJDKのリリーススケジュールって同期してるんですか?いまからコントリビュート
したとしてJDK9でのリリースに間に合いますか?
–JDKの一部なので同期しています
–現在は以下のスケジュールです
●2016/05/26 Feature Complete
–全機能の実装が完了し,テストと共にmasterにマージ
●2016/08/11 All Tests Run
–この日までに全てのテストは一度は実行されていないとダメ
●2016/09/01 Rampdown Start
–品質向上のための期間がスタート.Phase1ではP1〜P3のバグが修正可能.
●2016/10/20 Zero Bug Bounce
–この日までに,JDK9をターゲットにするバグは修正されるか,リスケされなければならない.以降に作成される
バグは原則的に将来のリリースをターゲットとする.
●2016/12/01 Rampdown Phase 2
–Phase2ではshowstopperなバグだけが修正可能
●2017/01/26 Final Release Candidate
●2017/03/23 General Availability
–jshellはすでにmasterにマージされているため,「Feature Complete」は関係ない(と思われる)
–P4,P5のバグは9/1まで,P1〜P3のバグは10/20まで修正可能!
–つまり,今からコントリビュートしても十分に間に合います!!!あなたとJShell,今すぐクローン!