20 min read

5 Easy Java Projects For Beginners (With Code)

Article Summary

Discover five easy Java projects for absolute beginners, including a temperature converter, number guessing game, calculator, quiz game, and inventory tracker. Each project includes working code, clear explanations, and practical challenges to help you build your Java programming skills step by step.

Key takeaways

  • Start with small, console-based Java projects before trying graphical applications.
  • Add a few new concepts with each project, building on what you’ve already learned.
  • Learn by running the sample code, changing it, and observing the results.
  • You can build all five projects using Java’s standard library, without additional frameworks.
  • Save your finished projects on GitHub to begin building a programming portfolio.

Learning Java is easier when you put what you’ve learned into practice. And you don’t need to build a complex application to get started. Some of the best Java projects for beginners are small programs that help you understand how code works.

If you’ve recently started learning Java, building a number guessing game, temperature converter, or simple calculator can help you practice essential programming skills, including variables, loops, methods, and conditional statements.

In this guide, you’ll find five easy Java projects for beginners. Each project includes working sample code, an explanation of what you’ll learn, and ideas for making your application more challenging as your skills improve.

Why should beginners build Java projects?

When you’re learning a programming language, reading tutorials and watching videos can help you understand syntax. But building projects gives you the opportunity to use that knowledge to solve problems.

Java projects can help you develop several foundational skills:

  • Problem-solving: Break a larger task into smaller steps your program can follow.
  • Programming fundamentals: Practice variables, data types, operators, loops, and conditions.
  • Debugging: Identify why your program isn’t behaving as expected and learn how to fix it.
  • Input validation: Make sure your program can handle unexpected user input.
  • Code organization: Learn to write readable code and, eventually, organize it into reusable methods and classes.

You don’t need to understand everything about Java before starting your first project. If you’re familiar with variables, basic arithmetic, and if statements, you’re ready for Project 1. The later projects add loops, switch statements, arrays, and ArrayList one step at a time, so check each project’s “What you’ll learn” list. If you haven’t met loops yet, read up on while and for loops before Project 2.

How to set up Java for your first project 

Before writing your first application, you’ll need a Java Development Kit (JDK) and a place to write your code.

Step 1: Install a Java Development Kit

The JDK includes the tools needed to compile and run Java programs. As of November 2026, Java 27 is the latest feature release, while Java 25 is the latest long-term support (LTS) release.

For beginners, Java 25 LTS is a practical choice because it provides a modern Java development environment with long-term support. You can download a JDK from Eclipse Temurin or Oracle.

After installation, open your terminal and enter:

java -version

Then check the Java compiler:

javac -version

These commands should display the installed Java version. Ideally, both should report Java 25.

Step 2: Choose a code editor or IDE

An integrated development environment (IDE) helps you write, run, and debug code. Popular options include IntelliJ IDEA, Eclipse, and Visual Studio Code with Java extensions.

For your first projects, choose whichever environment feels most comfortable. You don’t need advanced development tools to complete the examples in this article.

Step 3: Run your first Java program

Create a file called HelloWorld.java and add:

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello, Java!");

    }

}

Save the file. Open a terminal in the folder containing it and run:

javac HelloWorld.java

java HelloWorld

You should see:

Hello, Java!

The javac command compiles your source code and the java command runs the compiled program.

All five projects below follow this same approach. Save each code example in a file with the filename provided, compile it using javac, and run it using java.

Tip: Java 25 also supports simpler ways to write small programs, including compact source files. However, these examples use the traditional class and main() structure because you’ll see it frequently in Java tutorials and existing projects.

5 Java projects for beginners 

These projects are listed roughly from simplest to most involved. Each one builds on skills from the one before it, so working through them in order is a good way to learn.

