Documentation Contents
Java Platform, Standard Edition Java Scripting Programmer's Guide
Contents    Previous    Next

1 Scripting Languages and Java

This chapter 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. You can find more information about JSR 223 on the Java Community Process (JCP) website at http://jcp.org/en/jsr/detail?id=223

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. For information about using the Java Scripting API, see Chapter 2.

When writing a script in a language compliant with JSR 223, you have access to the entire standard Java library. For more information about accessing Java from scripts, see Chapter 3.

Contents    Previous    Next

Oracle and/or its affiliates Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Contact Us