Thursday, July 27, 2006

Intro to java scripting API

The scripting API consists of interfaces and classes that define Java Scripting Engines and provides a framework for their use in Java applications. This API is intended for use by application programmers who wish to execute programs written in scripting languages in their Java applications. The scripting language programs are usually provided by the end-users of the applications.

Mustang comes with a jrunscript tool. jrunscript is a command line script shell. jrunscript supports both an interactive (read-eval-print) mode and a batch (-f option) mode of script execution. This is a scripting language independent shell. By default, JavaScript is the language used, but the -l option can be used to specify a different language.
For more details visit here

This is very useful for exploratory programming ie. if we want to work with any new api then we can directly write the code in javascript and test out that api using the jrunscript.

For example i created a js file called test.js which contained the following code

var testList = new java.util.ArrayList();
var i = 1;
testList.add(i);
print("testList = " + testList);
i = testList.get(0);
print("i = " + i);

then i go to the command prompt and type
>jrunscript test.js

The Output is:
testList = [1.0]
i = 1.0

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home