DukeScript - Java Everywhere Again?
Written by Mike James   
Monday, 06 October 2014

DukeScript is a Duke's Choice winner at JavaOne 2014 and it is another take on the Java dream of write once run anywhere. In this case the target is mobile and web apps. 

 

duke3

 

DukeScript isn't a new language. It is the same old Java that you already know, but it has some additional deployment and UI options. The claim is that the same app can run on the desktop, iOS, Android and in any browser. Surprisingly, with claims like this, it isn't a Java to JavaScript compiler. It works by running the byte code on an appropriate JVM and uses a set of bindings to a UI created using HTML.

The key idea is that the UI is created using HTML/CSS. In particular you can use libraries like Knockout. The idea is that you create data models in Java that have values that can be automatically bound to HTML elements. This means that your Java code doesn't work directly with the HTML via the DOM. Instead you generate models using annotations and bind them to the HTML by specifying ids for both the HTML elements and the model properties.

 

duke2

 

This is a very "hands off" approach and means you can mostly ignore the details of how your data is actually manipulated by the UI - it is very much a Model-View approach. It also means that you can change the UI simply by changing the bindings. Models can also, for example, communicate with the sever via REST or WebSockets via bindings. 

You can make use of the new technology as an add-in for NetBeans and it presents you with a complete project template ready to go. However, what you are presented with looks complex and the documentation is not good. If you know how DukeScript works then you will find the JavaDocs adequate, but if you are looking for something simple, like how do I get a connection between a text element and a string of data, you have to work quite hard. 

As with so many new Java projects, the whole thing fails because there is no easy way into the new technology. The DukeScript website looks nice and it provides you with a 1000ft overview of what you can do, but how to do it is not so easy to see. There is also a video, but it really doesn't help. When will Oracle realise that the Nighthacking video series is seriously damaging its credibility?

Assuming that you manage to see how it all works and have created an app, you can easily deploy it to any of the platforms mentioned earlier. It is interesting to learn how each of these deployments actually works.

If you deploy to Android then the Dalvik VM runs the byte code and the HTML is hosted by the WebView component. Of course, there is a container app that makes this all work. For iOS a similar approach is used, but the VM is RoboVM.

For deployment to a browser the solution used is surprising. No, a real Java VM isn't used. Instead the Bck2Brwser project's implementation of a VM in JavaScript is used. This allows the byte code to run without any plugins or special Java provisions. It is all "native" JavaScript. Of course, the web browser renders the HTML. 

For desktop deployment JavaFX and a real JVM is used. 

So do we need DukeScript?

This isn't the only attempt at get Java on the browser. The most notabie is Google's GWT, but this compiles the Java to JavaScript. What is important and different about DukeScript is that it doesn't compile to JavaScript but runs the byte code using an appropriate JVM. 

This is the old way of Java - implement the JVM and then run your code. 

dukescriptlogo

 

It might even prove successful if they manage to make it easy to get started. 

 

More Information

DukeScript

Related Articles

Java JDK 9 Proposals

Google Web Toolkit 2.5       

Google Open Sources Java To Objective-C Translator       

GWT Swept Under Open Source       

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, FacebookGoogle+ or Linkedin,  or sign up for our weekly newsletter.

 

Banner


GitHub Universe AI Announcements - Copilot And Spark
30/10/2024

GitHub has announced several improvements for developers at Universe, its annual conference. Developers will get multi-model Copilot and GitHub Spark, an AI-native tool for building applications in na [ ... ]



Prompt Engineering Techniques To Make You An Expert
18/11/2024

Introducing a GitHub repository full of hot tips and instructions on how to build the perfect prompt presented in a collection of Jupiter Notebooks.


More News

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Sunday, 05 October 2014 )