ProjectDifficultyWhat you’ll practice
1. Temperature converterVery easyVariables, formulas, user input
2. Number guessing gameEasyRandom numbers, loops, conditions, error handling
3. Simple calculatorEasyArithmetic, switch statements, validation
4. Quiz gameEasyArrays, loops, scoring
5. Inventory trackerEasyArrayList, menus, adding and viewing data

You don’t need to build graphical interfaces or connect to external services to complete these projects. Everything runs in your terminal.

1. Create a temperature converter

A temperature converter is a great first Java project. It lets you practice calculations and user input. For your first version, create a program that asks the user for a temperature in Celsius and converts it to Fahrenheit.

The conversion formula is:

Fahrenheit = (Celsius × 9/5) + 32

For example, 0°C equals 32°F, and 100°C equals 212°F.

What you’ll learn

  • Store decimal values using the double data type.
  • Use arithmetic operators.
  • Read numbers from the user with Scanner and check them with hasNextDouble().
  • Display formatted output using System.out.printf().
  • Check whether input is valid.
  • Write a small method, toFahrenheit, that does one job and can be reused.

Java code example

Create TemperatureConverter.java:

import java.util.Scanner;

public class TemperatureConverter {

    // Converts a Celsius temperature to Fahrenheit.
    static double toFahrenheit(double celsius) {
        return celsius * 9.0 / 5.0 + 32;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter a temperature in Celsius: ");

        // hasNextDouble() checks that the next input is a valid number
        // before we try to read it.
        if (!scanner.hasNextDouble()) {
            System.out.println("Please enter a number, such as 20 or -5.5.");
            return;
        }

        double celsius = scanner.nextDouble();

        if (!Double.isFinite(celsius) || celsius < -273.15) {
            System.out.println("Enter a temperature at or above -273.15 C.");
            return;
        }

        System.out.printf("%.1f C = %.1f F%n", celsius, toFahrenheit(celsius));
    }
}

Run the program:

javac TemperatureConverter.java

java TemperatureConverter

Example output:

Enter a temperature in Celsius: 25

25.0 C = 77.0 F

How the code works

The toFahrenheit method holds the conversion formula. It takes a Celsius value and returns the Fahrenheit result, so main stays short and you can reuse the formula later.

In main, a Scanner reads the user’s input. First, hasNextDouble() checks that the input is a valid number. If it isn’t, the program prints a message and stops. Otherwise, nextDouble() reads the number into a double variable.

An if statement then rejects values below absolute zero (-273.15°C) and values that aren’t finite, such as Infinity.

Finally, System.out.printf() prints the result. Each %.1f is replaced by one of the values that follow it, in order, rounded to one decimal place, and %n starts a new line.

Note: Scanner and printf follow your computer’s regional settings. In regions that use a decimal comma, type 20,5 instead of 20.5.

Challenge yourself

Extend your application by:

  • Adding Fahrenheit-to-Celsius conversion.
  • Creating a menu for choosing the conversion direction.
  • Supporting Kelvin as a third temperature unit.
  • Allowing users to perform several conversions without restarting the program.

Beginner tip: Test your converter with 0°C, 100°C, and -40°C. The last example is interesting because -40°C equals -40°F.

2. Build a number guessing game

A great next Java project is a number guessing game because it combines several fundamental concepts without requiring much code.

The program generates a random number and asks the player to guess it. After each incorrect guess, it provides a hint and lets the player try again.

For this version, the player gets five attempts to guess a number between 1 and 20.

What you’ll learn

  • Generate random numbers using Random.
  • Repeat actions using a while loop.
  • Compare numbers using conditional statements.
  • Read user input using Scanner.
  • Handle invalid input without immediately crashing the program.

Java code example

Create a file called GuessingGame.java:

import java.util.Random;
import java.util.Scanner;

