Java is a static type/object-oriented programming language that has been used as a main language in the industrial field for 30 years since its announcement in 1995. In this episode, we will install JDK 21 LTS, select an IDE, and compile and run the first program.
Learning Objectives
- Install JDK 21 LTS and check the
java,javaccommands. - Choose either IntelliJ IDEA Community or VS Code to set up the environment.
- Understand the structure of
public class/public static void main - You can compile with
javacand run withjava.
Key concepts
1) JDK and JRE
To write and run Java code, you need the Java Development Kit (JDK). The JDK includes a compiler (javac), executor (java), standard library, and JRE (Java Runtime Environment). We recommend Eclipse Temurin JDK 21 LTS.
java --version # openjdk 21.x.x
javac --version # javac 21.x.x
2) Install JDK 21 for each operating system
Download page: https://adoptium.net/temurin/releases/?version=21
Windows
- Download
OpenJDK 21 - Windows x64 .msifrom the Temurin site and install by double-clicking. - Check "Set JAVA_HOME variable" and "Add to PATH" options in the installation wizard.
- Default installation path:
C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot\ - Open PowerShell again and check:
$env:JAVA_HOME # C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot java --version - If manual setting is required, at
System Properties → Advanced → Environment VariablesJAVA_HOME=C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot
- Add
%JAVA_HOME%\bintoPath
macOS
Option A — Homebrew (recommended):
brew install --cask temurin@21
Installation path:
/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home
Add the following to ~/.zshrc and source ~/.zshrc:
export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH="$JAVA_HOME/bin:$PATH"
Option B — Download and install .pkg from the Temurin site (installed in the same path as above).
Linux (Ubuntu/Debian)
Option A — OpenJDK 21 with apt:
sudo apt update
sudo apt install -y openjdk-21-jdk
Installation path:
/usr/lib/jvm/java-21-openjdk-amd64
Option B — Adoptium Temurin Repository:
#Add key and storage
sudo apt install -y wget apt-transport-https
wget -qO - https://packages.adoptium.net/artifactory/api/gpg/key/public \
| sudo gpg --dearmor -o /etc/apt/keyrings/adoptium.gpg
echo "deb [signed-by=/etc/apt/keyrings/adoptium.gpg] \
https://packages.adoptium.net/artifactory/deb $(lsb_release -cs) main" \
| sudo tee /etc/apt/sources.list.d/adoptium.list
sudo apt update
sudo apt install -y temurin-21-jdk
Installation path:
/usr/lib/jvm/temurin-21-jdk-amd64
To ~/.bashrc (or ~/.zshrc):
export JAVA_HOME=/usr/lib/jvm/temurin-21-jdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"
Check installation (common)
java --version
#openjdk 21.x.x or temurin 21.x.x
javac --version
# javac 21.x.x
echo $JAVA_HOME # macOS / Linux
#/Library/Java/... or /usr/lib/jvm/...
If java / javac are both 21, you are ready.
3) Hello.java file structure
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
- The file name must be the same as
public class→Hello.java main(String[] args)is execution entry pointSystem.out.println(...)prints one line and adds a line break.
4) Compilation and execution
javac Hello.java #Create Hello.class
java Hello #Run (no extension!)
javac converts the .java source to bytecode .class, and java executes the bytecode on the JVM.
5) Select IDE
| tools | Advantages |
|---|---|
| IntelliJ IDEA Community | Most Popular, Free, Powerful Refactorings for Java/Spring Tasks |
| VS Code + Extension Pack for Java | Lightweight and versatile, perfect for multilingual work |
This tutorial is written so that it can be followed equally with either tool.
6) Install IDE for each operating system
IntelliJ IDEA Community Edition
Download page: https://www.jetbrains.com/idea/download/?section=
Windows
- Download the
.exeinstaller from the "Community Edition" tab on the JetBrains site. - Double-click and follow the wizard (recommended to check 64-bit launcher / Add bin folder to PATH)
- Default installation path:
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2025.x\ - User settings (project cache/index):
C:\Users<user>\AppData\Roaming\JetBrains\IdeaIC2025.x\
**macOS**
Option A — Homebrew:
```bash
brew install --cask intellij-idea-ce
Option B — Get .dmg from JetBrains site and drag it.
Installation path:
/Applications/IntelliJ IDEA CE.app
User settings:
~/Library/Application Support/JetBrains/IdeaIC2025.x/
Linux (Ubuntu/Debian)
Option A — Snap (easiest):
sudo snap install intellij-idea-community --classic
Installation path: /snap/intellij-idea-community/current/
Option B — Unpack .tar.gz to /opt from JetBrains site:
sudo tar -xzf ideaIC-2025.x.tar.gz -C /opt
sudo ln -sf /opt/idea-IC-*/bin/idea.sh /usr/local/bin/idea
idea #run
User Setting: ~/.config/JetBrains/IdeaIC2025.x/
VS Code + Extension Pack for Java
Download page: https://code.visualstudio.com/Download
Windows
- Download and install
.exe(User Installer recommended) - Default installation path (User Installer):
C:\Users<user>\AppData\Local\Programs\Microsoft VS Code\
3. For System Installer:
C:\Program Files\Microsoft VS Code\
**macOS**
Option A — Homebrew:
```bash
brew install --cask visual-studio-code
Option B — Download .zip from the site, unzip it and drag it to Applications.
Installation path:
/Applications/Visual Studio Code.app
Linux (Ubuntu/Debian)
Option A — Microsoft .deb:
sudo apt install -y wget gpg apt-transport-https
wget -qO- https://packages.microsoft.com/keys/microsoft.asc \
| gpg --dearmor | sudo tee /etc/apt/keyrings/packages.microsoft.gpg > /dev/null
echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/packages.microsoft.gpg] \
https://packages.microsoft.com/repos/code stable main" \
| sudo tee /etc/apt/sources.list.d/vscode.list
sudo apt update
sudo apt install -y code
Installation path: /usr/share/code/, executable file is /usr/bin/code.
Option B — Snap:
sudo snap install --classic code
Installing Java Extension Pack (Common)
Run VS Code and click on the Extensions icon on the left (Ctrl+Shift+X).
Search for Extension Pack for Java (provided by Microsoft) and install it.
Also possible from the command line:
code --install-extension vscjava.vscode-java-pack
This pack includes:
- Language Support for Java (Red Hat)
- Debugger for Java
- Test Runner for Java
- Maven for Java
- Project Manager for Java
Note: VS Code's Java extension uses system
JAVA_HOMEinternally. IfJAVA_HOMEis set to 21 after installing JDK 21, separate IDE settings are not required.
See as example
Example 1 — Hello.java: The smallest Java program
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Execution result
Hello, Java!
Memo: If the file name and class name are different, a class Hello is public, should be declared in a file named Hello.java compilation error will occur.
Example 2 — Args.java: Receiving command line arguments
public class Args {
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Try passing the name as an argument.");
return;
}
System.out.println("Hello, " + args[0] + "!");
}
}
Execution result
$ java Args Java
Hello, Java!
Note: args is a parameter of main. You can know the number with args.length and access it with an index like args[0].
Example 3 — PrintFormats.java:print/println/printf
public class PrintFormats {
public static void main(String[] args) {
System.out.print("line break");
System.out.print("None\n");
System.out.println("automatic line break");
System.out.printf("Name=%s, Age=%d%n", "exponent", 21);
}
}
Execution result
No line breaks
automatic line break
Name=Jisoo, Age=21
Memo: %n of printf always outputs a line break according to the OS, and \n always outputs LF.
Example 4 — CommentsAndJavadoc.java: Three comments
/** Demo showing the types of annotations.*/
public class CommentsAndJavadoc {
//one line comment
/*multiple lines
tin*/
public static void main(String[] args) {
System.out.println(greeting("Java")); //inline comments
}
/** Returns the greeting.*/
static String greeting(String name) {
return "Hello, " + name + "!";
}
}
Execution result
Hello, Java!
Note: Javadoc comments in /** ... */ format are official API comments that the javadoc tool can convert to HTML documents.
Common Mistakes
- The file name is saved as
hello.java(lowercase letters), which is different from the class name. - Enter the extension like
java Hello.class→java Hellois correct. - The entry point is lost by changing the signature of
maintovoid main(). - Omit
outofSystem.out.printlnand write asSystem.println - Check encoding when Korean output is broken: Save the file as UTF-8, and the console is also UTF-8 (
chcp 65001Windows)
Cleanup
- The Java program starts at
public static void main(String[] args)withinpublic class Xxx - If you compile
.javawithjavac,.classis created, and run it asjava. - Use
print/println/printfofSystem.outaccording to the situation.
Try it yourself
cd 01_Basics/01_Java_Getting-Started/src
javac Hello.java
java Hello
Other examples do the same:
javac Args.java
java Args Coding Now