โ† Back | JDK + Maven Setup
Pre-Course
Pre-Course ยท Setup

JDK + Maven Setup

Before writing a single line of Spring Boot code, you need Java and Maven installed. This guide takes you from zero to a working Java development environment.

โ˜• Java 21 LTS ๐Ÿ”ง Maven 3.9 Windows / Mac / Linux
๐Ÿง 
Step 1
What are JDK, JRE, JVM and Maven?
Understand before you install
Simple Analogy: Think of building a house.
JVM (Java Virtual Machine) = the land your house sits on โ€” it runs Java bytecode on any OS.
JRE (Java Runtime Environment) = the house itself โ€” everything needed to run Java programs.
JDK (Java Development Kit) = the house + construction tools (hammer, saw, blueprint) โ€” everything needed to build Java programs.
Maven = the delivery truck that brings all building materials (libraries) to your construction site automatically.
ToolFull NamePurposeWho Needs It
JVMJava Virtual MachineRuns compiled Java (.class) filesEveryone
JREJava Runtime EnvironmentJVM + standard librariesEnd users
JDKJava Development KitJRE + compiler (javac) + toolsDevelopers โœ…
MavenApache MavenBuild tool + dependency managerDevelopers โœ…
Why Java 21? Java 21 is the current LTS (Long-Term Support) release. LTS means it receives security updates for years โ€” companies use LTS versions in production. Always choose LTS for real projects.
โ˜•
Step 2
Install JDK 21
Download and install Java Development Kit
1

Download JDK 21

Go to adoptium.net (Eclipse Temurin โ€” free and enterprise-ready). Choose:
Version: 21 (LTS) ยท OS: Windows/Mac/Linux ยท Architecture: x64

Download the .msi installer (Windows) or .pkg (Mac) or .tar.gz (Linux).

2

Run the Installer (Windows)

Double-click the .msi file. Click Next โ†’ Next โ†’ Accept the default install location (C:\Program Files\Eclipse Adoptium\jdk-21...) โ†’ Finish.

Tip (Windows): The Temurin installer automatically sets JAVA_HOME and updates PATH for you. Skip the manual steps if the installer asks you to set it โ€” just check "Add to PATH".
3

Install on Mac (using Homebrew)

Terminal
brew install --cask temurin@21
4

Install on Ubuntu/Linux

Terminal
sudo apt update sudo apt install temurin-21-jdk
โš™๏ธ
Step 3
Set JAVA_HOME (Windows manual)
Only needed if installer didn't set it automatically
1

Open Environment Variables

Press Win + S โ†’ type "environment variables" โ†’ click "Edit the system environment variables" โ†’ click "Environment Variables" button.

2

Add JAVA_HOME

Under "System variables" โ†’ click New:
Variable name: JAVA_HOME
Variable value: C:\Program Files\Eclipse Adoptium\jdk-21.0.x.x-hotspot (your exact folder)

3

Add Java to PATH

In System variables, find Path โ†’ Edit โ†’ New โ†’ add:
%JAVA_HOME%\bin
Click OK on all dialogs.

Important: After changing environment variables, close and reopen any terminals/command prompts. Old terminals won't see the new values.
โœ…
Step 4
Verify Java Installation
Confirm Java is working correctly

Open a new terminal (Command Prompt or PowerShell on Windows, Terminal on Mac/Linux) and run:

Terminal
java -version

Expected output:

openjdk version "21.0.3" 2024-04-16 LTS OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9) OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9, mixed mode)

Also verify the compiler:

javac -version
javac 21.0.3
Both commands must work. If only java works but not javac, you have JRE installed, not JDK. Reinstall using the JDK installer.
๐Ÿ“ฆ
Step 5
Install Apache Maven
The build tool that manages your project dependencies
What does Maven do? Imagine writing a Spring Boot app. You need Spring, Hibernate, Jackson, and 30 other libraries. Without Maven, you'd download each JAR manually, figure out versions, and copy them to your project. Maven does all this with a single file: pom.xml. You just list what you need and Maven downloads it.

Install on Windows

1

Download Maven

Go to maven.apache.org/download.cgi โ†’ download the Binary zip archive (e.g., apache-maven-3.9.x-bin.zip).

2

Extract and Place

Extract the zip to C:\Program Files\Apache\maven (create the folder). You should see C:\Program Files\Apache\maven\bin\mvn.cmd.

3

Set MAVEN_HOME and PATH

Environment Variables โ†’ System variables โ†’ New:
MAVEN_HOME = C:\Program Files\Apache\maven
Then edit Path โ†’ New โ†’ %MAVEN_HOME%\bin

