Java Reference
In-Depth Information
Chapter 4
Writing Scripts in Nashorn
In this chapter, you will learn:
How to write scripts in Nashorn
The difference between running the script in strict mode and
nonstrict mode
How to declare variables and write comments
Primitive and object data types, and how to convert values of one
data type to another data type
Operators, statements, and creating and invoking functions in
Nashorn
Different ways of creating and using objects
Variable scoping and hoisting
About built-in global objects and functions
Nashorn is a runtime implementation of the ECMAScript 5.1 specification on the
JVM. ECMAScript defines its own syntax and constructs for declaring variables, writing
statements, operators, creating and using objects, collections, iterating over collections of
data, and so on. Nashorn is 100 percent compliant with the ECMAScript 5.1, so you have
a new set of language syntax to learn when you work with Nashorn. For example, working
with objects in Nashorn is entirely different from working with objects in Java.
This chapter assumes that you have at least a beginner-level understanding of the
Java programming language. I will not explain details of the constructs and syntax offered
by Nashorn that work the same way as they work in Java. For example, I will not explain
what the assignment operator = in Nashorn does. Rather, I will simply mention that the
assignment operator = works the same in Nashorn and Java. The power of Nashorn is that
it lets you use Java libraries inside scripts. However, to use Java libraries inside Nashorn,
you must know the Nashorn syntax and constructs. This chapter gives you a brief
overview of Nashorn syntax and constructs.
 
Search WWH ::




Custom Search