3.3    JavaScript Image Linker Toolkit

The JaSIL.Toolkit is used to translate applications developed with Java to JavaScript. It currently contains three components: JaSIL.Self does translate Java classes and creates on the fly a JavaScript runtime image, JaSIL.GUI is used for building GUIs based on the document object model (DOM) and JaSIL.Harmony is a JDK based on Apache Harmony. The runtime image created by the linker does contain only the referenced classes, fields and methods.

The JaSIL project offers the possibility to explore the usage of preemptive Java threads with JavaScript and their application in clients of Web-Applications. This includes the development of a toolkit that can be used to run such clients with JavaScript as well as Java applets.

JaSIL.Self does translate bytecode to JavaScript and does therefore use a more general approach than similar projects which use special Java front-ends. A topic is therefore the application of techniques for bytecode optimization and decompilation. In principle it should be possible to use JaSIL.Self to translate further languages with bytecode generating compilers to JavaScript.

• Motivation for the Translation of Java to JavaScript

JavaScript is a functional language available on all popular current web browsers. In this way it is one of the most available and used platforms in the world. Java is a popular object oriented programming language with strong typing, which is available on many different platforms also. Very good IDE support allows developers to efficiently create and maintain complex Java applications. Porting Java to JavaScript should make the development of more scalable web applications with smart clients, which provide a better user experience and reduce the load on the server side, simpler and more efficient.

• Java/JVM Compatibility

If performance of JavaScript is influenced, JaSIL.Self does provide options to provide less or more Java/JVM compatibility of the generated JavaScript code. Generating support for preemptive Java threads, including synchronization is therefore optional. These threads are realized in software and do not provide real hardware based multiprocessing. It is currently not intended to support dynamic class loading or client side reflection.

Applications developed with JaSIL.GUI and JaSIL.Harmony can run as Java applets. This is due to the design of JaSIL.GUI which provides a DOM bridge for JavaScript and Java applets. Depending on the Java plugin true hardware multiprocessing is possible with applets. The Java applets use the JDK provided by SUN, but this API is compatible with JaSIL.Harmony.

The applet compatibility can be used to test applications, built with the JaSIL.Toolkit, also under the conditions of the JVM implementation of a Java plugin.

• A first Application with JaSIL

This web site can be started in two different forms. Both versions have been built from the same Java source code.

• Example with Threads

Pressing the button below opens a dialog and starts a simple word counting task. It reads a file from the server, counts the words and displays the results in a table. Closing the dialog does terminate this task. Both versions - JavaScript and Java applet - use a thread with low priority for this task.

Because threads are used, the GUI remains responsive, the window can be moved or minimized to the WEB-Dock and the table is constantly updated. Java programmers can use the thread concepts they are already familiar with. Note: The system does support threads with priorities. GUI activity can delay the word counting thread.

If the task would be started without threads, as foreground activity, the GUI would be blocked and the browser would periodically show annoying message boxes, because a script is running too long. The table would be updated only when one of these message boxes is shown. Removing this behavior would require additional programming. Dividing up a complex task into smaller units can be non trivial and does increase the efforts for development and maintenance.

• Related Projects