public class GuessingGame {
    public static void main(String[] args) {
        // "final" means these values can't change while the program runs.
        // Edit them here to change the game everywhere at once.
        final int maxNumber = 20;
        final int maxAttempts = 5;

        int secret = new Random().nextInt(1, maxNumber + 1);
        Scanner scanner = new Scanner(System.in);
        int attempts = 0;

        System.out.println("Guess a number from 1 to " + maxNumber
                + ". You have " + maxAttempts + " tries.");

        while (attempts < maxAttempts) {
            System.out.print("Your guess: ");

            if (!scanner.hasNextLine()) {
                System.out.println("\nInput ended. Goodbye!");
                return;
            }

            String input = scanner.nextLine();
            int guess;

            try {
                guess = Integer.parseInt(input.trim());
            } catch (NumberFormatException e) {
                System.out.println("Please enter a whole number.");
                continue;
            }

            if (guess < 1 || guess > maxNumber) {
                System.out.println("Choose a number from 1 to " + maxNumber + ".");
                continue;
            }

            attempts++;

            if (guess == secret) {
                System.out.println("Correct! You needed " + attempts + " tries.");
                return;
            }

            System.out.println(guess < secret ? "Try higher." : "Try lower.");
        }

        System.out.println("Game over! The number was " + secret + ".");
    }
}

Run it using:

javac GuessingGame.java

java GuessingGame

How the code works

Two final variables, maxNumber and maxAttempts, set the game’s rules. final means the value can’t change while the program runs, so you can edit it in one place to change the game everywhere.

new Random().nextInt(1, maxNumber + 1) picks the secret number. The upper limit is excluded, so this gives a number from 1 through maxNumber. This two-argument form requires Java 17 or later.

A while loop runs until the player is out of attempts. In each round, Integer.parseInt() converts the typed text to a whole number. If that fails, the catch block shows a message, and continue skips to the next round. An if statement does the same for numbers outside the allowed range. Only after both checks does attempts++ count the guess, so invalid input never uses up an attempt.

A correct guess ends the game with return. Otherwise, a ternary expression (condition ? valueIfTrue : valueIfFalse) picks the hint, “Try higher.” or “Try lower.”

Beginner tip: Change maxAttempts from 5 to 3. Both the loop and the opening message update automatically. Can you spot why?

Challenge yourself

Once your game works, try adding:

  • Three difficulty levels with different number ranges.
  • A replay option so players can start a new game.
  • A high-score system that records the fewest attempts needed to win.

3. Make a simple Java calculator

A calculator lets you practice arithmetic while learning how a program can perform different actions based on user input.

For this project, you’ll build a command-line calculator that supports addition, subtraction, multiplication, and division.

Unlike a graphical calculator, this version doesn’t require windows, buttons, or extra libraries. That makes it a manageable project for beginners.

What you’ll learn

  • Accept multiple inputs from a user.
  • Use arithmetic operators such as +, -, *, and /.
  • Select an action using a switch statement.
  • Handle common errors, including division by zero.
  • Work with decimal numbers.
  • Write a helper method that reads and checks a number, so you don’t repeat the same code twice.

Java code example

Create a file called SimpleCalculator.java:

import java.util.Scanner;

public class SimpleCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double first = readNumber(scanner, "First number: ");

        System.out.print("Operation (+, -, *, /): ");
        if (!scanner.hasNext()) {
            endOfInput();
        }
        String operation = scanner.next();

        double second = readNumber(scanner, "Second number: ");

        double result;

        switch (operation) {
            case "+":
                result = first + second;
                break;
            case "-":
                result = first - second;
                break;
            case "*":
                result = first * second;
                break;
            case "/":
                if (second == 0) {
                    System.out.println("Cannot divide by zero.");
                    return;
                }
                result = first / second;
                break;
            default:
                System.out.println("Unknown operation.");
                return;
        }

        if (!Double.isFinite(result)) {
            System.out.println("Result is outside the supported range.");
            return;
        }

        System.out.println("Result: " + result);
    }

    // Keeps asking until the user types a finite number.
    static double readNumber(Scanner scanner, String prompt) {
        System.out.print(prompt);

        while (true) {
            if (scanner.hasNextDouble()) {
                double value = scanner.nextDouble();
                if (Double.isFinite(value)) {
                    return value;
                }
                System.out.print("Enter a finite number: ");
            } else if (scanner.hasNext()) {
                scanner.next(); // discard the text that wasn't a number
                System.out.print("That isn't a number. Try again: ");
            } else {
                endOfInput();
            }
        }
    }

    // Runs if the input stream closes (for example, Ctrl+D).
    static void endOfInput() {
        System.out.println("\nInput ended. Goodbye!");
        System.exit(0);
    }
}

