Some actions have an end but no beginning; some begin but do not end. It all depends upon where the observer is standing. | |
Frank Herbert - Dune |
This document is for Java programmers who want to start programming web applications in Java programming language using Java to JavaScript compiler Java2Script.
We assume that the user is familiarized with the Java programming language.
TODO: unify and simplfy all content of this section
Java2Script is an Eclipse plugin that helps you write your web applications in Java. This means that your Java codes will be automatically translated into JavaScript which can be executed in a web page. With Java2Script you can transform your java application in a pure javascript application, reusing your java codes in your Rich Internet Applications (RIA), and most of all being able of developing your RIA 100% in java code just like if you were developing another java project.
As you would know, in a common java application this is what happen: First the .java files need to be compiled by the java compiler into .class files. Only then you can execute your program: calling the "java" command the java virtual machine will load and execute the .class files.
As we will see, in a Java2Script application something similar happens. First we need the java2script translator to translate out .java files to .js files and only then we are ready to load and execute the program from javascript in a browser.
A general diagram showing the roles of the Java2Script framework compared with the Java development kit is shown in the followign figure:
For all of this, Java2Script provides with the following components:
A java to javascript code translator (compiler). that translates each .java in a java source folder to a .js file, just like the java compiler javac translate .java files into .class files.
Java language and java runtime emulation. Javascript support for loading and executing generated JavaScript in the browser, including java language emulation utilities such as ClassLoader that will lazily load JavaScript code as required, Object Oriented Programming emulation, etc
Java core utilities. An implementation of Java SE SDK library is translated, by the Java2Script compiler, to JavaScript. It is available to the Java programmer in HTML document. Currently Apache Harmony Java SE SDK implementation is used.
The following shows a more general architectonic idea involving all the components in developing Java2Script applications.
For "running" our java programs in a browser, Java2Script also supports a java language emuilation library, letting as easyly configure, load and execute our java translated code inside an html document from javascript.
Also, Java2Script comes with known java libraries like (TODO links) SWT, JUnit and other Java tools translated to JavaScript by Java2Script compiler. All this translated-tools are inside the j2slib folder and are lazily loaded by the J2S class loader when needed by J2S applications. These componenets are:
SWT. SWT version 3 support is available! You can develop your rich internet application without having to learn another GUI toolkit API. More, you can develop applications which can be distributed for both desktop (Java+SWT) and internet!
ajax - simple RPC support. Aiming to help Java developers balancing and debugging *local* and *remote* procedure calls for AJAX RIAs without knowledge of serialization and deserialization. TODO: http://blog.java2script.org/2006/10/12/java2script-introduces-simple-rpc/
JUnit. So you do not need to learn or develop another testing framework.
YUI and others. The fact is Java2Script make it easy to port existing Java frameworks to JavaScript and vice versa. With a little more imagination, you can port existing JavaScript frameworks, like YUI, to Java. That is just the mission of the project yui4java that among other things contain tools that easily let the Java programmer to access JavaScript language constructions and Java API for YUI version 2 and 3 and other known JavaScript toolkits.
Note: At this point, it is important to understand that the only mandatory componenets of Java2Script are the first two, the Java to JavaScript compiler and the java language and runtime emulation. All others are optional or replacable by other implementations. For example, as we said, the implemenation for java.lang, java.util java standar library is apache harmony but could be easily replaceable by other implementation because 99% of the java standard library provided by Java2Script is javascript code generated with Java2Script compiler and is for this that we say that the compiler is a principal component of Java2Script.