Course Introduction

Get a JDK 25 running, then meet JShell — the fastest way to try Java out.

Subsections of Course Introduction

Setup: JDK 25 & Editor

Install the JDK

You need the JDK (compiler + tools), not just a JRE. Pick any OpenJDK build: Eclipse Temurin, Amazon Corretto or Oracle OpenJDK.

# macOS
brew install --cask temurin@25

# Linux
sudo apt install openjdk-25-jdk

# Windows
winget install EclipseAdoptium.Temurin.25.JDK

# any platform, several versions side by side
sdk install java 25-tem      # sdkman.io

Verify:

java --version     # openjdk 25 …
javac --version
No javac?

You installed a JRE, or the JDK’s bin folder is not on your PATH.

Editor

  • VS Code — install Extension Pack for Java
  • IntelliJ IDEA Community — set Project SDK and language level to 25

Your first program

Hello.java:

void main() {
    IO.println("Hello, Java 25!");
}
java Hello.java      # runs directly, no compile step
New in Java 25

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.

Compiling by hand

javac Hello.java     # produces Hello.class
java Hello           # no file extension!

★ Exercises

  1. Install JDK 25 and print java --version.
  2. Write Profile.java printing three lines about yourself.
  3. Compile it with javac. What file appears, and how big is it?
  4. Remove a semicolon on purpose and read the compiler error: file, line, column.

The REPL: JShell

JShell is a Read–Eval–Print Loop shipped with the JDK. Use it whenever you want to try something out without creating a file.

jshell
jshell> 2 + 3 * 4
$1 ==> 14

jshell> var name = "World"
name ==> "World"

jshell> "Hello, " + name + "!"
$3 ==> "Hello, World!"

Semicolons are optional. Results without a variable get names like $1, which you can reuse.

Declarations work too

jshell> int square(int x) { return x * x; }
|  created method square(int)

jshell> square(12)
$5 ==> 144

jshell> record Point(int x, int y) {}
jshell> new Point(3, 4)
$7 ==> Point[x=3, y=4]

Redefining a method simply replaces it.

Commands

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:

jshell> List.of("a", "b").stream().map(String::toUpperCase).toList()
$1 ==> [A, B]

Shortcuts

  • Tab completes names: "text".to + Tab lists matching methods.
  • Shift+Tab, then v turns the expression you just typed into a variable declaration.

★ Exercises

  1. Compute how many seconds are in a year.
  2. Declare name and print a greeting with it.
  3. Define isEven(int) and test it with five values.
  4. Use Tab completion to list String methods starting with str.
  5. /save your session, /reset, then /open it again.