If you had to name one thing that’s become synonymous with Java 9, at this point, most devs would likely point to the upcoming modular breakdown. However, in a recent interview, Java Language Architect Brian Goetz suggested that the REPL (read-eval-print loop – currently being investigated in ‘Project Kulla‘) could be the real “sleeper” feature in the next generation of the platform, and potentially “one of those ‘once you have it, you don’t know how you lived without it’ features.”

With REPL, Java developers can enjoy the same ability as Python, Ruby, and Scala developers in evaluating statements and expressions interactively. REPLs are a characteristic of most dynamic and functional languages, and there have been attempts to bring them into Java for a while – for example, with this forkable implementation.

Martijn Verburg, who recently ran a Java 9 REPL workshop for 20 London Java Community members to evaluate the current prototype, is similarly enthusiastic about its benefits. He comments to Voxxed that REPL will allow developers to perform rapid API exploration and trying out small snippets of code without having to fire up an entire IDE.

Verburg adds that, “Often I’m caught wanting to prove a simple argument in Java such as “Will type inference automatically happen in this Lambda”, it’s great that I don’t have to fire up a full IDE to prove that.”

Moreover, he believes REPL will also prove to be a useful teaching aid, noting that, “Java has a lot of ceremony round it and the REPL enables you to remove some of that when you’re teaching the language to first timers.” Having taking REPL through its paces, Verburg observed that, rather than spending their time crushing bugs, users found it to be “very, very good” from the outset.  In fact, he says, “Most of the hackers were asking for new features as opposed to battling any bugs and everyone was up and running in seconds.”

There were a few points Verburg did raise around REPL at this stage. He states that, “As Java is a statement based language, as opposed to an expression based one (expression languages marry themselves well to REPLs as you’re evaluating, well, an expression!).  This means that for those used to a REPL you find yourself doing a few odd things.”

Another “missing piece” identified by Verburg  is that of collection literals, “which isn’t a problem with the REPL per say, but more a feature lacking in Java (for now).  So Maps, Arrays and other collections aren’t first class citizens as they would be in say Groovy.”

Java trainer and author of ‘Java 8 LambdasRichard Warburton is similarly positive, telling us that, “I’m definitely convinced that adding a REPL to Java does add value. There are plenty of times when its helpful to be able to run some snippet of code.” He cites the following examples for this:

  1. Education: Unsure as to whether a snippet of code will work or not – just test it.

  2. A better debugger: introspecting the results of different snippets of code.

  3. Production interaction: having a live REPL embedded in a production server lets you run arbitrary queries and hotfix problems.

However, Warburton is unconvinced that REPL will prove to be a valuable to Java as it has been to other languages. “For a start,” he notes, “Java has an excellent toolchain, for example IDEs, which make it really easy to rapidly run compiled code. Intellij out of the box even has a code template ‘psvm’ which automatically generates you a main method.”

Moreover, he continues, “Despite improvements in Java 8 there’s a lot of verbosity in Java code which makes it harder to have 1-liner style statements that do useful things to the same extent as you can in say a Haskell, Perl or Scala.”

For Warburton, compared to the aforementioned modularity, REPL is very much a B-side feature, albeit quite a nice one to have. He concludes that, if anything, “The real sleeper features and things which need more review is the upcoming concurrency changes and the potential for a reactive stream framework.”

If you’d like to take the feature for a test drive yourself, you can download the latest version of the Java REPL (Kulla.jar – built using JDK9-ea-b59), from the AdoptOpenJDK CloudBees build farm.

 

 

What REPL will Mean for Java People

About The Author
- Editor of Voxxed.com, focusing on all things Java, JVM, cloud-y, methodical, future-fantastic, and everything in between. Got a piece of news, article or tutorial you'd like to share with your fellow Voxxians? Drop us a line at info@voxxed.com

3 Comments

  • Hildeberto Mendonça
    Reply

    The perfect REPL implementation for Java would be something similar to LightTable. Any command line tool will be a complete fail because Java is too verbose to be written in a single line.

  • Denis Falqueto
    Reply

    You know what? Oracle should adopt Groovy as the main language for the JVM and leave Java (the language) as legacy. That would be similar to what Apple is doing with Objective-C and Swift. Groovy is a hell of a language, easier, simpler, more powerful and have always had an interpreter. REPL is just a buzzword, one more for the bag of workarounds that Java is getting these days…

    I’m sad.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>