Industrielle Fertigung
Industrielles Internet der Dinge | Industrielle Materialien | Gerätewartung und Reparatur | Industrielle Programmierung |
home  MfgRobots >> Industrielle Fertigung >  >> Industrial programming >> Java

Java 9 - REPL (JShell)

REPL steht für Read-Eval-Print-Loop. Mit JShell hat Java REPL-Fähigkeit. Mit REPL können wir Java-basierte Logik codieren und testen, ohne mit Javac zu kompilieren, und das Ergebnis von Berechnungen direkt sehen.

Ausführen von JShell

Öffnen Sie die Eingabeaufforderung und geben Sie jshell.

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

Anzeigen von JShell-Befehlen

Geben Sie /help ein, sobald der jshell-Befehl ausgeführt wird.

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-Befehl wird ausgeführt

Geben Sie /imports ein, sobald der jshell-Befehl ausgeführt wird, und sehen Sie sich die verwendeten Importe an.

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>

Ausführen von Berechnungen in JShell.

Versuchen Sie, einfache Berechnungen in JShell auszuführen.

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

Erstellen und Verwenden von Funktionen in JShell

Erstellen Sie eine Funktion doubled(), um int zu nehmen und ihren verdoppelten Wert zurückzugeben.

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

JShell beenden

Geben Sie /exit ein.

jshell> /exit
| Goodbye

Java

  1. Java-Operatoren
  2. Java-Kommentare
  3. Java for-each-Schleife
  4. Java-Strings
  5. Java-Schnittstelle
  6. Anonyme Java-Klasse
  7. Java-Versuch-mit-Ressourcen
  8. Java-Anmerkungen
  9. Java-Assertionen
  10. Java-Vektor