Forget Dart – you can now execute Java code that displays HTML
It’s official – Dart is now obsolete for Java devs. Anton Epple tells us he has created a way to develop HTML applications with Java APIs.
We caught up with innovator Anton Epple to learn more about the new links between HTML and Java and about what he is looking forward to at the annual JavaOne conference.
JAXenter: You have created an entirely new kind of synergy between HTML and Java. Can you tell us a bit about it?
How did you create the API?
One thing I needed to avoid was the verbosity of classical JavaBean pattern and its getters and setters. I managed to do it with the @Model annotation. One just defines the Properties and their types and the whole JavaBean class is generated during compilation. Initially this may feel a bit upside-down, but people get used to it and find it productive. By the way, there has been some attempts to do this before (project Lombok comes to mind), but my solution needs no hacks. It is 100% valid Java code which gets compiled by standard Javac. The other issue was to effectively represent an HTML page and make it “live”.
You claim it’s possible to deploy these applications everywhere?
True. While the HTML/Java API has been primarily designed for NetBeans purposes, it has been created to be as “lightweight” as possible – it has as little runtime dependencies as possible – it does not depend on any other libraries (rather it exposes SPI to allow different implementations) and as such it does not require full featured Java SE to be executed – it can run on alternative Java virtual machines. Even those that support just a subset of what is now called Java.
Really. All you need is ability to execute Java code and display HTML. Of course it does not mean your current Swing based application will run everywhere, but if you create your application using the HTML/Java Maven archetype or appropriate NetBeans IDE wizard and evolve it with portability in mind, you can be sure it runs everywhere. First of all we can use JavaFX’s web view to run on desktop.
It is very useful for debugging (both Java as well as DOM structure) and for fast development of your application. Once ready you can publish the application as a standalone JAR or embed it into existing JavaFX (and thus also Swing) application. This is the way we use HTML/Java in NetBeans right now and the way I’d like to integrate HTML/Java into Eclipse.
Mobile or browser?
Android is easy. There is the Dalvik VM which can execute Java code and there is the WebView widget which can display HTML. It is “just” necessary to connect them. Well, saying “just” is a slight overstatement as it took me many sleepless nights to do it: the communication between Java and web view is asynchronous on Android and especially recursive calls get tricky. But now it is ready and thanks to HTML/Java TCK (which contains more than hundred tests) we know it behaves the same as on other systems. I thought iOS would be a challenge, but thanks to RoboVM project it was not that hard. RoboVM takes Java bytecode and converts it into LVVM assembler code – the same assembler that Objective-C targets – as a result the same, native code is produced, but one can code in Java, no need to suffer with Objective-C.
How is this possible?
When I talk about my Bck2Brwsr VM people often think it is a crazy idea. Possibly, but writing a JVM is not hard (the bigger problem is to implement libraries) and moreover I am not the only one trying that. I was contacted by Alexey Andreev who writes his own TeaVM. He was kind enough to put in necessary hooks for HTML/Java API support and as a result the minesweeper game can also be executed on his VM. I believe this is a great example how portable the HTML/Java APIs are.