Industriële fabricage
Industrieel internet der dingen | Industriële materialen | Onderhoud en reparatie van apparatuur | Industriële programmering |
home  MfgRobots >> Industriële fabricage >  >> Industrial programming >> Java

Java 9 - REPL (JShell)

REPL staat voor Read-Eval-Print Loop. Met JShell heeft Java REPL-mogelijkheden. Met REPL kunnen we op Java gebaseerde logica coderen en testen zonder te compileren met Java en het resultaat van berekeningen direct te zien.

JShell draaien

Open de opdrachtprompt en typ jshell.

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

JShell-commando's bekijken

Typ /help zodra het jshell-commando wordt uitgevoerd.

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-opdracht uitvoeren

Typ /imports zodra het jshell-commando begint te lopen en bekijk de gebruikte 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>

Berekeningen uitvoeren in JShell.

Probeer eenvoudige berekeningen uit te voeren in JShell.

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

Functies maken en gebruiken in JShell

Maak een functie doubled() om int te nemen en de verdubbelde waarde terug te geven.

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

JShell afsluiten

Typ /exit.

jshell> /exit
| Goodbye

Java

  1. Java-operators
  2. Java-opmerkingen
  3. Java voor elke lus
  4. Java-strings
  5. Java-interface
  6. Java anonieme klasse
  7. Java proberen-met-bronnen
  8. Java-annotaties
  9. Java-beweringen
  10. Java-vector
  11. Java 9 - REPL (JShell)