Skip to content
wannacode

Getting your computer ready

Problem

What you need

To write and run programs, you need two things:

  1. The JDK (Java Development Kit): the javac compiler, the JVM that runs programs, and the standard libraries.
  2. An editor for your code. You could write a program in Notepad, but an editor for programmers colors the code, gives you hints and shows errors as you type.

If you do not have a computer you can install programs on yet, an online editor is enough for the first few days: search the web for online Java compiler. The tasks from the "Language basics" module work there too. For the bigger programs later on, you will need an installation.

The idea

Install JDK 21

We use Java 21. This is a long-term support version (LTS): it gets fixes for years. Several organizations make a JDK. We recommend the free Eclipse Temurin from adoptium.net.

  • Windows and macOS: download the installer for Temurin 21 and run it. On Windows, leave on the option that adds Java to the PATH.
  • Linux: install the package from your system. On Ubuntu, that is:
Terminal
sudo apt install openjdk-21-jdk

If you already have a newer version (Java 25, for example), it works too: everything in the course runs on it.

Check. Open a new terminal (on Windows: PowerShell or Command Prompt) and type:

Terminal
java -version

You should see something like this. The numbers after 21 may be different:

openjdk version "21.0.5" 2024-10-15 LTS
OpenJDK Runtime Environment Temurin-21.0.5+11 (build 21.0.5+11-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.5+11 (build 21.0.5+11-LTS, mixed mode, sharing)

The idea

Choose an editor

Two good free options:

  • IntelliJ IDEA: an editor made specially for Java. The free version is enough for the whole course (in older releases it is called IntelliJ IDEA Community Edition). When you create a new project, choose JDK 21. You run the program with the green triangle next to main.
  • Visual Studio Code with the Extension Pack for Java extension from Microsoft. It is lighter and works for other languages too. A Run link appears above main, and you use it to run the program.

Which editor you choose does not matter much. What matters more is that you get used to one and use it every day.

See it

Your first program on your computer

Make a folder for the course, and in it a file named Main.java with this content:

Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello!");
}
}
Output
Hello!

In the terminal, go to the folder (cd and the path to it) and run:

Terminal
java Main.java

The command compiles the file in memory and runs it right away. This is called running a single-file source program, and it has been possible since Java 11. It is enough for the programs in the "Language basics" module.

More precisely, if you are curious
  • The java Main.java command does not leave a .class file behind. Here are the two steps done separately: javac Main.java makes Main.class, and java Main (without .java) runs it.
  • The file has the same name as the class: public class Main is in Main.java. The javac compiler requires this, so build the habit from the very start.
  • If the Windows terminal shows question marks or odd symbols instead of characters such as € or é, the terminal is not set up for UTF-8. Type chcp 65001 and run the program again. Editors usually do not have this problem.

Try it

Change it and run it again

Add a second line that prints "Your computer is ready.", save the file and run the program again. You should see:

Output
Hello!
Your computer is ready.

If you see only "Hello!", the file most likely is not saved. Here is the whole program, in case you get stuck:

Main.java
public class Main {
public static void main(String[] args) {
System.out.println("Hello!");
System.out.println("Your computer is ready.");
}
}

Why a change you have not saved does not reach the program:

public class Main {
public static void main(String[] args) {
System.out.println("Hello!");
System.out.println("Your computer is ready.");
}
}
Step by step, in words
  1. The editor and the file on disk both have only the first line.
  2. You run java Main.java: the program is built from the file on disk.
  3. You add a second line in the editor. The file on disk is still the old one.
  4. You run it without saving: you still get only "Hello!".
  5. You save (Ctrl+S): the editor writes the text to the file on disk.
  6. You run it again: now the program sees the second line too.

The idea

When it will not start

  • "'java' is not recognized…" (Windows) or "command not found" (macOS, Linux): the terminal cannot find Java. Close it and open a new one, because the old one does not see the changes from the installation. If it still does not work, Java is not in the PATH: run the installer again and turn on the PATH option.
  • java -version shows an old version, such as 1.8: there is also an older Java on the computer, and it comes first in the PATH. Remove it or move it after the new one.
  • "error: … expected" or another message with a line number: the program has reached the compiler, so the installation is fine. Compare your code with the example character by character.

In short

In short

  • You need JDK 21 (Temurin, for example) and an editor: IntelliJ IDEA or VS Code with the Extension Pack for Java.
  • java -version shows whether Java is installed.
  • java Main.java compiles and runs a single-file program.
  • If the terminal cannot find the command, open a new terminal.

Next comes the lesson on how to solve a task before a single line of code is written.

Made by Ivo Gergov as part of Evo Tech's campaign for accessible programming education ·