자바 문법?을 좀 더 다듬어보고자 유데미에서 강의를 듣는중에 JShell이라는 것을 알게 되었다.
JShell은 자바를 마치 python같은 인터프리터 언어처럼 한줄씩 입력하고 결과를 보여주는 기능을 제공한다.
그래서 테스트를 해보았다.
C:\Users\10>jshell

jshell>
jshell> 5*8
$1 ==> 40
jshell> 5+6
$2 ==> 11
jshell> System.out.println("hello")
hello
jshell> public class Test{
...> public int a;
...> public int b;
...> public Test(int a, int b)
...> {
...> this.a = a;
...> this.b = b;
...> }
...> }
| created class Test
jshell> Test tmp = new Test(5,4);
tmp ==> Test@6a41eaa2
jshell> System.out.println(tmp.a)
5
jshell> System.out.println(tmp.b)
4
jshell> /edit Test;

jshell> Test tmp2 = new Test(1,2);
create test
tmp2 ==> Test@5622fdf
jshell> /list
1 : 5*8
2 : 5+6
3 : System.out.println("hello")
5 : Test tmp = new Test(5,4);
6 : System.out.println(tmp.a)
7 : System.out.println(tmp.b)
8 : public class Test{
public int a;
public int b;
public Test(int a, int b){
this.a = a;
this.b = b;
System.out.println("create test");
}
}
9 : Test tmp2 = new Test(1,2);
jshell> /save c:\Users\10\desktop\test.jsh

C:\Users\10>jshell
| Welcome to JShell -- Version 11.0.16.1
| For an introduction type: /help intro
jshell> /open c:\Users\10\desktop\test.jsh
hello
| Error:
| cannot find symbol
| symbol: class Test
| Test tmp = new Test(5,4);
| ^--^
| Error:
| cannot find symbol
| symbol: class Test
| Test tmp = new Test(5,4);
| ^--^
| Error:
| cannot find symbol
| symbol: variable tmp
| System.out.println(tmp.a)
| ^-^
| Error:
| cannot find symbol
| symbol: variable tmp
| System.out.println(tmp.b)
| ^-^
create test
jshell> /list
1 : 5*8
2 : 5+6
3 : System.out.println("hello")
4 : public class Test{
public int a;
public int b;
public Test(int a, int b){
this.a = a;
this.b = b;
System.out.println("create test");
}
}
5 : Test tmp2 = new Test(1,2);
jshell> /exit
| Goodbye
C:\Users\10>
간단하게 jshell에 대해 알아보았다. 한줄 한줄 결과를 확인할 필요가 있을 때 사용하면 편리할 것 같다.
여기서 테스트해본 기능 이외에도 많은 것들이 가능하기 때문에 더 자세한 것은 공식문서나 다른 블로그를 참고하자.