Time to write and run your first Java code inside the Maven project you just created.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Java is installed and working!");
System.out.println("You are ready to start learning.");
}
}public static void main)Hello, World!
Java is installed and working!
You are ready to start learning.If you see this output, congratulations — your entire setup is working: JDK compiles the code, IntelliJ runs it, and the output is displayed.
| Code | What It Means |
|---|---|
| public class HelloWorld | Defines a class named HelloWorld — file name must match class name |
| public static void main(String[] args) | The entry point — Java always starts execution from this method |
| System.out.println("...") | Prints text to the console and adds a newline |
| { } | Curly braces define the start and end of a block |
| ; | Every statement ends with a semicolon |
public class QuickMath {
public static void main(String[] args) {
int a = 10;
int b = 3;
System.out.println("Sum: " + (a + b));
System.out.println("Difference: " + (a - b));
System.out.println("Product: " + (a * b));
System.out.println("Division: " + (a / b));
System.out.println("Remainder: " + (a % b));
}
}Create this file the same way: right-click java folder → New → Java Class → name it QuickMath → paste the code → click the green play button.
| Problem | Fix |
|---|---|
| No green play button appears | Make sure the file is inside src/main/java and the class has a `main` method |
| "Cannot resolve symbol" errors | File → Invalidate Caches → Invalidate and Restart |
| "Class not found" when running | Right-click project root → Maven → Reload Project |
| Red underlines everywhere | Check that JDK 17 is set in File → Project Structure → Project SDK |
| Code runs but no output | Check that you used println (not just print) and that there are no compilation errors in the Problems tab |
Exercise 1: Modify HelloWorld.java to print your name, your city, and today's date on separate lines. Run it.
Exercise 2: Create a new Java class called Calculator. Write code that calculates 15% discount on a price of 1299, then adds 18% GST on the discounted price. Print each step.
Exercise 3: Create a class called PersonalInfo that stores your name, age, and email in variables, then prints them in a formatted way: "Name: ..., Age: ..., Email: ..."
Answer all 5 questions, then submit to see your score.
1. What is the difference between JDK and JRE?
2. Which JDK version should you install for this course?
3. Where should you download JDK 17 from?
4. What does Maven do?
5. What file defines Maven project dependencies?