Skip to content
Volker Berlin edited this page Nov 26, 2023 · 5 revisions

Q: Can I compile with JWebAssembly Swing, AWT or Applet applications?
A: No, you need to write a GUI via the DOM API from the JWebAssembly API project. In theory, anyone can write a library that implements support for Swing and / or AWT. However, but this is not recommended.

Q: How fast is the generated JWebAssembly code?
A: It is slower than if you compiled and run the same code with Java. WebAssembly does not currently have a JIT and JWebAssembly optimizations are small. In the first tests, the code was about 50% slower. However, this is not linear and has a large variance.

Q: Why should I use JWebAssembly?
A: In the end, you can only answer this yourself. Here are a few points:

  • It is open source.
  • WebAssembly will be an important technology in the future.
  • You are already familiar with Java.
  • With a source map you can debug your Java code in the browser.
  • You can run JUnit tests and debug it in your IDE with the emulator.

Q: Can I use the JWebAssembly output of the browser?
A: Yes, you can use it with Node.js. Theoretical it is also possible to use it with a WebAssembly runtime environment with WASI and without JavaScript support. But there are some conditions.

  1. For a small wasm file and a high performance the JWebAssmebly use the Garbage Collector (GC) of the WASM runtime. This required that the WebAssembly runtime supports the optional GC feature. Without the GC feature you can only use static Java code without any allocation.
  2. It required that someone write a library for WASI access. Currently there is only a library for JavaScript and DOM access. But this should be possible in some days and you can do it step by step.

Q: Can I compile any existing Java library with JWebAssembly?
A: No, because WASM can not handle all the features of Java. There are also many open features. See the milestones on the project home page. Also, anything implemented via native code will need a replacement. The follow features will never work:

  • Threads - WASM and JavaScript are single thread.
  • Files - the browser does not can handle files
  • Swing/AWT

The follow features are samples of features which currently not work because it use native API and required community support:

  • Zip streams
  • Jpeg images
  • Reflection
  • Embedded resources
  • Adler32
  • URL handling
  • Graphics
  • Environment Variables
Clone this wiki locally