Java Hello World with Maven: What the JDK Does and What Maven Adds
javac compiles HelloWorld.java into bytecode and java runs it on the JVM. Maven adds one pom.xml, the same folders in every project and one build command. Then a real Maven Hello World in IntelliJ.
What you will learn
- Explain how javac turns a .java file into bytecode and how java runs it
- Describe what Maven adds: pom.xml, standard folders and one build command
- Create a Maven project in IntelliJ with a valid groupId and artifactId
- Read the output of mvn package line by line
Before you start
- JDK 25 and IntelliJ IDEA installed
Your first Java program, done the way real projects do it: as a Maven project. Two ideas come first. The JDK compiles and runs your code. Maven organises the project and builds it with one command. Then you put both together in IntelliJ IDEA.
What the JDK gives you
Here's the whole program:
package org.studyeasy;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
HelloWorld.java is source code, plain text that you write. Two tools from the JDK take it from there:
javac, the Java compiler, reads the file and producesHelloWorld.class. That's bytecode, made for the Java Virtual Machine (JVM), not for your processor directly.javastarts the JVM, loads that class, runs itsmainmethod, and you see the output.
Here's the same thing in a terminal:
> javac -d out src\main\java\org\studyeasy\HelloWorld.java
> java -cp out org.studyeasy.HelloWorld
Hello, World!
-d out tells javac to put the compiled class in the out folder (as out\org\studyeasy\HelloWorld.class). -cp out tells java where to look for classes, and you run the class by its full name, package included. You won't type these every day. IntelliJ and Maven call these same two tools for you each time you click Run.
What Maven adds
For one file, the JDK is enough. Real applications use many libraries, and managing them by hand gets painful fast: you download every jar yourself, keep the versions in sync, and sort out clashes yourself. Maven takes that over.
- One file,
pom.xml. It says what you're building (agroupId, anartifactIdand aversion) and lists the libraries you need. Maven fetches them from Maven Central, the big public store of Java libraries, downloads each one once into a local cache (~/.m2) and reuses it. - The same folders everywhere. Code in
src/main/java, tests insrc/test/java, output intarget. Open any Maven project and you know where things are. - One command.
mvn packagecompiles the code, runs the tests and packs the result into a jar intarget. The build works the same on your machine, your teammate's and a server.
Gradle is another build tool you'll hear about, but this course uses Maven.
Create the Maven project in IntelliJ
Step 1: a new Maven archetype project
On the welcome screen, click New Project. Under Generators, pick Maven Archetype. An archetype is a project template. (You can also make a plain Maven project from the Java page with Maven as the build system; both give you a pom.xml.) Name it Hello World, keep JDK 25 and leave the catalog on Internal, the archetype list that ships with IntelliJ.
Step 2: archetype and coordinates
From the archetype list, maven-archetype-quickstart gives you a starter class and a test. The lecture picks maven-archetype-site-simple 1.1, a bare starter with a pom.xml and a small site folder, and adds the Java code afterwards.
Open Advanced Settings. The artifactId took the name Hello World, and it's red: whitespaces are not allowed. Fix the coordinates:
| Field | Value | Meaning |
|---|---|---|
| groupId | org.studyeasy | Your organisation, usually your domain written backwards |
| artifactId | HelloWorld | This project's name, one word, no spaces |
| version | 1.0-SNAPSHOT | SNAPSHOT means still in development |
Click Create and Maven generates the project.
Step 3: the pom.xml
The project opens on pom.xml. You'll see the three coordinates (together they're the project's address) and, under properties, compiler settings: source and target 25, so Maven compiles for Java 25, and files read as UTF-8. If IntelliJ says Maven build scripts found, click Load Maven Project. The Run window shows BUILD SUCCESS. There's no Java code yet.
Step 4: add the class
You can create the class by hand. The lecture asks the AI agent in the chat panel instead, with the prompt "create a very simple hello world application out of this Maven project". (If you haven't set that up, see using an AI agent inside IntelliJ.) It creates the Maven folders src/main/java/org/studyeasy and HelloWorld.java inside them: the program you saw at the top.
Three things to notice in that code:
package org.studyeasy;matches the foldersorg/studyeasy.public class HelloWorldhas the same name as the file,HelloWorld.java.mainis where the program starts. Its one line prints the text.
Step 5: run it
Click the green Run button in the toolbar, or the green arrow next to main:
Hello, World!
Process finished with exit code 0
Exit code 0 means no error. A target folder has appeared: that's where the compiled HelloWorld.class goes. The M icon on the right edge opens the Maven tool window; under Lifecycle you'll find package.
mvn package, line by line
> mvn package
[INFO] Building HelloWorld 1.0-SNAPSHOT
[INFO] --- compiler:3.15.0:compile @ HelloWorld ---
[INFO] Compiling 1 source file with javac [debug target 25] to target\classes
[INFO] --- surefire:3.5.4:test @ HelloWorld ---
[INFO] No tests to run.
[INFO] --- jar:3.5.0:jar @ HelloWorld ---
[INFO] Building jar: target\HelloWorld-1.0-SNAPSHOT.jar
[INFO] BUILD SUCCESS
- The compiler plugin compiles one source file with
javacintotarget\classes. - The surefire plugin runs the tests. There are none yet, so "No tests to run".
- The jar plugin packs everything into
HelloWorld-1.0-SNAPSHOT.jar.
That jar runs with the plain java command:
> java -cp target\HelloWorld-1.0-SNAPSHOT.jar org.studyeasy.HelloWorld
Hello, World!
Double-clicking package under Lifecycle in IntelliJ's Maven window runs the same steps and builds the same jar.
Common mistakes
- A space in the artifactId. IntelliJ turns the field red. Use one word:
HelloWorld. - Class name doesn't match the file. A
public class HelloWorldmust live inHelloWorld.java. - Package doesn't match the folders.
package org.studyeasy;means the file sits inorg/studyeasy. - Running by the short name.
java -cp out HelloWorldfails; useorg.studyeasy.HelloWorld.
Recap
| Piece | Job |
|---|---|
javac | Compiles .java source into .class bytecode |
java | Starts the JVM and runs main |
pom.xml | Coordinates, settings and the libraries you need |
| Maven folders | src/main/java, src/test/java, target |
mvn package | Compile, test, then build the jar |
Next: variables, keywords and naming, and later the pom.xml and the Maven lifecycle in more depth.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE
Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)Related posts
Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
Install JDK 25 (Microsoft Build of OpenJDK) with JAVA_HOME, install IntelliJ IDEA, then point a run configuration at the JDK and the main class and run Hello World.
Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
Open IntelliJ's AI Chat, pick Claude Agent (the agent behind Claude Code) or Copilot and a model, ask in plain words for Main.java to print the date and time, review the change, and run it.
Java Variables, Keywords and Naming Rules
A variable is a labelled jar that holds one value at a time. Four small programs show declaring, reassigning, the names Java accepts, the keywords it reserves, and why daysUntilLaunch beats d.
Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
Open a plain project and a Maven project in IntelliJ, read an invoice app's pom.xml, follow jackson-databind from Maven Central into ~/.m2, and see why each lifecycle phase runs the ones before it.
