Skip to content

Commit b0e15a7

Browse files
authored
Update README.md
1 parent f6002cd commit b0e15a7

1 file changed

Lines changed: 44 additions & 42 deletions

File tree

README.md

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,46 +53,6 @@ OpenChemLib (OCL-SwingJS) https://github.com/BobHanson/OCL-SwingJS
5353

5454
See https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist and the README file in that directory.
5555

56-
# Relationship to Alternatives
57-
58-
A number of alternative methods of using Java to create JavaScript have been proposed and developed to one extent or another. The following discussion compares java2script/SwingJS to these other methods, based on my own limited understanding of them as of Dec. 2019.
59-
60-
## Google Web Toolkit ##
61-
62-
http://www.gwtproject.org/ "GWT is a development toolkit for building and optimizing complex browser-based applications. Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript."
63-
64-
I know that GWT has been successfully employed for relatively simple application conversions from Java to JavaScript. It implements a reasonably large set of JRE classes [http://www.gwtproject.org/doc/latest/RefJreEmulation.html], but not really a sufficiently large number of classes to support developed Java projects. For example, Class.forName() is missing, so that means no dynamic class loading; File, FileInputStream, and FileOutputStream are missing, meaning no standard file i/o. Most significantly, java.awt and javax.swing are missing. This means that whatever user interface is built must be built from scratch with JavaScript only in mind.
65-
66-
In contrast, java2script/SwingJS supports an HTML5-based "platform look and feel" (plaf) that leverages all the native features of HTML5 to match the Java AWT and Swing UI. For example, virtually all the Swing and AWT frame, window, panel, dialog, border, and layout classes have been implemented. There are no additional specialized classes that a developer needs to add to his or her project. Rather than using a working Java program as the basis for a JavaScript-specific application, as in GWT, java2script/SwingJS allows for parallel co-production of distributable Java and JavaScript _equivalent_ applications.
67-
68-
## TeaVM ##
69-
70-
http://teavm.org/ "TeaVM is an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. Its close relative is the well-known GWT. The main difference is that TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM successfully compiles Kotlin and Scala."
71-
72-
I can only find a very few examples of TeaVM use. But from what I can see, TeaVM is still at "concept" stage. It appears that they are hand writing "pseudo" Java as they go. For example, we see at
73-
74-
https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib
75-
76-
that "java.awt" contains three classes: TColor, TDimension, and TPoint. TColor has exactly four methods: getRed(), getGreen(), getBlue(), and getAlpha(). It appears to me that the developer has hand-written a decent collection of 800 files as org.teavm.classlib.java. Apparently, the idea is that you would take your Java project and swap in these pseudo-java classes. But this is not scalable. One can't expect a 100,000-line Java program to be retooled or limited to this small hand-crafted set of classes.
77-
78-
In the author's own words, "There are Java APIs that are impossible to implement without generating inefficient JavaScript. Some of these APIs are: reflection, resources, class loaders, and JNI. TeaVM restricts usage of these APIs. Generally, you’ll have to manually rewrite your code to fit into TeaVM constraints." OK, but java2script/SwingJS implements reflection, does just-in-time class loading, uses property files and resource bundles, loads images, and much more. There are only minimal constraints that require modifying Java code. Yes, modal dialogs and Thread.sleep() do require refactoring a bit, but we have had no problem with this on over 500,000 lines of code in multiple projects. So it doesn't seem to be a major impediment.
79-
80-
## CheerpJ ##
81-
82-
https://www.leaningtech.com/cheerpj/ "CheerpJ converts Java applications or libraries into JavaScript. Works on bytecode, does not require access to the source code. Compatible with 100% of Java including reflection and dynamic classes. Existing Java archives can be converted to Web applications effortlessly"
83-
84-
This sounds terrific. And truly it is. I am very impressed! Basically run the Java byte code in JavaScript. The Java Reporter demonstration at https://www.leaningtech.com/cheerpj/demos/ crashed both Firefox and Chrome for me, so I cannot really evaluate what I see here. But I have played with the JFiddle at https://javafiddle.leaningtech.com/, and it is pretty amazing.
85-
86-
The primary differences between java2script/SwingJS and CheerpJ, to the best of my knowledge, include:
87-
88-
- fast start-up time. SwingJS applications generally start within a second or two, sometimes within 100 ms
89-
- small downloads, anywhere from about 800K for a small non-GUI program to 10 MB for a full-blown Swing application (JSmol)
90-
- class-level just-in-time dynamic class loading; no need to retrieve entire JAR files just for a few methods
91-
- leveraging features of HTML5 and modern JavaScript rather than just painting a canvas the way Java does natively
92-
- delivering an easily interpretable and debuggable JavaScript translation of Java classes, with little or no obscurification (unless that is desired)
93-
- well-designed JavaScript-friendly Java core classes that leverage the considerable power of JavaScript
94-
- open source and completely extensible
95-
9656
# History - 2019-
9757

9858
SwingJS is now more than just "Swing"+JavaScript. AWT applets and applications are now supported. A test suite of over 500 AWT applets has been used to refine the AWT runtime classes with great success. Many thanks to Karsten Blankenagel (University of Wuppertal) for access to this source code set.
@@ -123,6 +83,10 @@ Jmol-SwingJS https://github.com/BobHanson/Jmol-SwingJS (code only)
12383

12484
Varna https://github.com/BobHanson/VARNA and https://chemapps.stolaf.edu/swingjs/varna
12585

86+
PhET, Falstad, and other tests https://chemapps.stolaf.edu/swingjs/phet/site/swingjs/examples (These are all early "first-generation" SwingJS tests converting AWT to Swing in Java, then transpiling.)
87+
88+
JSmol: https://chemapps.stolaf.edu/jmol/jsmol Non-AWT, Non-Swing version. (Our initial application of Java2Script technology, continued as "legacy Jmol" at https://sourceforge.net/projects/jmol. All continued Java development is based on work at Jmol-SwingJS even though this is still not a Swing application.)
89+
12690
# History - 2010-2016
12791

12892
https://github.com/java2script/java2script (stable master)
@@ -135,8 +99,7 @@ only known widely-available java2sript application.
13599
Developed further in 2016 by zhou Renjian, Udo Borkowski, Bob Hanson, Andrew Raduege, Nadia El Mouldi, and Paul Falstad (http://www.falstad.com) for the first round of post-JSmol application of java2script, adding javax.swing classes and
136100
dubbed "SwingJS". Used by Bob Hanson during 11/2016 for conversion of the PhET gas applications applets.
137101

138-
Version 2 allowed extensive development of JavaScript versions of Java applets, including JSmol, Falstad applets, and PhET applets.
139-
However, this version did not produce "fully qualified" method signatures, resulting in error-prone and performance-reducing run-time binding of methods. Java class loading procedures were not consistent with the sequence of events used by the Java class loader, and parameter and array typing was minimal. Thus, while functional, Version 2 was not fully generalizable and required extensive reworking of Java code to be "java2script compliant."
102+
Version 2 allowed extensive development of JavaScript versions of Java applets, including JSmol, Falstad applets, and PhET applets. However, this version did not produce "fully qualified" method signatures, resulting in error-prone and performance-reducing run-time binding of methods. Java class loading procedures were not consistent with the sequence of events used by the Java class loader, and parameter and array typing was minimal. Thus, while functional, Version 2 was not fully generalizable and required extensive reworking of Java code to be "java2script compliant."
140103

141104
Synchronized with https://github.com/BobHanson/java2script as the stable master version in 2018.
142105

@@ -156,3 +119,42 @@ Initially developed by Zhou Renjian (aka "Josson Smith", zhourenjian@gmail.com,
156119
Soheil Hassas Yeganeh (soheil.h.y@gmail.com, 2006), Sal Ferro (svferro@gmail.com, 2006), Sebastian Gurin (sgurin@softpoint.org, 2008),
157120
and others. The project was a "proof-in-concept" that saw limited actual application.
158121

122+
# Relationship to Alternatives
123+
124+
A number of alternative methods of using Java to create JavaScript have been proposed and developed to one extent or another. The following discussion compares java2script/SwingJS to these other methods, based on my own limited understanding of them as of Dec. 2019.
125+
126+
## Google Web Toolkit ##
127+
128+
http://www.gwtproject.org/ "GWT is a development toolkit for building and optimizing complex browser-based applications. Its goal is to enable productive development of high-performance web applications without the developer having to be an expert in browser quirks, XMLHttpRequest, and JavaScript."
129+
130+
I know that GWT has been successfully employed for relatively simple application conversions from Java to JavaScript. It implements a reasonably large set of JRE classes [http://www.gwtproject.org/doc/latest/RefJreEmulation.html], but not really a sufficiently large number of classes to support developed Java projects. For example, Class.forName() is missing, so that means no dynamic class loading; File, FileInputStream, and FileOutputStream are missing, meaning no standard file i/o. Most significantly, java.awt and javax.swing are missing. This means that whatever user interface is built must be built from scratch with JavaScript only in mind.
131+
132+
In contrast, java2script/SwingJS supports an HTML5-based "platform look and feel" (plaf) that leverages all the native features of HTML5 to match the Java AWT and Swing UI. For example, virtually all the Swing and AWT frame, window, panel, dialog, border, and layout classes have been implemented. There are no additional specialized classes that a developer needs to add to his or her project. Rather than using a working Java program as the basis for a JavaScript-specific application, as in GWT, java2script/SwingJS allows for parallel co-production of distributable Java and JavaScript _equivalent_ applications.
133+
134+
## TeaVM ##
135+
136+
http://teavm.org/ "TeaVM is an ahead-of-time compiler for Java bytecode that emits JavaScript and WebAssembly that runs in a browser. Its close relative is the well-known GWT. The main difference is that TeaVM does not require source code, only compiled class files. Moreover, the source code is not required to be Java, so TeaVM successfully compiles Kotlin and Scala."
137+
138+
I can only find a very few examples of TeaVM use. But from what I can see, TeaVM is still at "concept" stage. It appears that they are hand writing "pseudo" Java as they go. For example, we see at
139+
140+
https://github.com/konsoletyper/teavm/tree/master/classlib/src/main/java/org/teavm/classlib
141+
142+
that "java.awt" contains three classes: TColor, TDimension, and TPoint. TColor has exactly four methods: getRed(), getGreen(), getBlue(), and getAlpha(). It appears to me that the developer has hand-written a decent collection of 800 files as org.teavm.classlib.java. Apparently, the idea is that you would take your Java project and swap in these pseudo-java classes. But this is not scalable. One can't expect a 100,000-line Java program to be retooled or limited to this small hand-crafted set of classes.
143+
144+
In the author's own words, "There are Java APIs that are impossible to implement without generating inefficient JavaScript. Some of these APIs are: reflection, resources, class loaders, and JNI. TeaVM restricts usage of these APIs. Generally, you’ll have to manually rewrite your code to fit into TeaVM constraints." OK, but java2script/SwingJS implements reflection, does just-in-time class loading, uses property files and resource bundles, loads images, and much more. There are only minimal constraints that require modifying Java code. Yes, modal dialogs and Thread.sleep() do require refactoring a bit, but we have had no problem with this on over 500,000 lines of code in multiple projects. So it doesn't seem to be a major impediment.
145+
146+
## CheerpJ ##
147+
148+
https://www.leaningtech.com/cheerpj/ "CheerpJ converts Java applications or libraries into JavaScript. Works on bytecode, does not require access to the source code. Compatible with 100% of Java including reflection and dynamic classes. Existing Java archives can be converted to Web applications effortlessly"
149+
150+
This sounds terrific. And truly it is. I am very impressed! Basically run the Java byte code in JavaScript. The Java Reporter demonstration at https://www.leaningtech.com/cheerpj/demos/ crashed both Firefox and Chrome for me, so I cannot really evaluate what I see here. But I have played with the JFiddle at https://javafiddle.leaningtech.com/, and it is pretty amazing.
151+
152+
The primary differences between java2script/SwingJS and CheerpJ, to the best of my knowledge, include:
153+
154+
- fast start-up time. SwingJS applications generally start within a second or two, sometimes within 100 ms
155+
- small downloads, anywhere from about 800K for a small non-GUI program to 10 MB for a full-blown Swing application (JSmol)
156+
- class-level just-in-time dynamic class loading; no need to retrieve entire JAR files just for a few methods
157+
- leveraging features of HTML5 and modern JavaScript rather than just painting a canvas the way Java does natively
158+
- delivering an easily interpretable and debuggable JavaScript translation of Java classes, with little or no obscurification (unless that is desired)
159+
- well-designed JavaScript-friendly Java core classes that leverage the considerable power of JavaScript
160+
- open source and completely extensible

0 commit comments

Comments
 (0)