Java REPL Tools: A Practical Comparison
Java has several solid REPL implementations available. Here are the main options and how to use them.
jshell (Official)
The best choice for most users is jshell, included in JDK 9+. It’s the official interactive shell for Java and comes with every modern Java installation.
Start it immediately:
jshell
Basic usage:
jshell> long ts = System.currentTimeMillis() / 1000;
ts ==> 1491474800
jshell> System.out.println("Current time: " + ts);
Current time: 1491474800
jshell> int[] numbers = {1, 2, 3, 4, 5};
numbers ==> int[5] { 1, 2, 3, 4, 5 }
jshell> java.util.Arrays.stream(numbers).sum()
$6 ==> 15
jshell handles most Java syntax seamlessly—you can declare variables, define methods, create classes, and execute arbitrary code without boilerplate. Tab-completion works well for method names and packages.
Useful jshell commands:
jshell> /help # Show all commands
jshell> /vars # List all variables
jshell> /methods # List all methods you've defined
jshell> /list # Show command history
jshell> /save myfile.jsh # Save session to file
jshell> /open myfile.jsh # Load a previous session
jshell> /exit # Leave jshell
Load external libraries by adding them to the classpath at startup:
jshell --class-path ".:lib/*"
java-repl (Third-party Alternative)
If you’re stuck on Java 8 or need additional features, java-repl (https://github.com/albertlatacz/java-repl) is still functional though no longer actively maintained.
wget --quiet https://github.com/albertlatacz/java-repl/releases/download/428/javarepl-428.jar -O /tmp/javarepl-428.jar
java -jar /tmp/javarepl-428.jar
It works similarly to jshell but with some differences in command syntax (:help instead of /help).
Groovy Shell (groovysh)
For a more Pythonic experience with Java interoperability, Groovy provides groovysh:
groovysh
Groovy syntax is more concise than Java:
groovy> def numbers = [1, 2, 3, 4, 5]
groovy> numbers.sum()
==> 15
groovy> "Hello ${numbers.size()} items".toString()
==> Hello 5 items
Kotlin REPL (kotlinc -interactive)
If you have Kotlin installed, its REPL is excellent:
kotlinc -J-Xms128m -J-Xmx512m
Kotlin’s syntax is clean and it integrates seamlessly with Java libraries.
Recommendation
Use jshell unless you have a specific reason not to. It’s built-in, well-maintained, and handles imports, classpath management, and complex expressions gracefully. It’s the de facto standard for Java REPL work in 2026 and beyond.
For Java 8 systems (rare nowadays), fall back to java-repl or upgrade to a modern JDK.
Practical Tips and Common Gotchas
When working with programming languages on Linux, environment management is crucial. Use version managers like asdf, pyenv, or sdkman to handle multiple language versions without system-wide conflicts. Always pin dependency versions in production to prevent unexpected breakage from upstream changes.
For build automation, modern alternatives often outperform traditional tools. Consider using just or task instead of Make for simpler task definitions. Use containerized build environments to ensure reproducibility across different development machines.
Debugging Strategies
Start with the simplest debugging approach and escalate as needed. Print statements and logging often reveal the issue faster than attaching a debugger. For complex issues, use language-specific debuggers like gdb for C and C++, jdb for Java, or dlv for Go. Always check error messages carefully before diving into code.
Quick Verification
After applying the changes described above, verify that everything works as expected. Run the relevant commands to confirm the new configuration is active. Check system logs for any errors or warnings that might indicate problems. If something does not work as expected, review the steps carefully and consult the official documentation for your specific version.
