Maybe it’ll be part of JDK 9, maybe it won’t… but people are working hard on creating a REPL tool/environment for the Java Development Kit (JDK). More information on the code and the project is available as part of OpenJDK: project Kulla.
Some of you might not be familiar with the terminology ‘REPL’, it is short for Read Evaluate Print Loop. It is hard to explain exactly what it does, but very easy to demonstrate:
The idea is that you have a place you can enter Java and run it, without main method, class structure. You can build instances, and alter them while you type. For example you’ll able to do Swing development while you type:
Now we have a visible frame, you can drag it around, resize it etc.
Suddenly our frame has a panel, and the panel has an empty button! You can prototype, do live coding and you have instant feedback.
Now the button has text, but pressing it still does nothing…
And there we go, a final simple lambda creates a working “Hello World!”-button.
It is also possible to load a repl script from file, allowing you to share, store and run scripts. This is done using the ‘/load’ and ‘/save’ commands. You can even ‘/dump’ all the created classes in a directory.
I’m very curious how people will be using the REPL in the future, some use cases:
- (GUI) Prototyping
- Live music (like overtone)
- Coding at conferences
- Scripting
- Code golf!
If you want to try out Kulla, it took me literally 20 minutes to get up and running on my MacBook. Just follow the instructions on AdoptOpenJDK, but instead use http://hg.openjdk.java.net/kulla/dev/ as codebase. After building the JDK, go to ./langtools/repl and look at the README.