Compile and run:

javac SimpleCalculator.java

java SimpleCalculator

Example:

First number: 12

Operation (+, -, *, /): *

Second number: 3

Result: 36.0

How the code works

The calculator asks for two numbers and an operation, then uses a switch statement to pick the calculation. Entering *, for example, selects multiplication.

The helper method readNumber reads each number. It keeps asking until the user types a valid, finite number, so a typo doesn’t end the program. Because both numbers need the same checks, writing the logic once as a method avoids repeating it.

The program checks for division by zero before dividing, and it also checks that the result is finite. A very large result, such as 1e308 * 10, would otherwise display as Infinity.

For this exercise, double is fine for practicing arithmetic. But floating-point numbers can’t represent every decimal exactly: 0.1 + 0.2 gives 0.30000000000000004. If you later build programs that handle money, learn about Java’s BigDecimal class.

Beginner tip: Enter an unsupported operation, such as ^. Does your calculator show the expected error message?

Challenge yourself

Once the basic calculator works, try:

  • Adding percentage calculations.
  • Supporting powers and square roots with the Math class.
  • Creating a calculation history.
  • Letting users perform repeated calculations using a loop.

4. Develop a Java quiz game

A quiz game introduces a new challenge: working with groups of information. Instead of processing just one number or calculation, your application needs to display multiple questions, check answers, and calculate a final score.

For this beginner version, you’ll build a short multiple-choice quiz about Java fundamentals.

What you’ll learn

  • Store related information in arrays.
  • Repeat tasks using a for loop.
  • Compare text using equalsIgnoreCase().
  • Track a score with an integer variable.
  • Use an array’s length to control a loop.
  • Write a method that keeps asking until the player gives a valid answer.

Java code example

Create QuizGame.java:

import java.util.Scanner;

public class QuizGame {
    public static void main(String[] args) {
        String[] questions = {
            "Which keyword declares an integer? (a) String (b) int (c) boolean",
            "Which symbol means multiplication? (a) * (b) + (c) /",
            "Which value is a boolean? (a) 10 (b) hello (c) true"
        };

        // Keep the two arrays in the same order:
        // answers[i] is the correct answer for questions[i].
        String[] answers = {"b", "a", "c"};

        Scanner scanner = new Scanner(System.in);
        int score = 0;

        for (int i = 0; i < questions.length; i++) {
            System.out.println(questions[i]);

            String response = askForChoice(scanner);
            if (response == null) {
                System.out.println("\nInput ended. Goodbye!");
                return;
            }

            if (response.equalsIgnoreCase(answers[i])) {
                score++;
                System.out.println("Correct!");
            } else {
                System.out.println("Not quite. Correct answer: " + answers[i]);
            }
        }

        System.out.println("Final score: " + score + "/" + questions.length);
    }

    // Keeps asking until the player types a, b, or c.
    // Returns null if the input ends before an answer is given.
    static String askForChoice(Scanner scanner) {
        while (true) {
            System.out.print("Your answer (a, b, or c): ");

            if (!scanner.hasNextLine()) {
                return null;
            }

            String response = scanner.nextLine().trim();

            if (response.length() == 1 && "abc".contains(response.toLowerCase())) {
                return response;
            }
            System.out.println("Please type a, b, or c.");
        }
    }
}

