SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn
Novo Motor Javascript no Java SE 8
Bruno Borges
Principal Product Manager
Oracle Latin America
Agosto, 2014
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Bruno Borges
– Principal Product
Manager, Java
Evangelist
– Oracle Latin America
– @brunoborges
– bruno.borges@oracle.c
om
Speaker
Bruno Borges
Principal Product Manager, Java Evangelist
Oracle Latin America
@brunoborges
bruno.borges@oracle.com
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Rhino (Inglês) = Nashorn (Alemão)
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn Overview
• Runtime Java baseado na linguagem Javascript
– ECMAScript 262 v5.1
• Familar para desenvolvedores de conteúdo
• Permite uso de uma série de bibliotecas e ferramentas escritas em
Javascript
– Node.JS
• Obtém todas as vantagens das tecnologias Java
Scripting for Java
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn Overview
• Forte integração com a plataforma Java
– Extensões foram adicionadas para prover acesso ao Java
• Nashorn pode ser usado no Java usando a ScriptEngine API
• Nashorn pode também ser usado pela linha de comando jjs
• Suporte para shell scripting
• Suporte completo ao JavaFX
• NetBeans 8 suporta desenvolvimento com Nashorn
Funcionalidades
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn dentro de código Java
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e Java, usando JSR 223 – ScriptEngine
import javax.script.*;
public class Main {
public static void main(String[] args) {
final ScriptEngineManager manager = new ScriptEngineManager();
final ScriptEngine engine = manager.getEngineByName("nashorn");
try {
engine.eval("print('hello world');");
} catch (final ScriptException se) {System.err.println(se); }
}
}
Exemplo 1
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e Java
String script = "var x = 10;n" +
"var y = 20;n" +
"var z = x + y;n" +
"z;n";
Object result = engine.eval(script);
int value = (Integer)result;
System.out.println(value);
Exemplo 2
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e Java
engine.put("x", 100);
engine.put("y", 200);
engine.eval("var z = x + y;");
int value = (Integer)engine.get("z");
System.out.println(value);
Exemplo 3
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e Java
var HashMap = java.util.HashMap;
var map = new HashMap();
map.put("apple", "red");
map.put("bear", "brown");
map.put("canary", "yellow");
print("A bear is " + map.get("bear"));
for (var key in map) print("key: " + key);
for each (var value in map) print("value: " + value);
Exemplo 4
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn usando Java 8 Streams API
Exemplo 5
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn linha de comando – /usr/bin/jjs
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn usando jjs
• Nashorn pode ser chamado usando a ferramenta jjs por linha de comando
• Facilita o uso de Javascript no dia-a-dia
– Tarefas rápidas
– Prototipação
– Experimento com novas features do Java
– Shell scripts
A partir da linha de comando
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn usando jjs
$> where jjs
/usr/bin/jjs
$> jjs
jjs> var x = 10;
jjs> var y = 20;
jjs> print(x + y);
30
jjs> quit();
$>
Exemplo 6
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e Javascript como Unix Shell
Scripting
Shell scripts para Unix escritos em Javascript!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Shell Scripting com Nashorn
• Por que não utilizar uma linguagem que você já está familiarizado?
• Acesso a um vasto número de bibliotecas Java
• Extensões de scripting para simplificar
– Documentos
– Templates de Strings
– Execução de comandos
– Variáveis de ambiente
Substituto mais simples para outras linguagens shell
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Schell Scripting usando Nashorn
#!/usr/bin/jjs -doe -scripting
#
var dir = __DIR__ + "photos";
var files = `ls ${dir}`.trim().split("n");
var count = 1;
for each (var file in files) {
if (file.edsWith(".jpg")) {
`mv ${dir}/${file} ${dir}/Photo${count++}.jpg`;
}
}
Exemplo 7
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e JavaFX
Aplicacoes Desktop Escritas em Javascript!
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
FX
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JavaFX 3D
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 27
Criando Formas e Materiais Primitivos
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Colocando Textura em uma Esfera
28
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Colocando Textura em uma Esfera
29
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Colocando Textura em uma Esfera
30
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
JavaFX Scene Builder
bit.ly/javafxdownload
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Your First JavaFX App for RaspberryPi
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Nashorn e JavaFX
load("fx:base.js");
load("fx:controls.js");
load("fx:graphics.js");
$STAGE.title = "Hello World!";
var button = new Button();
button.text = "Say 'Hello World'";
button.onAction = function() print("Hello World!");
var root = new StackPane();
root.children.add(button);
$STAGE.scene = new Scene(root, 300, 250);
$STAGE.show();
Exemplo 8
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Recapitulando
• Forte integração com Java
• Reuso de bibliotecas Java existente
• Pode ser usado a partir do Java
• Nova ferramenta por linha de comando jjs
• Shell Scripting
• Aplicações escritas em JavaFX
• Motor do WebView no JavaFX
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Para saber mais
• Download: java.oracle.com
• Documentação: docs.oracle.com/javase
• Treinamentos: education.oracle.com/java
• Central do Java 8: www.oracle.com/java8
• Nashorn para Usuários
– wiki.openjdk.java.net/display/Nashorn/Nashorn+Documentation
• Exemplos: blogs.oracle.com/nashorn/
• Dúvidas: nashorn-dev@openjdk.java.net
Java 8 e outros sites
youtube.com/jav
a
blogs.oracle.comjava
facebook.com/ilovejava
@java
@javaembedded
nighthacking.com
Nashorn: Novo Motor Javascript no Java SE 8