Install on Mac (Homebrew)

brew install maven

Install on Ubuntu/Linux

sudo apt update sudo apt install maven
โœ…
Step 6
Verify Maven Installation
Terminal (new window)
mvn -version

Expected output:

Apache Maven 3.9.6 (bc0240f3c744dd6b6ec2920b3cd08dcc295161ae) Maven home: C:\Program Files\Apache\maven Java version: 21.0.3, vendor: Eclipse Adoptium, runtime: C:\Program Files\Eclipse Adoptium\jdk-21...
Important check: The "Java version" shown by Maven must be 21. If it shows an older version, Maven is using a different JDK. Double-check your JAVA_HOME and restart the terminal.

Understanding Key Maven Commands

CommandWhat it does
mvn compileCompiles your Java source code
mvn testCompiles and runs tests
mvn packageCreates a JAR/WAR file
mvn cleanDeletes the target/ folder
mvn clean installClean + compile + test + package + install to local repo
mvn spring-boot:runRuns a Spring Boot application
๐Ÿš€
Step 7
Create Your First Maven Project
Verify everything works end to end
1

Generate a project

mvn archetype:generate \ -DgroupId=com.campustoai \ -DartifactId=hello-java \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=1.4 \ -DinteractiveMode=false
2

Navigate and build

cd hello-java mvn package
3

Run the app

java -cp target/hello-java-1.0-SNAPSHOT.jar com.campustoai.App

You should see: Hello World!

You're all set! Java and Maven are working. The next step is to install VS Code extensions, then create your first Spring Boot project.
๐ŸŽฏ
Interview Prep
Common Interview Questions
Questions freshers get asked about Java setup and Maven
QWhat is the difference between JDK, JRE, and JVM?

JVM (Java Virtual Machine) โ€” An abstract machine that executes Java bytecode. It is platform-specific (there's a JVM for Windows, Mac, Linux) but the bytecode it runs is platform-independent โ€” "Write Once, Run Anywhere."

JRE (Java Runtime Environment) โ€” JVM + the standard class libraries (like java.lang, java.util). Enough to run Java applications.

JDK (Java Development Kit) โ€” JRE + development tools: javac (compiler), javadoc, jar, jdb (debugger). Required to write and compile Java code.

As a developer you always install the JDK.

QWhat is Maven and why do we use it?

Maven is a build automation and dependency management tool for Java projects. It solves two main problems:

1. Dependency management โ€” You declare libraries (Spring, Hibernate, etc.) in pom.xml and Maven downloads them automatically from a central repository (Maven Central). No more manually downloading JARs.

2. Build lifecycle โ€” Maven defines standard phases: validate โ†’ compile โ†’ test โ†’ package โ†’ install โ†’ deploy. One command (mvn clean install) does everything.

QWhat is pom.xml?

POM stands for Project Object Model. The pom.xml file is the heart of a Maven project. It contains:

  • coordinates โ€” groupId, artifactId, version (GAV) โ€” uniquely identify the project
  • dependencies โ€” libraries your project needs
  • plugins โ€” tools that run during the build (like the Spring Boot plugin)
  • properties โ€” configuration like Java version
QWhat are dependency scopes in Maven?

Scopes control when a dependency is available in the classpath:

  • compile (default) โ€” available in all phases. E.g., Spring Boot starter.
  • test โ€” only during testing. E.g., JUnit, Mockito.
  • provided โ€” available at compile time but provided by the runtime. E.g., servlet-api (the container provides it).
  • runtime โ€” not needed at compile time but needed at runtime. E.g., JDBC driver.
QWhat is the difference between mvn package and mvn install?

mvn package compiles, tests, and creates the JAR/WAR file in the target/ directory โ€” but only for the current project.

mvn install does everything package does, plus copies the artifact to your local Maven repository (~/.m2/repository). This makes the artifact available as a dependency for other local projects.

In most cases for Spring Boot apps, you use mvn package to get the deployable JAR, or mvn spring-boot:run to run directly during development.

QWhat is JAVA_HOME and why is it important?

JAVA_HOME is an environment variable that points to the JDK installation directory. Many tools (Maven, Gradle, IDEs, app servers) rely on JAVA_HOME to find the JDK they should use.

If JAVA_HOME is not set or points to the wrong version, tools may fail or use an unexpected Java version. Always verify that echo %JAVA_HOME% (Windows) or echo $JAVA_HOME (Mac/Linux) shows the correct JDK path.