SlideShare a Scribd company logo
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 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
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)
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 
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
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
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 )
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)”
• „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);
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 ga, pokreni test
{{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.”
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)

• 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
„Meet the team”
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.
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.”
Ž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/
Pitanja?
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

More Related Content

PPTX
Nashorn: JavaScript that doesn’t suck (ILJUG)
PDF
Server-Side JavaScript with Nashorn
PPTX
Nashorn
PDF
Node.js, toy or power tool?
PPTX
Introduction to Napa.js
PDF
Threads Needles Stacks Heaps - Java edition
PDF
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
PDF
Node.js for beginner
Nashorn: JavaScript that doesn’t suck (ILJUG)
Server-Side JavaScript with Nashorn
Nashorn
Node.js, toy or power tool?
Introduction to Napa.js
Threads Needles Stacks Heaps - Java edition
«Что такое serverless-архитектура и как с ней жить?» Николай Марков, Aligned ...
Node.js for beginner

What's hot (20)

PPTX
Nashorn
PPTX
Introduction to node.js by jiban
PPTX
Intro to Node.js (v1)
PPTX
T4T Training day - NodeJS
PPTX
Node.js tutoria for beginner
PDF
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
PDF
Introduction to Node.js
PDF
Running JavaScript Efficiently in a Java World
PDF
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
PPTX
Intro to nodejs
PPT
Introduction to node.js aka NodeJS
PDF
Migrate to JRuby
PDF
Running Containerized Node.js Services on AWS Elastic Beanstalk
PDF
PDF
Understanding the Single Thread Event Loop
PPTX
Introduction to node.js
PDF
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
KEY
Scripting with NodeJS
PDF
Why JRuby?
PPTX
Nodejs
Nashorn
Introduction to node.js by jiban
Intro to Node.js (v1)
T4T Training day - NodeJS
Node.js tutoria for beginner
JavaScript as a Server side language (NodeJS): JSConf 2011, Dhaka
Introduction to Node.js
Running JavaScript Efficiently in a Java World
Node.js: Whats the Big Deal? Presented and JS Meetup Chicago
Intro to nodejs
Introduction to node.js aka NodeJS
Migrate to JRuby
Running Containerized Node.js Services on AWS Elastic Beanstalk
Understanding the Single Thread Event Loop
Introduction to node.js
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Scripting with NodeJS
Why JRuby?
Nodejs
Ad

Similar to Javantura 2014 - Java 8 JavaScript Nashorn (20)

PDF
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
PDF
JRuby - The Best of Java and Ruby
PDF
Lagergren jvmls-2014-final
PPTX
GOTO Night with Charles Nutter Slides
KEY
Практики применения JRuby
PDF
Jax keynote
PPTX
Java (1)
PDF
JavaScript: Past, Present, Future
PDF
Expert JavaScript Programming
PDF
Server-Side JavaScript Developement - Node.JS Quick Tour
PDF
KEY
Dcjq node.js presentation
PDF
Peru JUG Micronaut & GraalVM
PPT
JavaScript Event Loop
PPTX
Are you ready for cloud-native java JavaCro2019
PPTX
Node.js, for architects - OpenSlava 2013
PDF
Node.js #digpen presentation
PPTX
introduction to node.js
PDF
Polyglot Plugin Programming
KEY
Introduction to JRuby
Java 8: Nashorn & avatar.js di Enrico Risa al JUG Roma
JRuby - The Best of Java and Ruby
Lagergren jvmls-2014-final
GOTO Night with Charles Nutter Slides
Практики применения JRuby
Jax keynote
Java (1)
JavaScript: Past, Present, Future
Expert JavaScript Programming
Server-Side JavaScript Developement - Node.JS Quick Tour
Dcjq node.js presentation
Peru JUG Micronaut & GraalVM
JavaScript Event Loop
Are you ready for cloud-native java JavaCro2019
Node.js, for architects - OpenSlava 2013
Node.js #digpen presentation
introduction to node.js
Polyglot Plugin Programming
Introduction to JRuby
Ad

Recently uploaded (20)

PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Machine learning based COVID-19 study performance prediction
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation theory and applications.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology
Machine learning based COVID-19 study performance prediction
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Empathic Computing: Creating Shared Understanding
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation theory and applications.pdf
Spectroscopy.pptx food analysis technology
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Javantura 2014 - Java 8 JavaScript Nashorn

  • 1. Java 8 JavaScript Nashorn @MiroslavResetar, Javantura, 22.2.2014.
  • 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. 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. 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. 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. 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. 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 )
  • 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. Kako do Nashorn-a? • JSR 223 – javax.script (Java 6, 12/2006)
  • 13. QUnit • „QUnit is a powerful, easy-to-use JavaScript unit testing framework.” • Dohvati engine, učitaj QUnit, setupiraj ga, pokreni test
  • 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. Shell scripting: JJS • Curl -> Regex -> Curl -> Play Audio
  • 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
  • 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. 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. Ž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/
  • 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