Run it:

javac QuizGame.java

java QuizGame

If the user answers all three questions correctly, the final output is:

Final score: 3/3

How the code works

This project uses two arrays: one holds the questions and the other holds the correct answers. Each question and its answer share the same position, called an index. Java arrays start at index 0, so questions[0] goes with answers[0]. Keep the arrays in the same order, or answers will no longer match their questions.

A for loop shows each question, then calls the helper method askForChoice. This method keeps asking until the player types a, b, or c, so a typo or blank answer doesn’t count as a wrong answer. If the input ends, it returns null and the program exits cleanly.

equalsIgnoreCase() compares the player’s answer with the correct one, ignoring uppercase and lowercase. Each correct answer adds one to score, and the final score is shown at the end.

Beginner tip: Add a fourth question. Remember to add its correct answer to the second array, too.

Challenge yourself

Make your quiz more interesting by:

  • Adding more questions.
  • Creating quizzes on different subjects.
  • Shuffling the questions.
  • Calculating the score as a percentage.
  • Adding a timer for each question.

5. Build a basic inventory tracker

An inventory tracker is a practical beginner Java project that introduces the idea of managing a collection of items. You could use it to track books, school supplies, games, or household items.

For your first version, you’ll create a program that lets users add items, display their inventory, and exit through a simple text menu. Unlike the previous examples, this program continues running until the user chooses to quit.

What you’ll learn

  • Store information in an ArrayList.
  • Add new elements to a collection.
  • Retrieve elements using their positions.
  • Create an interactive menu using a loop.
  • Use a switch statement to process menu choices.

Java code example

Create InventoryTracker.java:

import java.util.ArrayList;
import java.util.Scanner;

public class InventoryTracker {
    public static void main(String[] args) {
        ArrayList<String> items = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("\n1. Add item  2. View items  3. Quit");
            System.out.print("Choose 1, 2, or 3: ");

            String choice = readLine(scanner);
            if (choice == null) {
                System.out.println("\nInput ended. Goodbye!");
                return;
            }

            switch (choice) {
                case "1": {
                    System.out.print("Item name: ");
                    String item = readLine(scanner);

                    if (item == null) {
                        System.out.println("\nInput ended. Goodbye!");
                        return;
                    }

                    if (item.isEmpty()) {
                        System.out.println("Item name cannot be empty.");
                    } else {
                        items.add(item);
                        System.out.println("Added: " + item);
                    }
                    break;
                }

                case "2": {
                    if (items.isEmpty()) {
                        System.out.println("No items yet.");
                    } else {
                        for (int i = 0; i < items.size(); i++) {
                            System.out.println((i + 1) + ". " + items.get(i));
                        }
                    }
                    break;
                }

                case "3":
                    System.out.println("Goodbye!");
                    return;

                default:
                    System.out.println("Please choose 1, 2, or 3.");
            }
        }
    }

    // Returns the next line of input without extra spaces,
    // or null if the input has ended.
    static String readLine(Scanner scanner) {
        return scanner.hasNextLine() ? scanner.nextLine().trim() : null;
    }
}

Run the application:

javac InventoryTracker.java

java InventoryTracker

After adding two items, your inventory might look like this:

1. Notebook

2. Pencil

How the code works

This project introduces ArrayList, a collection that grows as you add items. Unlike an array, it doesn’t have a fixed length.

A while (true) loop keeps showing the menu until the user quits. A switch statement handles each choice:

  • Option 1 adds an item with items.add(). The program rejects blank names.
  • Option 2 displays the inventory using a for loop and items.get().
  • Option 3 ends the program with return.

The helper method readLine returns the next line of input with extra spaces removed, or null if the input has ended. The program checks for null so it can exit cleanly. The braces { } around each case keep variables like item local to that case.

Limitation: The inventory is stored in memory, so it disappears when the program closes. That’s fine for a first project, and it’s a good reason to learn file handling later.

