10 Comments
User's avatar
Yuri Iozzelli's avatar

Nice article!

It's crazy how far one can push Wasm to run all sorts of things in the browser.

There is a real potential for moving a lot of server side compute to the client.

I work on CheerpJ so I am probably biased, but I think that your "sharable snippets" idea

is already realized quite well by JavaFiddle (https://javafiddle.leaningtech.com).

As for the "Try it" button on a java docs site: that's something we have been wanting to do for a while as a showcase. If you end up building it, do post about it. And if you want to explore using CheerpJ for it, we would gladly help you out!

Brian Martin's avatar

Wow thanks so much! CheerpJ is a great product, and I think any sane person would probably use it over this demo. This is really more of a fun/silly demo. It's great that CheerpJ is licensed free for personal, and the pricing for commercial usage is pretty fair.

Jeff Martin's avatar

And here's a demo of shareable snippets in an HTML page using CheerpJ/SnapCode: https://reportmill.com/shared/learn_java.html

Brian Martin's avatar

i have updated the demo to be quite a bit faster now - it's really something!

Tim H's avatar

Nice :)

My friends and I also made a JVM that runs in the browser here: https://github.com/anematode/b-jvm

Brian Martin's avatar

This is super cool! Do you have a demo people could look at?

Jeff Martin's avatar

This is a cool technology demo - bringing us one step closer to making the browser language agnostic. It's interesting how often people tackle not just Java in the browser, but the Java compiler in the browser. I've seen prominent demos featuring that at the main web sites for TeaVM, CheerpJ and GraalVM-WASM:

TeaVM: https://teavm.org/playground.html

CheerpJ: https://javafiddle.leaningtech.com/

GraalVM: https://graalvm.github.io/graalvm-demos/web-image/javac/

My own effort is a Java IDE: http://reportmill.com/SnapCode/

The good news is that most of these can operate with only a 20-30mb download and run considerably faster than running it in a full Linux emulation. :-)

Brian Martin's avatar

hahahaha yup for sure! SnapCode looks super cool! love the animation at the beginning.

lots of great work by all of these teams, i especially like cheerpj. TeaVM is also pretty interesting, as I understand it, it transpiles the Java code to JavaScript and executes it?

Jeff Martin's avatar

The SnapCode animation at the beginning is meant to distract the user for the initial uncached launch (which can take ~5 seconds). Like mirrors outside the elevator. :-)

I especially like CheerpJ, too (it's what SnapCode uses) - it is definitely the no-compromise solution, with support for things like reflection and class loaders and almost full support for JRE API. It also runs straight from your desktop jar, so no additional compile step. And it 'pages' in the Java runtime on demand, so it only fetches what it needs (e.g. the SnapCode launch only needs 15 mb download).

TeaVM is also very cool - it turns a .jar into a .js (or .wasm or C code). It analyzes the code and only includes what is needed, so it can have a quicker/lighter startup when you don't really need dynamic features or the full runtime API. This slideshow app only downloads about 700k (gzip download): http://reportmill.com/SlideShow/teavm/ . GraalVM WebImage works this way too, but it's early days for them.

BTW, SnapCode is free, in case it helps with your use case: https://github.com/reportmill/SnapCode . :-)