티스토리 뷰

카테고리 없음

java9 - JShell

cozynow 2018. 9. 4. 00:08

Python 코드를 Jupyter에서 처음 했을때, 잊지 못할 기억은 REPL(Read-Evaluate-Print-Loop, 읽기-평가-출력-루프)를 제공하는 것이였다.

즉, 콘솔창에서 컴퓨터와 내가 실시간으로 채팅을 한다는 느낌이 이였는데, 드디어 java9에서 JShell 이라는 이름으로 제공한다.


jshell
##환영 인사

|  Welcome to JShell -- Version 9.0.4
|  For an introduction type: /help intro

jshell>
##텍스트 길이 체크(main 함수를 사용하려면 최소 5라인이상었이다.
jshell> "Hello, JShell".length()
$1 ==> 13

##에러도 한번 내보자
jshell> "Hello, JShell".length
|  Error:
|  cannot find symbol
|    symbol:   variable length
|  "Hello, JShell".length
|  ^--------------------^
jshell> new Random().nextInt()
$2 ==> -349162228

jshell> Random var = new Random(15);
var ==> java.util.Random@7085bdee

#.을 찍고 Tab을 누르면 해당 메소드가 노출된다.
jshell> var.
doubles(         equals(          getClass()       hashCode()
ints(            longs(           nextBoolean()    nextBytes(
nextDouble()     nextFloat()      nextGaussian()   nextInt(
nextLong()       notify()         notifyAll()      setSeed(
toString()       wait(

jshell> var.next
nextBoolean()    nextBytes(       nextDouble()     nextFloat()
nextGaussian()   nextInt(         nextLong()

jshell> var.nextInt()
$4 ==> -1159716814

jshell> Date now = new Date()
now ==> Tue Sep 04 00:30:01 KST 2018

jshell> now.
after(                before(               clone()
compareTo(            equals(               getClass()
getDate()             getDay()              getHours()
getMinutes()          getMonth()            getSeconds()
getTime()             getTimezoneOffset()   getYear()
hashCode()            notify()              notifyAll()
setDate(              setHours(             setMinutes(
setMonth(             setSeconds(           setTime(
setYear(              toGMTString()         toInstant()
toLocaleString()      toString()            wait(

jshell> now.get
getClass()            getDate()             getDay()
getHours()            getMinutes()          getMonth()
getSeconds()          getTime()             getTimezoneOffset()
getYear()

jshell> now.getDate()
$6 ==> 4

python이 AI로 인해서 급부상하는 가운데, java9에서 REPL 을 지원하겠다는 것은 Python의 독보를 막겠다는 것이 아닌가 한다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함