在Java中使用Nashorn? [英] Using Nashorn in Java?
问题描述
我正在阅读有关新Java 8功能的内容,并且知道它附带了Nashorn(Javascript引擎)。有人可以解释一下为什么我应该/应该在Java中使用Javascript引擎。它会解决哪些编程问题?任何例子
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
谢谢,
Ravi
Thanks, Ravi
推荐答案
简单,它允许您创建独立的JavaScript程序并允许在Java中嵌入JavaScript。 Java必须先编译成所谓的机器语言才能运行。 JavaScript是基于文本和解释的,并由浏览器解释。因此,能够在Java中使用这项技术是一件非常酷的事情。 JRuby是可以在Java中运行的脚本语言的另一个例子,以及它的Python等效Jython。它们都只是Java内部语言的包装器。已经可以在JVM之上运行动态语言,但目标是简化新的动态语言实现并提高其性能。
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.
我能想到的一个优势正在使用JavaScript来编写Java游戏的脚本。
One advantage I can think of is using JavaScript for the scripting of a Java game.
希望有所帮助:)
这篇关于在Java中使用Nashorn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!