Install JDK and IntelliJ: run your first Java program

Install JDK 25 on Windows, check it with java --version, and run your first Java program from IntelliJ or the command line, plus common newcomer mistakes.

To run Java you need to install the JDK, the toolkit that holds the compiler and the Java virtual machine. Today you should pick JDK 25 or 21, both long-term support releases. After installing, type java --version to check it, then write a .java file and run it from IntelliJ or the command line.

Let's start from a small problem. The Mộc café, a small online café that I use as the running example in this series (an illustrative situation, not a real café), manages its orders in a spreadsheet. There are a few hundred orders a day, and the file has started to be slow and wrong. The owner wants to rewrite the order system in Java. To write it, the first thing is that your machine can run a Java program, even if it only prints one line.

If you do not know where you stand in the whole path, look at the map in the Java backend developer roadmap. This post is the first step of the first stage.

How are the JDK, JRE and JVM different?

These three abbreviations confuse newcomers right from the start, and this is also a common interview question, so I explain it in some detail.

When you write Java code, you write a text file with the extension .java. A computer does not understand this file. A tool called javac (the Java compiler) reads that file and translates it into another file with the extension .class. A .class file holds bytecode, an intermediate form of code, not the machine code of Windows or macOS in particular. Finally the program java starts something called the JVM (Java Virtual Machine) to read the bytecode and run it.

From code to running
HelloMoc.java  --javac-->  HelloMoc.class  --java (JVM)-->  result on screen
 (you write it)         (bytecode, intermediate code)      (the JVM reads and runs it)

Because bytecode is not tied to an operating system, the same .class file can run on Windows, macOS or Linux, as long as that machine has a JVM. This is why Java is used so much for servers: you write and compile on a Windows laptop, then take the file and run it on a Linux server.

So what are the three abbreviations? The JVM is the virtual machine I just described. The JRE (Java Runtime Environment) is the JVM plus the standard libraries, enough to run a Java program that already exists. The JDK (Java Development Kit) is the JRE plus the tools to write and compile, of which the most important is javac.

A person who writes code needs the JDK. You do not need to install a JRE separately.

Which Java version should you install?

Java gets a new version every six months, but only some versions are called LTS (Long-Term Support), which means they get security updates for many years. Every company likes to use LTS versions for real systems. According to the sources I looked up on 16 November 2026, Java 25 is the newest LTS, released on 16 September 2025, and the first LTS since Java 21 (2023).

This series uses Java 25. If the company you work for still uses Java 21, most of the content is still right, because most of the changes between the two versions are advanced features that I will point out when we reach them. I will not make you use Java 8 or 11, the two old versions that you still see in many tutorials online.

And which vendor's JDK? Several publishers package the open-source OpenJDK: Oracle, Microsoft, Amazon, Eclipse Adoptium and others. For a newcomer, the most significant difference is the licence: the Oracle build has free terms for a period and then charges for commercial use, while Eclipse Temurin (from Eclipse Adoptium) uses the open-source GPLv2 licence with the Classpath Exception, so you do not have to worry about this. I use Temurin in the post, and you can choose another build without a problem.

One thing to say up front to save you time: the name "Eclipse" here is the name of the publishing organization and has nothing to do with the Eclipse programming IDE. You still use IntelliJ as usual.

How do you install the JDK on Windows?

There are two ways. The first is to go to adoptium.net, choose version 25, download the .msi file and click through the installer like any other software. The second is to use winget, the package manager that comes with Windows 10 and 11. I use the second because it needs only one command:

Install Temurin JDK 25 with winget
winget install --id EclipseAdoptium.Temurin.25.JDK

On my machine, the end of this command printed the lines below. You need to look at the line with the word Version and the last line, Successfully installed:

Output (the introduction part is cut)
Found Eclipse Temurin JDK with Hotspot 25 [EclipseAdoptium.Temurin.25.JDK] Version 25.0.5.8
Downloading https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.5+8/OpenJDK25U-jdk_x64_windows_hotspot_25.0.5_8.msi
Successfully verified installer hash
Starting package install...
Successfully installed

The line Successfully verified installer hash says that winget checked that the downloaded file matches the published hash, which means the file was not altered on the way. This is one reason why I like to use a tool such as winget instead of downloading a file from a page of unknown origin.

To find out whether the installation worked, open a new command window (a window that was already open has not picked up the new configuration) and type:

Check the JDK
java --version
Output on my machine
openjdk 25.0.5 2026-10-20 LTS
OpenJDK Runtime Environment Temurin-25.0.5+8 (build 25.0.5+8-LTS)
OpenJDK 64-Bit Server VM Temurin-25.0.5+8 (build 25.0.5+8-LTS, mixed mode, sharing)

You only need to look at the first line: the number 25 is the Java version that runs. The small patch version (here .0.5) may differ on your machine, because Temurin updates often. I only tested this way of installing on Windows. If you use macOS or Linux, adoptium.net has separate instructions for each operating system.

