Java Reference
In-Depth Information
Chapter 1
Getting Started
In this chapter, you will learn:
What scripting in Java is
How to execute your first script from Java
How to use other scripting languages such as JRuby, Jython
from Java
javax.script API
How script engines are discovered and instantiated
What Is Scripting in Java?
Some believe that the Java Virtual Machine (JVM) can execute programs written only in
the Java programming language. However, that is not true. The JVM executes language-
neutral bytecode. It can execute programs written in any programming language, if the
program can be compiled into Java bytecode.
A scripting language is a programming language that provides you with the ability
to write scripts that are evaluated (or interpreted) by a runtime environment called a
script engine (or an interpreter). A script is a sequence of characters that is written using
the syntax of a scripting language and used as the source for a program executed by
an interpreter. The interpreter parses the scripts, produces intermediate code, which
is an internal representation of the program, and executes the intermediate code. The
interpreter stores the variables used in a script in data structures called symbol tables .
Typically, unlike in a compiled programming language, the source code (called a
script) in a scripting language is not compiled but is interpreted at runtime. However,
scripts written in some scripting languages may be compiled into Java bytecode that can
be run by the JVM.
Java 6 added scripting support to the Java platform that lets a Java application
execute scripts written in scripting languages such as Rhino JavaScript, Groovy, Jython,
JRuby, Nashorn JavaScript, and so on. Two-way communication is supported. It also
lets scripts access Java objects created by the host application. The Java runtime and a
scripting language runtime can communicate and make use of each other's features.
Support for scripting languages in Java comes through the Java Scripting API. All
classes and interfaces in the Java Scripting API are in the javax.script package.
 
Search WWH ::




Custom Search