问题
I'm reading about new Java 8 features and came to know it comes with Nashorn (Javascript engine). Can someone explain me why would/should I use a Javascript engine inside Java. What programming problems it would solve ? any examples
Thanks, Ravi
回答1:
Simply, it would allow you to create standalone JavaScript programs and allow embedding JavaScript in Java. Java must be compiled into what is known as a "machine language" before it can be run. JavaScript is text-based and interpreted, and is interpreted by browsers. So being able to use this technology inside Java is a pretty cool thing. JRuby is another example of a scripting language that can run inside Java, as well as it's Python equivalent Jython. They are all just wrappers for languages to use inside Java. It is already possible to run dynamic languages on top of the JVM, but the goal is to ease new dynamic language implementations and increase their performance.
One advantage I can think of is using JavaScript for the scripting of a Java game.
Hope it helps :)
来源:https://stackoverflow.com/questions/26318856/using-nashorn-in-java