Beginner tip: Add three items and view them. Then explore ArrayList.remove() and try building an option to delete an item.

Challenge yourself

Extend the tracker by adding:

  • An option to remove items.
  • A search feature.
  • A quantity for each item.
  • Categories such as books, stationery, and electronics.
  • File storage so the inventory is available after restarting the program.

How to learn more from your Java beginner projects

Finishing a project is valuable, but experimenting with it can teach you even more. Here are a few habits that can help you get the most out of these exercises.

1. Understand the code before changing it

Avoid simply copying code and moving on. Instead, look at each section and ask what it does. For example, in the number guessing game, what happens if you change the maximum number of attempts? What happens if you change the random number range?

Small experiments can help you become more comfortable reading and modifying Java code.

2. Test your program with unexpected input

A program should do more than work under perfect conditions. Try typing letters where a number is expected, submitting empty answers, or choosing menu options that don’t exist. You can also end the input stream: press Ctrl+D on macOS or Linux, or Ctrl+Z then Enter on Windows. Does your program exit politely, or crash with an error?

Note: Your IDE may warn that the Scanner is never closed. For these small programs that’s harmless; you’ll learn how to close resources properly later.

3. Learn to debug your code

When something goes wrong, read the error message and identify the relevant line. You can also use System.out.println() to display variable values while your program runs. As your projects grow, consider using your IDE’s debugger to inspect variables and execute your code one line at a time.

4. Save your projects on GitHub

Once you’ve completed a project, consider uploading it to GitHub. Include a short README explaining:

  • What the project does.
  • Which Java version it uses.
  • How to compile and run it.
  • What you learned while building it.
  • What features you’d like to add next.

You can begin with these five projects and gradually improve them as you become more experienced.

Learn Java with Udemy

Building projects is one of the best ways to practice Java, but a structured course can help you understand the concepts behind the code and decide what to learn next. For example, Mastering Modern Java Programming: Beginner to Pro course on Udemy is designed to take learners from Java fundamentals into more advanced programming topics.

The course begins with the basics, including setting up Java, understanding data types, writing methods, and working with classes. It then explores more complex concepts that can help you build larger applications.

The course also includes more than 100 coding exercises, giving you opportunities to practice the material rather than relying on lectures alone. Its updated curriculum includes coverage through Java 25.

Ready to build your Java skills? Explore Mastering Modern Java Programming: Beginner to Pro [2026] or check for any other Java courses for beginners on Udemy.

FAQ

Which Java project is best for absolute beginners?

A temperature converter is the gentlest starting point: it’s short, and it needs only one formula and basic input and output. Once it works, a number guessing game adds loops and error handling. If you’re completely new to programming, start with a small Hello World program first.

Can I build Java projects without knowing object-oriented programming?

Yes. You can build simple Java console applications before learning advanced object-oriented programming concepts.

Which Java version should beginners use in 2026?

Java 25 LTS is a practical choice for learners in 2026 because it provides a modern development environment with long-term support. Java 27 is the latest feature release as of November 2026.

Do I need to learn JavaFX or Swing to build Java projects?

No. JavaFX and Swing are tools for building graphical applications, but you don’t need either one to create console-based programs. Starting with console applications allows you to focus on programming logic before learning how to design windows and handle graphical events.

How long does it take to complete a beginner Java project?

It depends on your familiarity with programming and the features you want to include. A small temperature converter or guessing game may take only a few focused practice sessions. A project that includes several menu options, data storage, or additional features will usually take longer. Focus on understanding and completing each feature rather than finishing as quickly as possible.

Can I add beginner Java projects to my GitHub portfolio?

Yes. Even small Java projects can help demonstrate your progress, especially when you include clear documentation and explain what you’ve learned. As you gain experience, you can return to your earlier projects and improve them with better validation, testing, file storage, or more advanced functionality.