What if the machine says it cannot find java?

This is the most common error when you install for the first time. It happens when the folder that contains the program java is not yet in the PATH environment variable, the list of folders where the command line looks for programs. I reproduced it by running java in a PowerShell window whose PATH has only the system folders:

When PATH does not have the folder of the JDK (PowerShell)
The term 'java' is not recognized as the name of a cmdlet, function, script file, or operable program.

The message in cmd.exe is worded a bit differently but means the same. The installer of Temurin usually adds the bin folder of the JDK to PATH by itself and sets the variable JAVA_HOME to point at the install folder (on my machine, C:\Program Files\Eclipse Adoptium\jdk-25.0.5.8-hotspot\). If you run java --version and still get the error, close all the command windows, open a new one, and try again. An old window only reads PATH when it is opened.

What does the first Java program look like?

Create a file called HelloMoc.java with the content below. I explain each line right after, because to a newcomer every line looks strange:

HelloMoc.java
public class HelloMoc {
    public static void main(String[] args) {
        System.out.println("Hello from the Mộc café!");
        System.out.println("First order: 1 milk coffee, 35000 đồng");
        System.out.println("Running on Java " + System.getProperty("java.version"));
    }
}

The first line, public class HelloMoc, declares a class named HelloMoc. In Java, all code lives inside a class, and for a class marked public, the file name must match the class name: the class HelloMoc must be in a file named HelloMoc.java. I will explain what a class is in later posts. The price of 35000 đồng is about US$1.30.

The second line, public static void main(String[] args), is the starting point of the program. When you run a Java program, the JVM looks for a method (function) named main with exactly this signature and starts running from there. For now you can think of main as the "front door", and I will explain the words public, static and void one by one as we meet them.

The three System.out.println(...) lines print three lines of text to the screen. The last one joins a string with the result of System.getProperty("java.version"), a command that asks the JVM which Java version it is. Putting the version in the output helps you make sure you are running the JDK you just installed and not some older version left on the machine.

There are two ways to run this file. The first one, compile and then run:

Way 1: javac, then java
javac HelloMoc.java
java HelloMoc

The command javac prints nothing if there are no errors, and creates a file HelloMoc.class next to the .java file. The command java HelloMoc (note: write the class name, without the .class extension) starts the JVM to run that file. The second way, shorter, exists since Java 11:

Way 2: run the source file directly
java HelloMoc.java

This way compiles the file in memory and runs it at once, leaving no .class file. I checked this by running ls after each way. After javac, the folder has HelloMoc.class and HelloMoc.java. After I deleted the .class file and ran java HelloMoc.java, the folder only had HelloMoc.java. The second way is handy for quickly trying a small piece of code, while real projects always use the first (really, a build tool such as Maven does it for you, which I will cover in a later post).

Why do Vietnamese letters break when you run on Windows?

Both ways above run fine on my machine, but the output has something odd: many letters with marks are replaced by a ?. If you see exactly that, this is an error that Vietnamese people hit very often, and it is worth understanding a little because it will come back when you read and write files that contain Vietnamese text. Even if you never write Vietnamese, the same thing happens with any character outside Western European alphabets, and that is why my example text has ộ and đ in it.

To find the cause, I wrote a small program that asks Java which character encoding it uses:

CheckEncoding.java
import java.nio.charset.Charset;

public class CheckEncoding {
    public static void main(String[] args) {
        System.out.println("file.encoding   = " + System.getProperty("file.encoding"));
        System.out.println("native.encoding = " + System.getProperty("native.encoding"));
        System.out.println("stdout.encoding = " + System.getProperty("stdout.encoding"));
        System.out.println("System.out uses = " + System.out.charset());
        System.out.println("Default (Mặc định) = " + Charset.defaultCharset());
    }
}

Running java CheckEncoding.java on my machine, the result is:

Output of CheckEncoding on my machine
file.encoding   = UTF-8
native.encoding = Cp1252
stdout.encoding = Cp1252
System.out uses = windows-1252
Default (M?c ??nh) = UTF-8

Look at two things. First, the line stdout.encoding = Cp1252: the output of the program uses the Windows-1252 encoding, which only has the letters of Western European languages. Second, the last line: the Vietnamese word "Mặc định" (which means "default") is printed as M?c ??nh, because the letters ặ, đ and ị do not exist in this encoding, so Java replaces them with question marks. The letter é in the word "café", on the other hand, does exist in the 1252 encoding, so it still shows correctly. That is exactly why some accented letters disappear and others do not. Running HelloMoc without any option gives Hello from the M?c café! and First order: 1 milk coffee, 35000 ??ng.

What is worth remembering is that file.encoding is already UTF-8: since Java 18, the default encoding for reading and writing files is UTF-8 on every operating system. The problem lies in the output on the screen, which takes its encoding from the operating system (native.encoding). The fix is to tell Java to print in UTF-8:

