Script languages -- integration with Java

Instructor's Guide


intro, paradigms, comparison, design, prototypes, architectures, summary, Q/A, literature
Scripting has become a popular way to create applications, in particular GUI-based applications and Web applications. Tcl/Tk and Python are extensively used for GUI-based applications. For Web applications, scripting may be used at the client-side, for example to customize HTML pages using Javascript, or at the server-side, for writing CGI-scripts in (for example) Perl.

Script languages

Java embedding



slide: Script languages

Most of the scripting languages, including Tcl/Tk, Perl and Python, have an extensive library for creating (server-side) Web applications. For Tcl/Tk, there exists a Netscape plugin which allows for the inclusion of so-called tclets (pronounce ticklets), applets written in Tcl/Tk, in a HTML Web page.

Scripting has clear advantages for rapid prototyping. Disadvantages of scripting concern the lack of efficiency, and the absence of compile-time checks.

Script languages may be extended using C/C++, and more recently Java. The impact of Java becomes evident when considering that there exists a Java implementation for almost each scripting language, including Tcl/Tk, Perl and Python. JPython, which is the realization of Python in Java, even offers the possibility to integrate Python classes with Java classes, and is announced as a candidate scripting platform for Java in  [JPython].

Java has also in other respects stimulated programming language research, since it appears to be an ideal platform for realising higher level programming languages.

Objects in Javascript

Originally, objects were not part of the languages Tcl/Tk and Perl. For these languages, objects have been added in an ad hoc fashion. In contrast, Python has been developed as an object-oriented language from its inception.

Javascript is a somewhat special case, since it allows for the use of built-in objects, in particular the objects defined by the Document Object Model (DOM), and its precursors. Nevertheless, due to its dynamic nature, Javascript also allows for creating user-defined objects, as indicated in the example below.


  
  <script language=Javascript> 
javascript
function object_display(msg) {
object method
return msg + ' (' + this.variable++ + ')'; } function object() {
object constructor
this.variable=0; this.display = object_display; return this; } var a = new object();
create object
document.write(a.display("a message")); document.write(a.display("another message")); </script>
The trick is to define a function that allocates the storage for instance variables, which may include references to functions. Using the keyword new, a new structure is created that may be used as an object.

Which objects are available as built-in objects depends on the environment in which Javascript programs are executed. In the example, there is an invocation of the write method for a document object. The document object, as well as other objects corresponding to the browser environment and the contents of the page loaded, are part of the Document Object Model, which is discussed in more detail in section DOM.

As an aside, Javascript has become surprisingly popular for writing dynamic HTML pages, as well as for writing server-side scripts. It is also supported by many VRML (Virtual Reality Modeling Language) browsers to define script nodes. See section DIVA. A reference implementation of Javascript is available, for embedding Javascript in C/C++ applications.