Chapter 12. Scripting Java


Despite its name, the JavaScript programming language is unrelated to the Java programming language. There is a superficial syntactical resemblance because they both use syntax of the C programming language, but beneath that they are very different. Nevertheless, JavaScript has evolved and can now actually be used to script Java.[*] Java 6 recognizes this fact and ships with a bundled JavaScript interpreter so that scripting capability can easily be embedded into any Java application. Furthermore, some JavaScript interpreters (such as the one bundled with Java 6) support a feature set that allows JavaScript to interact with Java objects, setting and querying fields and invoking methods.

[*] This chapter is written for Java programmers, and many of the examples in this chapter are written partially or entirely in Java. Unless you already know how to program in Java, you should skip this chapter.

This chapter first explains how to embed a JavaScript interpreter into a Java 6 application and how to run JavaScript scripts from that application. It then turns things around and demonstrates how those scripts can script Java objects directly.

I'll return to the topic of Java scripting again in Chapter 23, which covers Java applets and the Java plug-in in the context of a web browser.




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net