Java 8 JavaScript Nashorn
@MiroslavResetar, Javantura, 22.2.2014.
JavaScript na Javanturi?
•

Alfresco
•

•

CMIS API implementiran u JavaScriptu

Neo4J
•

„people love to use Neo4j from N...
Popularnost JavaScripta?
• Redmonk, siječanj 2014.
• Github repozitoriji vs Stack Overflow

1.

JavaScript (+1)

2. Java (...
JVM polyglot programming
• Clojure, Scala, JRuby, Jython, Rhino (JavaScript)
• Zašto JVM?
• Jer je zakon
• GC, Threads, Ja...
Rhino
• Rhino – Java implementacija JavaScripta
• 1997 – Netscape započeo rad na Rhino-u

• 1998 – Rhino je predan Mozilli...
Problemi sa Rhino-om
• Rhino je veoma spor u usporedbi sa ostalim JavaScript
engine-ima (browserima)
• Velika potrošnja me...
Nashorn
• Potpuno nova implementacija JavaScripta
• Kompajlirani kod a ne interpreter

• Dolazi standardno sa JDK-om 8
• 5...
Rhino vs Nashorn
Nashorn vs Groovy
InvokeDynamic
• A First Taste of InvokeDynamic
• „... static nature of Java is in the language itself (and not the
JVM)”
•...
Kako do Nashorn-a?
• JSR 223 – javax.script (Java 6, 12/2006)
Nashorn smoke test
QUnit
• „QUnit is a powerful, easy-to-use JavaScript unit testing

framework.”

• Dohvati engine, učitaj QUnit, setupiraj ...
{{Mustache}}
• „Mustache is a logic-less template syntax. It can be used for HTML,

config files, source code - anything. ...
Shell scripting: JJS
• Curl -> Regex -> Curl -> Play Audio
Što Nashor nije
• Nije DOM/CSS okruženje
• Ne podržava korištenje biblioteka kao što su JQuery, Dojo,
Ext. (out-of-the-box...
„Meet the team”
Jim Laskey odgovara
• Postoji li debugger za Nashorn?
• Debuger je integriran u Netbeans 8 (beta).
• Eclipse još nema debu...
Project Avatar i Avatar.js
• „Avatar.js is a project to bring the node programming model,
APIs and module ecosystem to the...
Želite znati više?
• Jim Laskey - Nashorn, JavaScript for the JVM
• http://www.youtube.com/watch?v=I6eo2KPsk7U

• Attila S...
Pitanja?
Reference
• Kod - https://github.com/mresetar/javantura-nashorn
• JUnit benchmarks - http://labs.carrotsearch.com/junitben...
Upcoming SlideShare
Loading in …5
×

Javantura 2014 - Java 8 JavaScript Nashorn

1,806 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,806
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
18
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Javantura 2014 - Java 8 JavaScript Nashorn

  1. 1. Java 8 JavaScript Nashorn @MiroslavResetar, Javantura, 22.2.2014.
  2. 2. JavaScript na Javanturi? • Alfresco • • CMIS API implementiran u JavaScriptu Neo4J • „people love to use Neo4j from Node.js and the browser” • Sencha Touch, Ext.Js, D3.js, • JavaFX • • Dart • • „writing JavaFX scripts in Nashorn is very easy” transkompajlira se u JavaScript! Vert.x • JavaScript API
  3. 3. Popularnost JavaScripta? • Redmonk, siječanj 2014. • Github repozitoriji vs Stack Overflow 1. JavaScript (+1) 2. Java (-1) 3. PHP 4. C# (+2) 5. Python (-1)
  4. 4. JVM polyglot programming • Clojure, Scala, JRuby, Jython, Rhino (JavaScript) • Zašto JVM? • Jer je zakon • GC, Threads, Java API, ogromna količina biblioteka, puno platformi • JVM – najbolji dio Jave 
  5. 5. Rhino • Rhino – Java implementacija JavaScripta • 1997 – Netscape započeo rad na Rhino-u • 1998 – Rhino je predan Mozilli i open source-an • 2006 – Java 6 pakira Rhino kao standardnu implementaciju skriptnog jezika
  6. 6. Problemi sa Rhino-om • Rhino je veoma spor u usporedbi sa ostalim JavaScript engine-ima (browserima) • Velika potrošnja memorije • Veoma stari codebase (iz Java 1.1 vremena) • Kako bi se „popravio” bio je potreban veliki rewrite, odluka je bila krenuti iz početka
  7. 7. Nashorn • Potpuno nova implementacija JavaScripta • Kompajlirani kod a ne interpreter • Dolazi standardno sa JDK-om 8 • 5 x manji footprint • 20 x bolje performanse (otprilike )
  8. 8. Rhino vs Nashorn
  9. 9. Nashorn vs Groovy
  10. 10. InvokeDynamic • A First Taste of InvokeDynamic • „... static nature of Java is in the language itself (and not the JVM)” • „Every invocation has to be called against a known type.” • „we must generate hundreds of tiny methods into tiny classes with everything neatly tied up in a bow so the JVM will pretty please perform that invocation for us as quickly as possible” • „java.lang.OutOfMemoryError: PermGen space” • „InvokeDynamic ... the ability to make a dynamic call that the JVM not only recognizes, but also optimizes in the same way it optimizes plain old static-typed calls.” • MethodHandle happyTimeHandle = MethodHandles.findVirtual(Happy.class, "happyTime", void.class, String.class);
  11. 11. Kako do Nashorn-a? • JSR 223 – javax.script (Java 6, 12/2006)
  12. 12. Nashorn smoke test
  13. 13. QUnit • „QUnit is a powerful, easy-to-use JavaScript unit testing framework.” • Dohvati engine, učitaj QUnit, setupiraj ga, pokreni test
  14. 14. {{Mustache}} • „Mustache is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object.”
  15. 15. Shell scripting: JJS • Curl -> Regex -> Curl -> Play Audio
  16. 16. Što Nashor nije • Nije DOM/CSS okruženje • Ne podržava korištenje biblioteka kao što su JQuery, Dojo, Ext. (out-of-the-box) • Nema browser plugin API • Nije embeddable u browser • Ne podržava ne standardizirane feature JavaScripta • Nije multithreaded safe • generalno nije problem ukoliko se izbjegava globalni scope • loadWithNewGlobal creates a fresh global before loading the script
  17. 17. „Meet the team”
  18. 18. Jim Laskey odgovara • Postoji li debugger za Nashorn? • Debuger je integriran u Netbeans 8 (beta). • Eclipse još nema debugger za Nashorn. • Da li radite još na poboljšanju performansi? • Da. Veliki trud se ulaže kako bi performanse bile još bolje sa verzijom 8u20. Verzija se očekuje na jesen. Za sada su brojke obećavajuće. • Što se događa sa Node.jar projektom? • Preimenovan u Avatar.js. StrongLoop ulažu ogroman trud ne bi li podržali projekt. Trenutne performanse su bolje od Node.js. Bit će još bolje sa verzijom 8u20.
  19. 19. Project Avatar i Avatar.js • „Avatar.js is a project to bring the node programming model, APIs and module ecosystem to the Java platform.” • „Avatar.js applications are both asynchronous and singlethreaded (exactly as in Node.js).” • „Avatar - JavaScript services layer...rich client side framework that assumes very minor JavaScript knowledge.”
  20. 20. Želite znati više? • Jim Laskey - Nashorn, JavaScript for the JVM • http://www.youtube.com/watch?v=I6eo2KPsk7U • Attila Szegedi - The Curious Case of JavaScript on the JVM (http://vimeo.com/78890890) • Oracle Java Magazine Jan/Feb 2014 – Oracle Nashorn • http://julien.ponge.org/blog/nashorn-article-in-oraclejavamagazine-jan-feb-2014/
  21. 21. Pitanja?
  22. 22. Reference • Kod - https://github.com/mresetar/javantura-nashorn • JUnit benchmarks - http://labs.carrotsearch.com/junitbenchmarks-tutorial.html • Nashorn JavaFx debugger https://github.com/wickund/nashornexamples/ • Spring boot sample project • Rhino QUnit setup • VoiceRSS service

×