A shell for prototyping scientific java applications

As I wrote in a previous post, I worked on data processing and visualization for my PhD in applied physics. It sparked my work on Java, although I didn’t use Java for that particular part.

Like many researchers, I felt the overhead of creating an application with tests and a build environment, compiling and running it, was too high for some quick experiments. I needed to create a simple plot, change some parameters, plot again, and so on.

Clearly, Java has a number of benefits. For a long time, it is the number one language on Tiobe, and with 12 million developers worldwide it is easy to find a Java developer near you. Java has security as one of its corner stones. Add multi-threading, garbage collection and a vibrant ecosystem with lots of great libraries, and it is clear that Java is a very powerful platform.

There are some great scientific libraries available for Java. I’m a big supporter of SkyMind, and their deeplearning4j and nd4j API’s allow developers to create high-performant AI and numerical applications using Java. For the visualization, there are a number of tools on top of the JavaFX API’s like FXyz that can render complex 3D scenes leveraging hardware acceleration.

It would be great though, if that same Java language can also be used during research and prototyping. In that phase, things like security and scalability might be less important. But it would be a huge time and cost saver if the exact same code that you are using in research and development can also be used in production — where security and scalability do matter.

Since Java 9, Java contains JShell, which is a REPL (Read-Eval-Print Loop) for Java. This is a very important piece for doing research and prototyping. Rather then editing code, compiling, running, debugging, the REPL approach is often easier if you need immediate feedback from a single expression without having to go through the other steps

I did some experiments with extending JShell with an existing JavaFX wrapper, the Nd4j libraries, and a wrapper for the JavaFX Chart API’s.

The result is a simple shell-based application that does not require build files (no ant/maven/gradle required) and that gives immediate access to the API’s. Code snippets can be saved and restored, and also embedded in end-to-end Java applications.

It is still very rough, but this screencast shows how to create an INDArray using Nd4j and doing some basic matrix operations.

A second screencast shows how to create a simple function and plot the values for a specific range, thereby changing some parameters.

Since we are doing some work with (distributed) deep learning using Java in the Mobile Enterprise at Gluon recently (e.g. see https://github.com/gluonhq/gluon-samples/tree/master/deeplearning-linearclassifier), I plan to enhance those experiments since I found out it really saves me time to do some quick prototyping in a REPL environment.

If you think this is useful for you too, please contact me with any kind of feedback.

Originally published at johanvos.wordpress.com on April 5, 2018.