Force the output to UTF-8
java -Dstdout.encoding=UTF-8 HelloMoc.java
Output
Hello from the Mộc café!
First order: 1 milk coffee, 35000 đồng
Running on Java 25.0.5

There is a limit that I must state plainly: I checked the output through a pipe, where a program that receives the text receives it correctly. With the real Windows command window, besides setting -Dstdout.encoding=UTF-8, you may need to use Windows Terminal or change the code page with chcp 65001. I did not take a screenshot of a cmd window to confirm each step, so if you follow along and still see boxes instead of letters, try switching to Windows Terminal. When you run inside IntelliJ you usually do not meet this error, because the Run window of IntelliJ accepts UTF-8 text.

Two mistakes newcomers often make when writing Java

Running correctly once is not enough. I deliberately broke two things so you become familiar with the error messages of the compiler, because you will see them a lot.

The first mistake is a file name that does not match the class name. I copied the content of HelloMoc.java into a file called Wrong.java and compiled it:

javac Wrong.java
Wrong.java:1: error: class HelloMoc is public, should be declared in a file named HelloMoc.java
public class HelloMoc {
       ^
1 error

The first sentence says almost everything: the class HelloMoc is public, so it must be in the file HelloMoc.java. The arrow ^ points at the word HelloMoc on line 1. The fix is to rename the file to match, not to change the code.

The second mistake is a missing semicolon at the end of a statement. I took the ; away from the line System.out.println("hello") in a file called Oops.java:

javac Oops.java
Oops.java:3: error: ';' expected
        System.out.println("hello")
                                   ^
1 error

The message says line 3, and the ^ points to the exact position right after the closing parenthesis, where a ; should be. Every statement in Java ends with a semicolon, and this is the mistake of nearly everyone in the first days. A good habit: read the first line of the message, look at the line number, and open exactly that line. How to read an error message from the bottom up or from the top down, I wrote in the post on how to read a stack trace.

Does Java 25 have a shorter way to write this?

Yes. If you read a newer tutorial, you may see a Java program with only a few lines, without public class or public static void main. That is the feature "compact source files and instance main methods" (JEP 512), final since Java 25, which makes the first program of a newcomer less heavy. I tried it with a file HelloMocCompact.java:

HelloMocCompact.java
void main() {
    IO.println("Hello from the Mộc café (the short Java 25 syntax)");
}
Run the short file
java -Dstdout.encoding=UTF-8 HelloMocCompact.java
Output
Hello from the Mộc café (the short Java 25 syntax)

The program runs correctly. The class IO is a new utility class in Java 25 that makes printing and reading from the keyboard shorter. In my view this way of writing is great for learning and for quick experiments, but I still teach the full form (public class with main) in this series, because Spring code and nearly every real project in the later posts use the full form, and interviews also ask in that form. You can read the details of this feature in JEP 512 on openjdk.org.

How do you run the program in IntelliJ?

You can already run it from the command line, but once you have many files you will use an IDE. I use IntelliJ IDEA because it is the most popular IDE for Java backend work. There are two things to notice before you install.

The first is that your version of IntelliJ must be new enough. According to JetBrains, IntelliJ IDEA has supported Java 25 since version 2025.2, and version 2025.3 improves it further. If your machine has an old version, for example 2021 or 2022, it will not understand the syntax and the libraries of Java 25, so update first.

The second is that from version 2025.3, JetBrains merged the Community and Ultimate editions into one single IntelliJ IDEA (the free and paid parts share one installer). In the first posts of this series I only use plain Java, so the free part is enough. When we reach Spring, I will check exactly which parts need the paid version and say so in that post.

After installing IntelliJ, the basic steps are:

  1. Choose New Project, give it a name and choose the language Java.
  2. In the JDK box, choose the JDK 25 you just installed (if you do not see it yet, choose Add JDK and point to the install folder; IntelliJ can also download a JDK for you).
  3. Create a class named HelloMoc in the src folder and paste the code above into it.
  4. Click the green arrow next to the line public static void main to run it.

I describe these steps in the way IntelliJ works in general, and I did not take screenshots of every version. The menu names can differ slightly between versions, so if you see something different, just look for the same idea ("New Project", "JDK", "Run"). The important thing to check is that the JDK box says 25 and not an old version.

What is the next step?

You now have the JDK, you can run your first program, and you can read two common compile errors. But the program of the Mộc café only prints one order as text. There is nowhere to store the item name, the price or the quantity, and we do not yet know which number type to declare for the price 35000, because the wrong number type will make the price calculation wrong. That is the job of the next post, about variables and data types. You can follow this series on the page Learn Java from scratch for backend developers.

If you are preparing for interviews, try answering the question about how the JDK, JRE and JVM differ in the interview question bank before you read the answer.

Get the next post by email.

One email a week, only when there is something worth reading. No spam.