Java + Spring Boot track

Lesson 01 · Part 1: Basics

Getting Started with Java

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…

Part 1: Basics6 min readFree lesson

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, javac commands.
  • 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 javac and run with java.

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

  1. Download OpenJDK 21 - Windows x64 .msi from the Temurin site and install by double-clicking.
  2. Check "Set JAVA_HOME variable" and "Add to PATH" options in the installation wizard.
  3. Default installation path:
    C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot\
    
  4. Open PowerShell again and check:
    $env:JAVA_HOME
    # C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot
    java --version
    
  5. If manual setting is required, at System Properties → Advanced → Environment Variables
    • JAVA_HOME = C:\Program Files\Eclipse Adoptium\jdk-21.x.x-hotspot
  • Add %JAVA_HOME%\bin to Path

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 point
  • System.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

  1. Download the .exe installer from the "Community Edition" tab on the JetBrains site.
  2. Double-click and follow the wizard (recommended to check 64-bit launcher / Add bin folder to PATH)
  3. Default installation path:
    C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2025.x\
    
  4. 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

  1. Download and install .exe (User Installer recommended)
  2. 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_HOME internally. If JAVA_HOME is 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

  1. The file name is saved as hello.java (lowercase letters), which is different from the class name.
  2. Enter the extension like java Hello.class → java Hello is correct.
  3. The entry point is lost by changing the signature of main to void main().
  4. Omit out of System.out.println and write as System.println
  5. Check encoding when Korean output is broken: Save the file as UTF-8, and the console is also UTF-8 (chcp 65001 Windows)

Cleanup

  • The Java program starts at public static void main(String[] args) within public class Xxx
  • If you compile .java with javac, .class is created, and run it as java.
  • Use print / println / printf of System.out according 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

Example files

The runnable files used in this lesson. Copy them into your own project and experiment.

src/Args.javaJava
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] + "!");
    }
}
src/CommentsAndJavadoc.javaJava
/** 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 + "!";
    }
}
src/Hello.javaJava
public class Hello {
    public static void main(String[] args) {
        System.out.println("Hello, Java!");
    }
}
src/PrintFormats.javaJava
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);
    }
}

Assignment

Problem 1 — Self-introduction printout

  • File name: Homework01.java
  • Core concepts: public class, main, System.out.println

Requirements

  • Print your name, favorite language, and start year on one line each.
  • The first line of output is === Self-introduction ===.

Expected output

=== Self-introduction ===
Name: Hong Gil-dong
Favorite language: Java
Start year: 2026

Hint

  • Just call System.out.println 4 times.

Problem 2 — Command line greetings

  • File name: Homework02.java
  • Key concepts: args array, conditional branching

Requirements

  • If the command line argument is empty, it prints Usage: java Homework02 <name> and exits.
  • If the first argument is given, it outputs Hello, <name>!.

Expected output

$ java Homework02
Usage: java Homework02 <name>

$ java Homework02 Jisoo
Hello, Jisoo!

Hint

  • Check the number of arguments with args.length.

Check the correct answer

After solving it yourself, compare it with the reference solution below. The reference solution is annotated with key points and common mistakes.

Show the reference solution

Try the assignment yourself first — comparing your attempt with a working solution is where most of the learning happens.

Homework01.javaJava
/** Print your self-introduction in 4 lines.*/
public class Homework01 {
    public static void main(String[] args) {
        System.out.println("=== Self-introduction ===");
        System.out.println("Name: Hong Gil-dong");
        System.out.println("Favorite language: Java");
        System.out.println("Start year: 2026");
    }
}
Homework02.javaJava
/** Print greetings according to command line arguments.*/
public class Homework02 {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Usage: java Homework02 <name>");
            return;
        }
        System.out.println("Hello," + args[0] + "Sir!");
    }
}

Learn this lesson with a mentor

Work through the Java + Spring Boot track on your own, or join a guided cohort at our Pitampura campus and online.

Call NowEnroll Now