1
Scripting Languages and Java
This section describes the characteristics of scripting languages and how they can be
used by Java programmers.
Scripting languages are programming languages that support the ability to write
scripts. Unlike source files for other programming languages that must be compiled
into bytecode before you run them, scripts are evaluated by a runtime environment (in
this case, by a script engine) directly.
Most scripting languages are dynamically typed. This enables you to create new
variables without declaring the variable type (the interpreter assigns the type based on
the type of the object associated with the variable), and you can reuse the same
variable for objects of different types (type conversion is performed automatically).
Scripting languages generally have simple syntax; they allow complex tasks to be
performed in relatively few steps.
Although scripting languages are usually interpreted at runtime, they can be compiled
into Java bytecode that can then be executed on the Java Virtual Machine (JVM).
Scripting languages can be faster and easier to use for certain problems, so it is
sometimes chosen by developers of Java applications. However, if you write your Java
application in a scripting language, then you lose the benefits of the Java language
(such as type safety and access to the class library).
Java Specification Request (JSR) 223: Scripting for the Java Platform addresses the
issue of integrating Java and scripting languages. It defines a standard framework and
application programming interface (API) to embed scripts in your Java applications
and access Java objects from scripts.
By embedding scripts in your Java code, you can customize and extend the Java
application. For example, you can have configuration parameters, business logic, math
expressions, and other external parts written as scripts. When developing your Java
application, you do not need to choose the scripting language. If you write your
application with the Java Scripting API (defined by JSR 223), then users can write
scripts in any language compliant with JSR 223. See The Java Scripting API.
When writing a script in a language compliant with JSR 223, you have access to the
entire standard Java library. See Using Java from Scripts.
1-1