To use jshell and run the examples in this book, you need Java JDK version 9 or later installed on your computer. This appendix will help you check if you already have Java installed and guide you through installation if needed.
First, let’s see if you already have Java installed and what version it is.
On Windows:
-
Press
Windows + R, typecmd, and press Enter -
Or search for "Command Prompt" in the Start menu
On macOS:
-
Press
Cmd + Space, typeterminal, and press Enter -
Or go to Applications > Utilities > Terminal
On Linux:
-
Press
Ctrl + Alt + T -
Or search for "Terminal" in your applications
Type the following command and press Enter:
java -versionYou might see output like this:
java version "17.0.2" 2022-01-18 LTS
Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.2+8-LTS-86, mixed mode, sharing)If you see a version number 9 or higher (like 11, 17, 21), you’re all set!
If you see an error like "java is not recognized" or "command not found", you need to install Java.
If you see a version number lower than 9 (like 1.8), you should update to a newer version.
To use jshell, you specifically need the JDK (Java Development Kit), not just the JRE (Java Runtime Environment). Check by typing:
javac -versionYou should see something like:
javac 17.0.2If you get "javac is not recognized" or "command not found", you have the JRE but need the full JDK.
If you need to install or update Java, here are the recommended approaches:
-
Download the latest LTS (Long Term Support) version for your operating system
-
Run the installer and follow the setup wizard
-
Restart your terminal/command prompt
-
Test the installation using the commands from Step 2 above
OpenJDK is a free, open-source implementation of Java:
For Windows:
-
Go to https://adoptium.net/
-
Download the latest LTS version
-
Run the installer
-
Make sure "Set JAVA_HOME variable" is checked during installation
For macOS with Homebrew:
brew install openjdkFor Ubuntu/Debian Linux:
sudo apt update
sudo apt install openjdk-17-jdkFor Red Hat/CentOS/Fedora Linux:
sudo yum install java-17-openjdk-develSDKMAN is a tool for managing multiple Java versions:
-
Install SDKMAN: https://sdkman.io/install
-
Install Java:
sdk install java 17.0.2-temAfter installation, open a new terminal/command prompt and run:
java -version
javac -version
jshellThe first two commands should show version 9 or higher. The third command should start jshell with a welcome message like:
| Welcome to JShell -- Version 17.0.2
| For an introduction type: /help intro
jshell>Type /exit to quit jshell.
On Windows:
-
The Java installer should have set the PATH automatically
-
If not, you may need to add Java to your PATH manually:
-
Find where Java is installed (usually
C:\Program Files\Java\jdk-XX\bin) -
Add this to your system PATH environment variable
-
Restart your command prompt
-
On macOS/Linux:
-
Java might be installed but not in your PATH
-
Try:
which javato see if it’s found -
You may need to add Java to your PATH in your shell configuration file
If you have multiple Java versions installed:
On Windows: The last installed version usually becomes the default
On macOS: Use java_home to manage versions:
/usr/libexec/java_home -VOn Linux: Use update-alternatives:
sudo update-alternatives --config javaFor this book, we recommend:
-
Java 21 LTS - Latest long-term support version (recommended)
-
Java 17 LTS - Widely used long-term support version
-
Java 11 LTS - Older but still supported LTS version
Avoid:
-
Java 8 and earlier (no jshell support)
-
Non-LTS versions unless you have a specific need
Once Java is installed, you have several options for writing and running Java code:
jshell is perfect for learning and experimenting:
-
No need to create full programs
-
Immediate feedback on code snippets
-
Great for testing small pieces of code
-
Comes built-in with Java 9+
Start jshell by typing jshell in your terminal.
For larger projects, consider these tools:
Beginner-Friendly:
-
Visual Studio Code with Java extensions - Free, lightweight
-
IntelliJ IDEA Community Edition - Free, powerful
-
Eclipse - Free, widely used
Professional:
-
IntelliJ IDEA Ultimate - Commercial, full-featured
-
NetBeans - Free, Oracle-supported
Simple Text Editors:
-
Notepad++ (Windows) - Basic syntax highlighting
-
TextEdit (macOS) - Simple text editing
-
Gedit (Linux) - Basic code editing
For this book, jshell is sufficient, but having a good editor helps when you want to save your programs.
If you’re still having trouble:
-
Check your Java vendor’s documentation:
-
Oracle: https://docs.oracle.com/en/java/
-
Adoptium: https://adoptium.net/support/
-
-
University/School IT Support: Many institutions provide Java installation help
-
Online Communities:
-
Stack Overflow: https://stackoverflow.com/questions/tagged/java
-
Reddit: r/learnjava
-
-
Verify Installation:
-
Make sure you downloaded the JDK, not just the JRE
-
Ensure you downloaded the correct version for your operating system (32-bit vs 64-bit)
-
Try restarting your computer after installation
-
Once you have Java JDK 9 or later installed and working, you’re ready to start using jshell and following along with all the examples in this book!