A Java REPL will soon be coming to a JDK near you. Robert Field, engineer on the Langtools team at Oracle, recently proposed the creation of a Java REPL ("Read-Evaluate-Print-Loop") project. After a vote, the project, known as Project Kulla was approved.
A REPL is essentially a scripting shell or console, such as a UNIX shell or Groovy console, that can be used to obtain quick results, for example in algorithm exploration.
The corresponding JEP for Java's REPL states that a few items are out of scope: graphical interfaces, debugger support, and IDE-like functionality. The motivation is that immediate feedback is important when learning a programming languages, and due to that omission many schools are moving away from Java. Interactive evaluation is much more efficient than traditional edit/compile/execute. As stated in the JEP:
Without the ceremony of class "public static void main(String[] args) {", short scripts written in Java become practical.
Some currently available REPL alternatives for Java are:
- Groovy Console
- Eclipse's Java Scrapbook Page
- Beanshell 2
- The Scala REPL
- Java REPL
- IntelliJ IDEA's REPL plugin (based on Java REPL)
According to its JEP, a Java REPL will be shipped with JDK 9. However, OpenJDK's JDK 9 does not list it as a feature.
Martin Odersky, founder of Scala, was recently asked what he thought about using REPL in Java. His response:
"The problem for Java here is that it is a fundamentally statement-oriented language. You write a statement, and when it executes, it has an effect. REPLs by contrast are expression-oriented: You write an expression, and the REPL shows the result, much like a calculator would. While a REPL is certainly possible for Java, it won't be as useful as for an expression-oriented language."
A REPL can become an essential part of learning a new language. It remains to be seen if its quick feedback will encourage novices to learn Java over other languages.