Course Introduction
Get a JDK 25 running, then meet JShell — the fastest way to try Java out.
Get a JDK 25 running, then meet JShell — the fastest way to try Java out.
You need the JDK (compiler + tools), not just a JRE. Pick any OpenJDK build: Eclipse Temurin, Amazon Corretto or Oracle OpenJDK.
Verify:
You installed a JRE, or the JDK’s bin folder is not on your PATH.
Hello.java:
Compact source files and instance main methods (JEP 512) drop the class shell,
static, and String[] args. The always-available java.lang.IO class provides
println, print and readln. The classic form still works — see
chapter 7.
java --version.Profile.java printing three lines about yourself.javac. What file appears, and how big is it?JShell is a Read–Eval–Print Loop shipped with the JDK. Use it whenever you want to try something out without creating a file.
Semicolons are optional. Results without a variable get names like $1, which you can reuse.
Redefining a method simply replaces it.
| Command | Does |
|---|---|
/help |
list all commands |
/vars /methods /types |
what you have defined |
/list |
code so far, numbered |
/edit 3 |
edit snippet 3 |
/save f.jsh /open f.jsh |
save / load a session |
/imports |
the automatic imports |
/reset |
start over |
/exit |
quit |
java.util, java.io, java.math, java.net, java.util.stream and
java.util.function are imported for you:
"text".to + Tab lists matching methods.v turns the expression you just typed into a variable declaration.name and print a greeting with it.isEven(int) and test it with five values.String methods starting with str./save your session, /reset, then /open it again.