π What Youβll Learn
- What the JDK is and why you need it
- How to download and install the JDK
- Picking and setting up an IDE (like IntelliJ or VS Code)
- Verifying your installation
- Writing a basic "Hello, World!" program
π§ What is the JDK?
The Java Development Kit (JDK) is a software package that includes the Java compiler, Java Runtime Environment (JRE), and tools to develop Java programs.
You need it installed to:
- Compile
.javafiles into bytecode - Run Java applications locally
β¬οΈ Step 1: Download the JDK
Go to the official Java website: π https://dev.java
Choose your OS (Windows, macOS, Linux)
Download the latest Long-Term Support (LTS) version β currently Java 21 LTS is recommended
π» Step 2: Install the JDK
On Windows:
- Run the
.exeinstaller - Accept defaults or choose install path (e.g.,
C:\Program Files\Java\jdk-21) - After install, set your
JAVA_HOMEenvironment variable - Add
JAVA_HOME\binto the systemPATH
On macOS:
- Install using the
.pkginstaller - Java is usually auto-configured by macOS
- Verify via terminal:
java -version
On Linux (Ubuntu/Debian):
sudo apt update
sudo apt install openjdk-21-jdk
β Step 3: Verify Installation
Open your terminal or command prompt and type:
java -version
You should see something like:
openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-58)
OpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)
π οΈ Step 4: Choose an IDE
An IDE (Integrated Development Environment) makes writing Java easier with features like autocomplete and debugging.
Popular IDEs:
- IntelliJ IDEA (Community Edition) β Best full-featured option
- VS Code β Lightweight with Java extensions
- Eclipse β Veteran option, a bit dated but functional
π For beginners, we recommend IntelliJ:
βοΈ Step 5: Create Your First Java File
In your IDE or text editor:
- Create a new file called
HelloWorld.java - Add this code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
- Compile the file (if using terminal):
javac HelloWorld.java
- Run it:
java HelloWorld
π Output
Hello, World!
If you see that, you're ready to dive into Java programming!