Manufaturação industrial
Internet das coisas industrial | Materiais industriais | Manutenção e reparo de equipamentos | Programação industrial |
home  MfgRobots >> Manufaturação industrial >  >> Industrial programming >> Java

Java 9 - REPL (JShell)


REPL significa Read-Eval-Print Loop. Com JShell, java tem capacidade REPL. Usando REPL, podemos codificar e testar a lógica baseada em java sem compilar usando javac e ver o resultado dos cálculos diretamente.

Executando JShell


Abra o prompt de comando e digite jshell.
$ jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro
jshell>

Visualizando comandos do JShell


Digite /help quando o comando jshell começar a ser executado.
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

Executando o comando JShell


Digite /imports quando o comando jshell começar a ser executado e veja as importações usadas.
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>

Executando cálculos no JShell.


Tente executar cálculos simples no JShell.
jshell> 3+1
$1 ==> 4
jshell> 13%7
$2 ==> 6
jshell> $2
$2 ==> 6
jshell>

Criando e usando funções no JShell


Crie uma função doubled() para receber int e retornar seu valor dobrado.
jshell> int doubled(int i){ return i*2;}
|  created method doubled(int)
jshell> doubled(6)
$3 ==> 12
jshell>

Saindo do JShell


Digite /sair.
jshell> /exit
| Goodbye

Java

  1. Operadores Java
  2. Comentários Java
  3. Java para cada loop
  4. Strings Java
  5. Interface Java
  6. Classe anônima Java
  7. Java try-with-resources
  8. Anotações Java
  9. Asserções Java
  10. Vetor Java