Jump to ratings and reviews
Rate this book

Harnessing Scripting in Java

Rate this book
Harnessing Scripting in Java covers the Java Script API that enables Java applications to execute scripts written in scripting languages such as Rhino JavaScript, Groovy, JRuby, Jython, etc. Java Script API was introduced in Java 6.

This book is not for learning a scripting language such as Rhino JavaScript, Groovy, etc. Rather, it is for learning how to use the Java Script API to execute scripts written in a scripting language and take advantage of the features of a scripting language while developing Java applications. The book also covers topics that enable scripting languages to take advantage of the Java programming language features and the Java class library.

Although it is not required, it would be helpful to have a basic knowledge of a scripting language before reading this book. Most of the examples in this book use Rhino JavaScript. Scripts in Groovy and Rhino JavaScript are used to compare support for Java features by these two scripting languages.

The book contains nine Each chapter introduces a new topic from the Java Script API. A chapter makes use of the material covered in the previous chapters.

Chapter 1, Getting Started, introduces readers to the Java Script API and demonstrates how to write your first Java program to execute a script written in Rhino JavaScript. It walks through the steps that are needed to download and install other scripting languages such as Groovy, Jython, and JRuby. Finally, this chapter takes a brief tour of the classes and interfaces contained in the javax.script package describing their usages and relationship with other classes.

Chapter 2, Executing Scripts, shows how to execute a script, which is stored in a file. It also demonstrates how to pass parameters from a Java application to a scripting engine and vice-versa.

Chapter 3, Advanced Parameter Passing Techniques, discusses advanced techniques and internal setups involved in passing parameters between a Java application and a scripting engine. The terms - bindings, scope, and script context are discussed in detail. Later, it explains in detail with several illustrations how bindings, scope, and script context work together in Java Script API. Each explanation is paired with a snippet of code, a complete program, or both. The chapter ends with a program that shows how to redirect outputs from a script to a file.

Chapter 4, Invoking Script Procedures, explains how to invoke top-level procedures, functions, and object-level methods written in a scripting language from a Java application. Rhino JavaScript language is used in the examples.

Chapter 5, Implementing Java Interfaces in Scripts, explains how a scripting language can provide an implementation for interfaces declared in Java, using top-level functions and object-level methods. Rhino JavaScript language is used in the examples.

Chapter 6, Using Compiled Scripts, explains how to compile scripts in intermediate form, if supported by the scripting engine, and execute them repeatedly.

Chapter 7, Using Java in Scripting Languages, explains how to use Java class library inside scripting languages. Complete programs in JavaScript and Groovy are provided. The features discussed are importing Java classes, creating Java objects, using Java overloaded methods, creating Java arrays, and implementing Java interfaces.

Chapter 8, Implementing Script Engines, discusses the steps to implement a new script engine. It explains classes and interfaces that are involved in creating a new script engine. It walks through the deployment setup that makes a script engine auto-discoverable by a script engine manager. In the process, it creates a simple script engine, which we call JKScript, which can execute an arithmetic expression.

Chapter 9, The jrunscript Command-line Shell, explains how to use the jrunscript command-line shell to execute scripts. It lists and explains the syntax and the options. Several examples are provided to illustrate the usage of the shell.

146 pages, Kindle Edition

First published July 17, 2012

About the author

Kishori Sharan

31 books4 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
0 (0%)
4 stars
0 (0%)
3 stars
0 (0%)
2 stars
0 (0%)
1 star
1 (100%)
No one has reviewed this book yet.

Can't find what you're looking for?

Get help and learn more about the design.