Skip to content

How is this compared to Google's j2cl? #209

Open

Activity

  1. ghost closed this as completedon Oct 25, 2022
  2. BobHanson commented on Mar 13, 2023

    @BobHanson
    Collaborator

    Somehow I missed this. Apologies.

    Looking at https://github.com/google/j2cl/blob/master/docs/limitations.md

    From what I can see, j2cl probably has a lot of limitations. No reflection, for one thing. Probably no dynamic class loading, I don't see anything there about Swing support or, for that matter, any javax packages. Modal dialogs? java.io/*? I don't know where to find those.

    java2script loads classes exactly the way Java does as long as the classes have been transpiled.

    See https://github.com/BobHanson/java2script/raw/master/sources/net.sf.j2s.java.core/dist/differences.txt for general information and https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.java.core/src for included packages and classes.

  3. BobHanson commented on Mar 17, 2023

    @BobHanson
    Collaborator

    OK, after looking at j2cl, I would say this:

    I think the answer is that there are missing pieces of Java in both. The transpiling is probably along similar lines (real-time transpiling in Eclipse, subclassing org.eclipse.jdt.core.compiler.CompilationParticipant in the case of java2script, not sure how that works in j2cl -- Is there real-time transpiling going on there as well?), but java2script aims to reproduce the relatively full class loading and reflection capabilities of Java in JavaScript.

    There is a very different philosophy here. java2script is for creating fully-functional JavaScript browser-based equivalents of working stand-alone Java programs. The full GUI, whether java.awt or javax.swing. JFrame, JDialog, JOptionPane, etc.

    I get the impression that GWT and j2cl are more tuned toward using Java as a base language for the programming on the web rather than JavaScript. I could be wrong about that. But I don't see them as being used for actively generating equivalent Java stand-alone and JavaScript operation (the way Java applets were originally designed).

    So, my take on this:

    java2script allows for reflection and dynamic class loading that follows Java class loading sequencing precisely;
    java2script has java.applet.Applet and a full java.awt package, including all of the GUI components, as well as java.awt.image, color, datatransfer, dnd, event, font, geom, im, image, peer, print, and text;
    java2script has extensive java.io.File and related classes, including java.io.FileInputStream and java.io.FileOutputStream;
    java2script includes javax.annotation, javax.imageio, javax.json, javax.sound, javax.swing, and javax.xml
    java2script doesn't make extensive use of WASM, so might be slower (it would be interesting to compare these);

    java2script adds some "JavaScript-friendly" classes in the javajs package that allow for "pseudo"-modal dialogs (blocked as a GUI, event-based returns) and SwingWorker use. It manages to do this with a single thread and a lot of asynchronous timeouts.

    java2script is extensible -- anyone can add additional Java classes that don't happen to be in the collection, which is based on Java8 but has selected additional classes up through Java 11.

  4. BobHanson commented on Mar 17, 2023

    @BobHanson
    Collaborator

    From google/j2cl#183 (reply in thread)

    Optimization of java2script similarly allows for packaging just the classes used, though that is a bit more complicated due to allowances for real-time class loading and reflection in JavaScript that java2script allows for.

    Overhead: For example, https://chemapps.stolaf.edu/jme/jme_JME-core.html (about 50 user classes) transfers about 750 kb. About 180 kb of that is the non-Java JavaScript side of the operation. And about half of that is jQuery. So, not including jQuery, I would say java2script base download is around 90 kb.

    Maybe this is a accurate comparison:

    j2cl leverages Java non-GUI/non-filesystem-related classes for use in JavaScript applications that generate their own GUI and other unsupported features typical of standard JavaScript apps. j2cl is not for producing Java stand-alone programs that also run in JavaScript.

    java2script/SwingJS enables full traditional stand-alone Java GUI applications or applets to also run in JavaScript in browsers with minimal (still Java-compatible) adjustments -- only enough to allow for the more asynchronous, single-threaded nature of JavaScript, and, coincidentally, may even make the Java programs themselves run faster. Basically, java2script provides a full transpilation of Java classes into JavaScript, and SwingJS provides an "HTML5 platform look-and-feel" package that creates HTML5 counterparts for java.awt.* and javax.swing.* GUI classes as well. So from a Java programmer perspective all the GUI design is still done in Java; the browser operation is more like an additional look-and-feel.

    It really is a totally different relationship between the Java and JavaScript between the two ideas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions