Back to Blog

JDK vs JVM vs JRE, JAR vs WAR, and Maven Setup (Complete Beginner Guide)

JDK vs JVM vs JRE, JAR vs WAR, and Maven Setup (Complete Beginner Guide)

If you are new to Java, terms like JDK, JVM, JRE, JAR, WAR, and Maven can feel like alphabet soup.

This guide is a practical path from beginner to advanced understanding, so Java architecture becomes clear and not confusing.

Big picture first: how Java runs

When you write Java:

  1. You write source code (.java)
  2. The compiler converts it into bytecode (.class)
  3. The JVM executes that bytecode on your machine

That is Java's core promise: write once, run anywhere (where a JVM exists).

JDK, JRE, and JVM in simple terms

Think of a kitchen:

  • JVM: the stove that actually cooks
  • JRE: the stove + basic utensils needed to run an app
  • JDK: everything in JRE + chef tools to build apps

JVM (Java Virtual Machine)

JVM is the runtime engine that executes Java bytecode.

Main jobs:

  • Loads classes
  • Verifies bytecode safety
  • Runs code via interpreter/JIT compiler
  • Manages memory and garbage collection

You usually do not install JVM separately. It comes with a JDK.

JRE (Java Runtime Environment)

JRE provides what is needed to run Java apps:

  • JVM
  • Core Java libraries
  • Supporting runtime files

Historically, people used JRE for running apps only. In modern Java, you usually install JDK directly.

JDK (Java Development Kit)

JDK is what developers install.

It includes:

  • JRE capabilities
  • Compiler (javac)
  • Packager (jar)
  • Debug and tooling commands (jdb, javadoc, jshell, etc.)

If you want to build Java code, install JDK.

JAR and WAR: what gets packaged

JAR (Java ARchive)

A JAR is a zip-like package for Java classes/resources.

Use it for:

  • Libraries
  • Console apps
  • Runnable Java applications

Common command:

jar --create --file app.jar -C out .

Run executable JAR:

java -jar app.jar

WAR (Web ARchive)

A WAR packages a Java web app for servlet containers/app servers.

Contains web structure like:

  • WEB-INF/web.xml
  • classes
  • JSP/static files
  • dependencies

Use WAR for traditional web apps deployed to Tomcat/Jetty.

JAR vs WAR quickly

  • JAR: general Java package, often standalone
  • WAR: web application package for servlet containers
  • JAR entry point: Main-Class manifest
  • WAR entry point: servlet container + deployment descriptor/annotations

Step 1: Install JDK on macOS

Option A (recommended on macOS with Homebrew):

brew update
brew install openjdk@21

Then link and expose it (Apple Silicon path shown):

sudo ln -sfn /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-21.jdk

Set environment in your shell profile (~/.zshrc):

export JAVA_HOME=$(/usr/libexec/java_home -v 21)
export PATH="$JAVA_HOME/bin:$PATH"

Reload shell:

source ~/.zshrc

Verify:

java -version
javac -version
echo $JAVA_HOME

Option B:

  • Download an LTS JDK (21 or 17) from Adoptium/Oracle
  • Install .pkg
  • Verify with same commands above

Step 2: Write and run your first Java app

Create Hello.java:

public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello, Java architecture!");
  }
}

Compile + run:

javac Hello.java
java Hello

Now you have seen source -> bytecode -> JVM execution.

Step 3: Build a JAR manually

Create manifest file manifest.txt:

Main-Class: Hello

Package:

jar --create --file hello.jar --manifest manifest.txt Hello.class

Run:

java -jar hello.jar

You now understand JAR as deployable packaging.

Step 4: Understand WAR with a simple mental model

WAR is for web app deployment where server handles HTTP lifecycle.

Flow:

Browser -> Tomcat -> Servlet -> Business logic -> Response/JSP

For WAR-based projects, you either:

  • Deploy app.war to a server, or
  • Run embedded server frameworks that internally handle this for you

Step 5: Install Maven

Why Maven is important:

  • Standard project structure
  • Dependency management from repositories
  • Build lifecycle (compile, test, package, install)
  • Reproducible builds across machines/CI

Install on macOS:

brew install maven
mvn -version

You should see Maven version and Java version together.

Step 6: Create a Maven Java project and build JAR

Create project:

mvn archetype:generate \
  -DgroupId=com.example \
  -DartifactId=java-core-demo \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DinteractiveMode=false

Build:

cd java-core-demo
mvn clean package

Generated artifact appears in target/.

Step 7: Create WAR project with Maven

Create a web app project:

mvn archetype:generate \
  -DgroupId=com.example \
  -DartifactId=java-web-demo \
  -DarchetypeArtifactId=maven-archetype-webapp \
  -DinteractiveMode=false

Package WAR:

cd java-web-demo
mvn clean package

You get target/java-web-demo.war.

Deploy this WAR to Tomcat webapps directory, then start Tomcat.

Beginner to advanced roadmap (recommended learning order)

Phase 1: Beginner

  • Java syntax, classes, methods, collections
  • Compile and run with javac + java
  • Understand what bytecode is

Phase 2: Core runtime understanding

  • JVM memory model (heap, stack, metaspace)
  • Class loading lifecycle
  • Garbage collection basics
  • JIT vs interpreted execution

Phase 3: Packaging and build

  • JAR creation and manifests
  • WAR structure and servlet flow
  • Maven lifecycle and dependency scopes

Phase 4: Advanced architecture clarity

  • Layered architecture (controller/service/repository)
  • API contracts and DTO patterns
  • Modularization and multi-module Maven
  • Performance and observability basics

Common beginner mistakes to avoid

  • Installing only runtime and missing compiler tools
  • Not setting JAVA_HOME correctly
  • Mixing Java versions in IDE and terminal
  • Treating Maven as just a command runner instead of a build standard
  • Jumping into frameworks before understanding JAR/WAR and JVM basics

Quick cheat sheet

  • Build toolchain: JDK
  • Runtime engine: JVM
  • Runtime bundle (historical concept): JRE
  • Package for Java apps/libs: JAR
  • Package for Java web apps: WAR
  • Standard build/dependency automation: Maven

Final takeaway

If this still feels like many concepts, that is normal.

Use this sequence repeatedly:

  1. Install JDK and verify
  2. Compile and run simple Java
  3. Package as JAR and run it
  4. Build and inspect a WAR
  5. Use Maven to automate and standardize everything

Once these are clear, Java core architecture becomes predictable, and advanced frameworks become much easier to learn.