JShell Java 9 버전에서 도입된 새로운 개념입니다. Java에 REPL 제공 (읽기-평가-인쇄-루프) 기능. JShell을 사용하여 자바 기반 로직을 테스트할 수 있습니다. 및 표현 컴파일하지 않고. REPL은 즉각적인 피드백 루프 역할을 하며 특정 언어의 생산성에 큰 영향을 미칩니다.
1단계 :명령 프롬프트를 열고 JShell을 입력합니다. .
Microsoft Windows [Version 6.3.9600] (c) 2013 Microsoft Corporation. All rights reserved. C:\Users\User>JShell | Welcome to JShell -- Version 9.0.4 | For an introduction type: /help intro jshell>
2단계 : /help 입력 (JShell 명령을 보려면) JShell 명령 창에서 실행을 시작하면
jshell> /help | Type a Java language expression, statement, or declaration. | Or type one of the following commands: | /list [|-all|-start] | list the source you have typed | /edit | edit a source entry referenced by name or id | /drop | delete a source entry referenced by name or id | /save [-all|-history|-start] | Save snippet source to a file. | /open | open a file as source input | /vars [|-all|-start] | list the declared variables and their values | /methods [|-all|-start] | list the declared methods and their signatures | /types [|-all|-start] | list the declared types | /imports | list the imported items | /exit | exit jshell | /env [-class-path ] [-module-path ] [-add-modules < | view or change the evaluation context | /reset [-class-path ] [-module-path ] [-add-modules | reset jshell | /reload [-restore] [-quiet] [-class-path ] [-module-path | reset and replay relevant history -- current or previous ( | /history | history of what you have typed | /help [|] | get information about jshell | /set editor|start|feedback|mode|prompt|truncation|format ... | set jshell configuration information | /? [|] | get information about jshell | /! | re-run last snippet | / | re-run snippet by id | /- | re-run n-th previous snippet | | For more information type '/help' followed by the name of a | command or a subject. | For example '/help /list' or '/help intro'. | | Subjects: | | intro | an introduction to the jshell tool | shortcuts | a description of keystrokes for snippet and command comple | information access, and automatic code generation | context | the evaluation context options for /env /reload and /reset
3단계 : /imports 유형 JShell 명령 창에서 JShell에서 가져온 패키지를 가져옵니다.
jshell> /imports | import java.io.* | import java.math.* | import java.net.* | import java.nio.file.* | import java.util.* | import java.util.concurrent.* | import java.util.function.* | import java.util.prefs.* | import java.util.regex.* | import java.util.stream.*
4단계 :JShell에서 계산 수행(산술 계산 시도 JShell 사용)
jshell> 3+5 $1 ==> 8 jshell> 8-4 $2 ==> 4 jshell> 2*6 $3 ==> 12 jshell> 9%3 $4 ==> 0 jshell> 8/2 $5 ==> 4
5단계 :JShell을 종료하려면 /exi를 입력합니다. 그 .
jshell> /exit | Goodbye