산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Industrial programming >> java

자바 9 - REPL(JShell)

REPL은 Read-Eval-Print Loop의 약자입니다. JShell을 사용하면 Java에 REPL 기능이 있습니다. REPL을 사용하면 javac를 사용하여 컴파일하지 않고 Java 기반 로직을 코딩하고 테스트할 수 있으며 계산 결과를 직접 볼 수 있습니다.

JShell 실행

명령 프롬프트를 열고 jshell을 입력합니다.

$ jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro
jshell>

JShell 명령 보기

jshell 명령이 실행되기 시작하면 /help를 입력하십시오.

jshell> /help
|  Type a Java language expression, statement, or declaration.
|  Or type one of the following commands:
|  /list [<name or id>|-all|-start]
|  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 [<name or id>|-all|-start]
|  list the declared variables and their values
|  /methods [<name or id>|-all|-start]
|  list the declared methods and their signatures
|  /types [<name or id>|-all|-start]
|  list the declared types
|  /imports 
|  list the imported items

JShell 명령 실행

jshell 명령이 실행되기 시작하면 /imports를 입력하고 사용된 가져오기를 확인합니다.

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.*
jshell>

JShell에서 계산 실행

JShell에서 간단한 계산을 실행해 보세요.

jshell> 3+1
$1 ==> 4
jshell> 13%7
$2 ==> 6
jshell> $2
$2 ==> 6
jshell>

JShell에서 함수 생성 및 사용

doubled() 함수를 만들어 정수를 받아 두 배 값을 반환합니다.

jshell> int doubled(int i){ return i*2;}
|  created method doubled(int)
jshell> doubled(6)
$3 ==> 12
jshell>

JShell 종료

/exit를 입력하세요.

jshell> /exit
| Goodbye

java

  1. 자바 연산자
  2. 자바 주석
  3. 자바 for-each 루프
  4. 자바 문자열
  5. 자바 인터페이스
  6. 자바 익명 클래스
  7. 자바 리소스 사용
  8. 자바 주석
  9. 자바 어설션
  10. 자바 벡터