Mais conteúdo relacionado

Semelhante a Nashorn: Novo Motor Javascript no Java SE 8

Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG  - March 2014)Project Avatar (Lyon JUG & Alpes JUG  - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
David Delabassee
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
David Delabassee
 
Tweet4Beer - Beertap powered by Java goes IoT and JavaFX
Tweet4Beer - Beertap powered by Java goes IoT and JavaFXTweet4Beer - Beertap powered by Java goes IoT and JavaFX
Tweet4Beer - Beertap powered by Java goes IoT and JavaFX
Bruno Borges
 
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
David Delabassee
 
Александр Белокрылов. Java 8: Create The Future
Александр Белокрылов. Java 8: Create The FutureАлександр Белокрылов. Java 8: Create The Future
Александр Белокрылов. Java 8: Create The Future
Volha Banadyseva
 

Semelhante a Nashorn: Novo Motor Javascript no Java SE 8 (20)

Project Avatar (Lyon JUG & Alpes JUG - March 2014)
Project Avatar (Lyon JUG & Alpes JUG  - March 2014)Project Avatar (Lyon JUG & Alpes JUG  - March 2014)
Project Avatar (Lyon JUG & Alpes JUG - March 2014)
 
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur! Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
 
Jaroslav Tulach: GraalVM - z vývoje nejrychlejšího virtuálního stroje na světě
Jaroslav Tulach: GraalVM - z vývoje nejrychlejšího virtuálního stroje na světěJaroslav Tulach: GraalVM - z vývoje nejrychlejšího virtuálního stroje na světě
Jaroslav Tulach: GraalVM - z vývoje nejrychlejšího virtuálního stroje na světě
 
Server Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David DelabasseeServer Side JavaScript on the Java Platform - David Delabassee
Server Side JavaScript on the Java Platform - David Delabassee
 
Tweet4Beer - Beertap powered by Java goes IoT and JavaFX
Tweet4Beer - Beertap powered by Java goes IoT and JavaFXTweet4Beer - Beertap powered by Java goes IoT and JavaFX
Tweet4Beer - Beertap powered by Java goes IoT and JavaFX
 
Avatar 2.0
Avatar 2.0Avatar 2.0
Avatar 2.0
 
Surviving Life in the JavaScript Ecosystem
Surviving Life in the JavaScript EcosystemSurviving Life in the JavaScript Ecosystem
Surviving Life in the JavaScript Ecosystem
 
Nashorn - JavaScript on the JVM - Akhil Arora
Nashorn - JavaScript on the JVM - Akhil AroraNashorn - JavaScript on the JVM - Akhil Arora
Nashorn - JavaScript on the JVM - Akhil Arora
 
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
Server Side JavaScript on the JVM - Project Avatar - QCon London March 2014
 
Java EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c DevelopersJava EE 7 for WebLogic 12c Developers
Java EE 7 for WebLogic 12c Developers
 
2015 Java update and roadmap, JUG sevilla
2015  Java update and roadmap, JUG sevilla2015  Java update and roadmap, JUG sevilla
2015 Java update and roadmap, JUG sevilla
 
10 Building Blocks for Enterprise JavaScript
10 Building Blocks for Enterprise JavaScript10 Building Blocks for Enterprise JavaScript
10 Building Blocks for Enterprise JavaScript
 
Александр Белокрылов. Java 8: Create The Future
Александр Белокрылов. Java 8: Create The FutureАлександр Белокрылов. Java 8: Create The Future
Александр Белокрылов. Java 8: Create The Future
 
Slovenian Oracle User Group
Slovenian Oracle User GroupSlovenian Oracle User Group
Slovenian Oracle User Group
 
Session at Oredev 2016.
Session at Oredev 2016.Session at Oredev 2016.
Session at Oredev 2016.
 
Imworld.ro
Imworld.roImworld.ro
Imworld.ro
 
Java 8
Java 8Java 8
Java 8
 
What's new in Java 8
What's new in Java 8What's new in Java 8
What's new in Java 8
 
Debugging PL/SQL with Oracle SQL Developer
Debugging PL/SQL with Oracle SQL DeveloperDebugging PL/SQL with Oracle SQL Developer
Debugging PL/SQL with Oracle SQL Developer
 
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
Java Concurrency, A(nother) Peek Under the Hood [JavaOne 2016 CON1497]
 

Mais de Bruno Borges

Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na NuvemTecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Bruno Borges
 
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Bruno Borges
 
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Bruno Borges
 
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Bruno Borges
 
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFXTweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Bruno Borges
 

Mais de Bruno Borges (20)

Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
 
[Outdated] Secrets of Performance Tuning Java on Kubernetes
[Outdated] Secrets of Performance Tuning Java on Kubernetes[Outdated] Secrets of Performance Tuning Java on Kubernetes
[Outdated] Secrets of Performance Tuning Java on Kubernetes
 
From GitHub Source to GitHub Release: Free CICD Pipelines For JavaFX Apps
From GitHub Source to GitHub Release: Free CICD Pipelines For JavaFX AppsFrom GitHub Source to GitHub Release: Free CICD Pipelines For JavaFX Apps
From GitHub Source to GitHub Release: Free CICD Pipelines For JavaFX Apps
 
Making Sense of Serverless Computing
Making Sense of Serverless ComputingMaking Sense of Serverless Computing
Making Sense of Serverless Computing
 
Visual Studio Code for Java and Spring Developers
Visual Studio Code for Java and Spring DevelopersVisual Studio Code for Java and Spring Developers
Visual Studio Code for Java and Spring Developers
 
Taking Spring Apps for a Spin on Microsoft Azure Cloud
Taking Spring Apps for a Spin on Microsoft Azure CloudTaking Spring Apps for a Spin on Microsoft Azure Cloud
Taking Spring Apps for a Spin on Microsoft Azure Cloud
 
A Look Back at Enterprise Integration Patterns and Their Use into Today's Ser...
A Look Back at Enterprise Integration Patterns and Their Use into Today's Ser...A Look Back at Enterprise Integration Patterns and Their Use into Today's Ser...
A Look Back at Enterprise Integration Patterns and Their Use into Today's Ser...
 
Melhore o Desenvolvimento do Time com DevOps na Nuvem
Melhore o Desenvolvimento do Time com DevOps na NuvemMelhore o Desenvolvimento do Time com DevOps na Nuvem
Melhore o Desenvolvimento do Time com DevOps na Nuvem
 
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na NuvemTecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
 
Java EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The CloudJava EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The Cloud
 
Migrating From Applets to Java Desktop Apps in JavaFX
Migrating From Applets to Java Desktop Apps in JavaFXMigrating From Applets to Java Desktop Apps in JavaFX
Migrating From Applets to Java Desktop Apps in JavaFX
 
Servidores de Aplicação: Por quê ainda precisamos deles?
Servidores de Aplicação: Por quê ainda precisamos deles?Servidores de Aplicação: Por quê ainda precisamos deles?
Servidores de Aplicação: Por quê ainda precisamos deles?
 
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
Build and Monitor Cloud PaaS with JVM’s Nashorn JavaScripts [CON1859]
 
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
Cloud Services for Developers: What’s Inside Oracle Cloud for You? [CON1861]
 
Booting Up Spring Apps on Lightweight Cloud Services [CON10258]
Booting Up Spring Apps on Lightweight Cloud Services [CON10258]Booting Up Spring Apps on Lightweight Cloud Services [CON10258]
Booting Up Spring Apps on Lightweight Cloud Services [CON10258]
 
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
Java EE Application Servers: Containerized or Multitenant? Both! [CON7506]
 
Running Oracle WebLogic on Docker Containers [BOF7537]
Running Oracle WebLogic on Docker Containers [BOF7537]Running Oracle WebLogic on Docker Containers [BOF7537]
Running Oracle WebLogic on Docker Containers [BOF7537]
 
Lightweight Java in the Cloud
Lightweight Java in the CloudLightweight Java in the Cloud
Lightweight Java in the Cloud
 
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFXTweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
Tweet for Beer - Beertap Powered by Java Goes IoT, Cloud, and JavaFX
 
Integrando Oracle BPM com Java EE e WebSockets
Integrando Oracle BPM com Java EE e WebSocketsIntegrando Oracle BPM com Java EE e WebSockets
Integrando Oracle BPM com Java EE e WebSockets
 

Nashorn: Novo Motor Javascript no Java SE 8

  • 1. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn Novo Motor Javascript no Java SE 8 Bruno Borges Principal Product Manager Oracle Latin America Agosto, 2014
  • 2. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Bruno Borges – Principal Product Manager, Java Evangelist – Oracle Latin America – @brunoborges – bruno.borges@oracle.c om Speaker Bruno Borges Principal Product Manager, Java Evangelist Oracle Latin America @brunoborges bruno.borges@oracle.com
  • 3. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Rhino (Inglês) = Nashorn (Alemão)
  • 4. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn Overview • Runtime Java baseado na linguagem Javascript – ECMAScript 262 v5.1 • Familar para desenvolvedores de conteúdo • Permite uso de uma série de bibliotecas e ferramentas escritas em Javascript – Node.JS • Obtém todas as vantagens das tecnologias Java Scripting for Java
  • 5. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn Overview • Forte integração com a plataforma Java – Extensões foram adicionadas para prover acesso ao Java • Nashorn pode ser usado no Java usando a ScriptEngine API • Nashorn pode também ser usado pela linha de comando jjs • Suporte para shell scripting • Suporte completo ao JavaFX • NetBeans 8 suporta desenvolvimento com Nashorn Funcionalidades
  • 6. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn dentro de código Java
  • 7. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e Java, usando JSR 223 – ScriptEngine import javax.script.*; public class Main { public static void main(String[] args) { final ScriptEngineManager manager = new ScriptEngineManager(); final ScriptEngine engine = manager.getEngineByName("nashorn"); try { engine.eval("print('hello world');"); } catch (final ScriptException se) {System.err.println(se); } } } Exemplo 1
  • 8. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e Java String script = "var x = 10;n" + "var y = 20;n" + "var z = x + y;n" + "z;n"; Object result = engine.eval(script); int value = (Integer)result; System.out.println(value); Exemplo 2
  • 9. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e Java engine.put("x", 100); engine.put("y", 200); engine.eval("var z = x + y;"); int value = (Integer)engine.get("z"); System.out.println(value); Exemplo 3
  • 10. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e Java var HashMap = java.util.HashMap; var map = new HashMap(); map.put("apple", "red"); map.put("bear", "brown"); map.put("canary", "yellow"); print("A bear is " + map.get("bear")); for (var key in map) print("key: " + key); for each (var value in map) print("value: " + value); Exemplo 4
  • 11. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn usando Java 8 Streams API Exemplo 5
  • 12. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn linha de comando – /usr/bin/jjs
  • 13. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn usando jjs • Nashorn pode ser chamado usando a ferramenta jjs por linha de comando • Facilita o uso de Javascript no dia-a-dia – Tarefas rápidas – Prototipação – Experimento com novas features do Java – Shell scripts A partir da linha de comando
  • 14. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn usando jjs $> where jjs /usr/bin/jjs $> jjs jjs> var x = 10; jjs> var y = 20; jjs> print(x + y); 30 jjs> quit(); $> Exemplo 6
  • 15. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e Javascript como Unix Shell Scripting Shell scripts para Unix escritos em Javascript!
  • 16. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Shell Scripting com Nashorn • Por que não utilizar uma linguagem que você já está familiarizado? • Acesso a um vasto número de bibliotecas Java • Extensões de scripting para simplificar – Documentos – Templates de Strings – Execução de comandos – Variáveis de ambiente Substituto mais simples para outras linguagens shell
  • 17. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Schell Scripting usando Nashorn #!/usr/bin/jjs -doe -scripting # var dir = __DIR__ + "photos"; var files = `ls ${dir}`.trim().split("n"); var count = 1; for each (var file in files) { if (file.edsWith(".jpg")) { `mv ${dir}/${file} ${dir}/Photo${count++}.jpg`; } } Exemplo 7
  • 18. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e JavaFX Aplicacoes Desktop Escritas em Javascript!
  • 19. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  • 20. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | FX
  • 21. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  • 22. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  • 23. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  • 24. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
  • 25. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JavaFX 3D
  • 26. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 27 Criando Formas e Materiais Primitivos
  • 27. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Colocando Textura em uma Esfera 28
  • 28. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Colocando Textura em uma Esfera 29
  • 29. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Colocando Textura em uma Esfera 30
  • 30. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JavaFX Scene Builder bit.ly/javafxdownload
  • 31. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Your First JavaFX App for RaspberryPi
  • 32. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Nashorn e JavaFX load("fx:base.js"); load("fx:controls.js"); load("fx:graphics.js"); $STAGE.title = "Hello World!"; var button = new Button(); button.text = "Say 'Hello World'"; button.onAction = function() print("Hello World!"); var root = new StackPane(); root.children.add(button); $STAGE.scene = new Scene(root, 300, 250); $STAGE.show(); Exemplo 8
  • 33. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Recapitulando • Forte integração com Java • Reuso de bibliotecas Java existente • Pode ser usado a partir do Java • Nova ferramenta por linha de comando jjs • Shell Scripting • Aplicações escritas em JavaFX • Motor do WebView no JavaFX
  • 34. Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Para saber mais • Download: java.oracle.com • Documentação: docs.oracle.com/javase • Treinamentos: education.oracle.com/java • Central do Java 8: www.oracle.com/java8 • Nashorn para Usuários – wiki.openjdk.java.net/display/Nashorn/Nashorn+Documentation • Exemplos: blogs.oracle.com/nashorn/ • Dúvidas: nashorn-dev@openjdk.java.net Java 8 e outros sites youtube.com/jav a blogs.oracle.comjava facebook.com/ilovejava @java @javaembedded nighthacking.com