Exploring JShell: IntelliJ, VSCode Extension, and the Traditional Terminal

Java developers have long envied the quick feedback loops available in languages like Python or JavaScript. But with the introduction of JShell in Java 9, we finally got our own interactive Read-Eval-Print Loop (REPL). JShell allows us to test code snippets on the fly, experiment with new APIs, and rapidly prototype without the overhead of setting up an entire project.

In this post, I’ll share my experiences using JShell in three different environments:

  1. IntelliJ IDEA’s JShell Console
  2. VSCode with the JShell Easy Extension
  3. The traditional JShell terminal

I’ll discuss the pros and cons of each, and hopefully, help you decide which setup might work best for your workflow.


1. JShell in IntelliJ IDEA – Seamless Integration

If you’re an IntelliJ user like me, you’ll find the JShell integration to be a game-changer. Opening the JShell console in IntelliJ is straightforward:

  • Go to Tools > JShell Console.

For detailed steps, you can refer to the official documentation.

Why IntelliJ Stands Out

  • Automatic Classpath Handling: IntelliJ automatically includes your project’s classpath. This means you can reference any dependencies or classes from your project without additional configuration.
  • Rich Editor Features: You get all the goodies—code completion, syntax highlighting, and immediate error detection.
  • Convenience: No need to switch contexts. You can test snippets right where you’re coding.

My Experience: I was working on a project that used several external libraries. With IntelliJ’s JShell console, I could test methods from these libraries instantly. No classpath headaches, no manual setup—just instant feedback.


2. VSCode + JShell Easy Extension – Real-Time Execution

For those who prefer Visual Studio Code, the JShell Easy extension brings JShell to your fingertips.

Highlights of the Extension

  • Interactive Execution: As you type, JShell executes your code. It’s like having an instant conversation with your code.
  • Lightweight Setup: While you do need to configure the --class-path if you’re using external libraries, the extension guides you through it.

Configuration Tip:

{
  "jshell.classPath": "path/to/your/classes"
}

Why It’s Cool

  • JavaScript-Like Feedback: It feels almost like coding in JavaScript, where changes reflect immediately.
  • Great for Learning: If you’re trying to grasp new Java concepts, this immediate feedback loop is invaluable.

My Experience: I loved the instant execution. It made experimenting with new Java features feel more dynamic. Configuring the classpath was a minor hurdle, but once set up, it was smooth sailing.


3. The Traditional JShell Terminal – Back to Basics

Last but not least, we have the good old JShell terminal. You can start it by simply running:

jshell

The Raw Experience

  • Manual Classpath Management: You need to add classpaths manually using the --class-path option.
  • Command Memorization: Commands like /vars, /methods, and /exit need to be remembered.
  • No IDE Assistance: You’re on your own—no code completion or error highlighting.

Why Use It?

  • Lightweight: No need for an IDE. Great for quick tests or when working on remote servers.
  • Learning Commands: It forces you to learn JShell’s command set, which can be empowering.

My Experience: Initially, this was my go-to method. But I quickly realized the limitations. Managing dependencies was cumbersome, and I missed the comforts of an IDE.


Honorable Mention: .jsh Files

Did you know you can save your JShell commands into a .jsh file? This is handy for scripting and sharing code snippets.

Example:

// File: example.jsh
System.out.println("Hello, JShell!");
int sum(int a, int b) { return a + b; }
sum(5, 7);

Run it using:

jshell example.jsh

Why .jsh Files are Cool

  • Reusable Scripts: Save and rerun your code snippets anytime.
  • Version Control: Track changes using Git or other VCS.
  • Sharing: Easily share scripts with teammates.

A Quick Introduction to JShell

For those new to JShell:

  • What is JShell? It’s Java’s REPL tool introduced in Java 9.
  • Why Use It? Experiment with code, test APIs, and prototype without creating a full project.
  • Key Commands:
  • /help – Lists all commands.
  • /vars – Shows declared variables.
  • /methods – Shows declared methods.
  • /exit – Exits JShell.

Conclusion

JShell has bridged a gap in Java development, offering a level of interactivity we’ve craved for years. Whether you choose:

  • IntelliJ IDEA for its seamless integration and zero-configuration convenience,
  • VSCode with JShell Easy Extension for its real-time execution and lightweight feel, or
  • The Traditional JShell Terminal for its simplicity and command-line power,

…each has its place in a developer’s toolkit.

My Recommendation: If you’re already using IntelliJ, stick with its JShell console for the best experience. If you prefer VSCode and don’t mind a bit of setup, the JShell extension offers a refreshing, interactive way to code. And for quick, simple tests or when working in environments without an IDE, the JShell terminal gets the job done.


Happy coding, and may your Java journey be ever more interactive!

Have you tried JShell in any other environments? Share your experiences in the comments below!


References:


Join the Conversation

If you found this post helpful, consider subscribing to my blog for more insights into Java development and other tech adventures. Let’s learn and grow together!

📚 Further Reading:

🔗 Exploring JShell: IntelliJ, VSCode, and Terminal – Dive deeper into the JShell tool, comparing how popular IDEs and command-line interfaces impact your workflow and productivity when writing Java code interactively.

🔗 The Case for Visual Studio Code in Spring Boot Java Development – If you’re intrigued by IDE choices, this article evaluates VSCode specifically for Spring Boot development, highlighting its strengths and workflow enhancements.

These links help you explore further IDE capabilities and optimize your Java development experience.

2 responses to “Exploring JShell: IntelliJ, VSCode Extension, and the Traditional Terminal”

  1. “IDE Build has expired” with JetBrains Gateway and WSL Integration – Scalable Human Blog Avatar

    […] Exploring JShell IntelliJ VSCode Extension and the Traditional Terminal – Learn how different terminal and code execution environments compare, including IntelliJ’s […]

    Like

  2. Debugging War Stories: Fixing Port Conflict from Rogue Node.js Process on Mac – Scalable Human Blog Avatar

    […] from rogue Node.js processes on Mac, these related articles will provide deeper insights: • Exploring JShell IntelliJ VSCode Extension and the Traditional Terminal – This post delves into using the traditional terminal for development tasks, which is essential […]

    Like

Leave a reply to “IDE Build has expired” with JetBrains Gateway and WSL Integration – Scalable Human Blog Cancel reply

I’m Sean

Welcome to the Scalable Human blog. Just a software engineer writing about algo trading, AI, and books. I learn in public, use AI tools extensively, and share what works. Educational purposes only – not financial advice.

Let’s connect