Java Number Guess Game

Su Suriya Ravichandran Updated 18 Nov 2026
17 min read ·Lesson 296 of 306

A Java number guess game picks a secret number and lets the player guess it, answering "higher" or "lower" after each try. It is a perfect second project because it combines random numbers, loops, conditions, input validation and enums in one small program. Along the way you also learn a real algorithm: binary search, the fastest way to find the number.

This project continues from the Java Calculator App and reuses its read-validate-repeat loop. You start by generating a secret number and finish with number-guess-game.jar, a game with three difficulty levels, limited attempts, best scores and a --seed option for repeatable testing. All examples were run on JDK 21.


Generate the Secret Number in Java

The game needs a random whole number in a fixed range, such as 1 to 100. Java offers several generators, covered in detail in Java Random Numbers.

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class SecretNumber {
    public static void main(String[] args) {
        // a seeded Random gives the same numbers every run (good for testing)
        Random seeded = new Random(42);
        System.out.print("Seeded Random(42): ");
        for (int i = 0; i < 5; i++) {
            System.out.print(seeded.nextInt(1, 101) + " ");
        }
        System.out.println();

        // an unseeded generator gives different numbers every run
        int secret = ThreadLocalRandom.current().nextInt(1, 101);
        System.out.println("Secret is between 1 and 100: " + (secret >= 1 && secret <= 100));

        // the old formula with Math.random()
        int oldStyle = (int) (Math.random() * 100) + 1;
        System.out.println("Math.random() style in range: " + (oldStyle >= 1 && oldStyle <= 100));
    }
}
Seeded Random(42): 31 64 49 85 71 
Secret is between 1 and 100: true
Math.random() style in range: true
Way to get 1-100Repeatable?Notes
new Random(seed).nextInt(1, 101)Yes, same seed gives same numbersUse for tests and demos
ThreadLocalRandom.current().nextInt(1, 101)NoFast, good default for games
RandomGenerator.getDefault().nextInt(1, 101)NoModern interface (Java 17+)
(int) (Math.random() * 100) + 1NoOlder style, easy to get the range wrong

How it works:

  • nextInt(1, 101) returns a number from 1 up to but not including 101, so 100 is the largest possible value.
  • A seed is the starting value of the generator. new Random(42) produces 31, 64, 49, 85, 71 on every computer, every time. The final game uses this to make test sessions repeatable.
  • Math.random() returns a double from 0.0 to just below 1.0. Multiplying by 100, casting to int and adding 1 gives 1 to 100.

Compare a Guess With Higher or Lower Hints

Each guess has exactly three outcomes, so an enum describes them clearly. A method compares the guess to the secret and returns the hint.

public class CompareGuess {
    enum Hint { TOO_LOW, TOO_HIGH, CORRECT }

    static Hint check(int guess, int secret) {
        if (guess < secret) return Hint.TOO_LOW;
        if (guess > secret) return Hint.TOO_HIGH;
        return Hint.CORRECT;
    }

    public static void main(String[] args) {
        int secret = 64;
        int[] guesses = {50, 75, 62, 68, 64};
        int attempts = 0;

        for (int guess : guesses) {
            attempts++;
            Hint hint = check(guess, secret);
            String message = switch (hint) {
                case TOO_LOW -> "Too low";
                case TOO_HIGH -> "Too high";
                case CORRECT -> "Correct!";
            };
            System.out.println("Guess " + attempts + ": " + guess + " -> " + message);
            if (hint == Hint.CORRECT) {
                System.out.println("Found it in " + attempts + " attempts.");
                break;
            }
        }
    }
}
Guess 1: 50 -> Too low
Guess 2: 75 -> Too high
Guess 3: 62 -> Too low
Guess 4: 68 -> Too high
Guess 5: 64 -> Correct!
Found it in 5 attempts.

How it works:

  • check contains only the comparison logic. It does not print anything, which keeps it easy to reuse and test.
  • The switch expression covers all three enum constants, so no default is needed. If you add a fourth constant later, the compiler reports the missing case.
  • break ends the loop as soon as the guess is correct. The fixed array of guesses stands in for a player while you develop the logic.

Read Guesses Safely With Scanner

Real players type mistakes: words, decimals, numbers outside the range. A helper method keeps asking until it gets a valid whole number, the same pattern as in the calculator project and the Java While Loop lesson.

import java.util.Scanner;

public class ReadGuess {
    static final int MIN = 1;
    static final int MAX = 100;

    // keeps asking until the user types a whole number inside the range
    static int readGuess(Scanner scanner) {
        while (true) {
            System.out.print("Your guess (" + MIN + "-" + MAX + "): ");
            String text = scanner.nextLine().strip();
            try {
                int value = Integer.parseInt(text);
                if (value < MIN || value > MAX) {
                    System.out.println("  Please stay between " + MIN + " and " + MAX + ".");
                    continue;
                }
                return value;
            } catch (NumberFormatException e) {
                System.out.println("  '" + text + "' is not a whole number.");
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int guess = readGuess(scanner);
        System.out.println("You guessed " + guess);
    }
}
Your guess (1-100): fifty
  'fifty' is not a whole number.
Your guess (1-100): 150
  Please stay between 1 and 100.
Your guess (1-100): 42.5
  '42.5' is not a whole number.
Your guess (1-100): 42
You guessed 42

How it works:

  • Integer.parseInt throws NumberFormatException for fifty and 42.5, because neither is a whole number. The catch prints a message and the loop repeats.
  • 150 parses fine but fails the range check. continue jumps back to the top of the loop and asks again.
  • Only a valid value reaches return, so the code that calls readGuess never has to check the input again.

Note: Reading the whole line with nextLine() and parsing it yourself is safer than nextInt(). With nextInt(), a word like fifty stays in the input buffer and causes an endless loop of errors.


Limit Attempts With Difficulty Levels

A game without a limit is never lost. An enum stores each difficulty level together with its range and its number of attempts.

public class LimitedAttempts {
    enum Difficulty {
        EASY(50, 10), MEDIUM(100, 7), HARD(1000, 10);

        final int maxNumber;
        final int maxAttempts;

        Difficulty(int maxNumber, int maxAttempts) {
            this.maxNumber = maxNumber;
            this.maxAttempts = maxAttempts;
        }
    }

    static boolean play(Difficulty level, int secret, int[] guesses) {
        System.out.println(level + ": 1-" + level.maxNumber + ", " + level.maxAttempts + " attempts");
        int attemptsLeft = level.maxAttempts;
        for (int guess : guesses) {
            if (attemptsLeft == 0) break;
            attemptsLeft--;
            if (guess == secret) {
                System.out.println("  " + guess + " is correct! Attempts left: " + attemptsLeft);
                return true;
            }
            String direction = guess < secret ? "higher" : "lower";
            System.out.println("  " + guess + " -> go " + direction + " (" + attemptsLeft + " left)");
        }
        System.out.println("  Out of attempts. The number was " + secret);
        return false;
    }

    public static void main(String[] args) {
        play(Difficulty.MEDIUM, 37, new int[] {50, 25, 37});
        play(Difficulty.MEDIUM, 91, new int[] {10, 20, 30, 40, 50, 60, 70, 80});
    }
}
MEDIUM: 1-100, 7 attempts
  50 -> go lower (6 left)
  25 -> go higher (5 left)
  37 is correct! Attempts left: 4
MEDIUM: 1-100, 7 attempts
  10 -> go higher (6 left)
  20 -> go higher (5 left)
  30 -> go higher (4 left)
  40 -> go higher (3 left)
  50 -> go higher (2 left)
  60 -> go higher (1 left)
  70 -> go higher (0 left)
  Out of attempts. The number was 91
LevelRangeAttemptsGuesses a perfect player needs
EASY1-5010at most 6
MEDIUM1-1007at most 7
HARD1-100010at most 10

How it works:

  • Each enum constant passes its values to the constructor, so Difficulty.MEDIUM.maxAttempts is 7. All game rules live in one place.
  • attemptsLeft counts down with every guess. When it reaches 0, the loop stops and the player loses.
  • Counting up by tens (the second game) wastes guesses. The next section shows why 7 attempts are always enough for 1 to 100 with the right strategy.

Binary Search: The Best Number Guessing Strategy

The smartest strategy is to always guess the middle of the remaining range. Each answer removes half of the possible numbers. This is binary search, the same idea Arrays.binarySearch uses on sorted arrays.

public class ComputerGuesser {
    // the computer finds the secret by always guessing the middle of the range
    static int solve(int low, int high, int secret) {
        int attempts = 0;
        while (low <= high) {
            int guess = low + (high - low) / 2;   // middle, without int overflow
            attempts++;
            System.out.printf("  try %d: range %d-%d, guess %d%n", attempts, low, high, guess);
            if (guess == secret) return attempts;
            if (guess < secret) low = guess + 1;   // secret is in the upper half
            else high = guess - 1;                  // secret is in the lower half
        }
        throw new IllegalStateException("Secret was outside the range");
    }

    public static void main(String[] args) {
        System.out.println("Secret 73 in 1-100:");
        System.out.println("Solved in " + solve(1, 100, 73) + " attempts");

        for (int max : new int[] {100, 1000, 1_000_000}) {
            int worstCase = 32 - Integer.numberOfLeadingZeros(max); // floor(log2(max)) + 1
            System.out.println("1-" + max + " never needs more than " + worstCase + " guesses");
        }
    }
}
Secret 73 in 1-100:
  try 1: range 1-100, guess 50
  try 2: range 51-100, guess 75
  try 3: range 51-74, guess 62
  try 4: range 63-74, guess 68
  try 5: range 69-74, guess 71
  try 6: range 72-74, guess 73
Solved in 6 attempts
1-100 never needs more than 7 guesses
1-1000 never needs more than 10 guesses
1-1000000 never needs more than 20 guesses

How it works:

  • After a "higher" answer, every number up to the guess is impossible, so low moves to guess + 1. After "lower", high moves to guess - 1.
  • low + (high - low) / 2 finds the middle without overflow. (low + high) / 2 can overflow when both values are close to Integer.MAX_VALUE.
  • 32 - Integer.numberOfLeadingZeros(max) counts the bits in max, which equals the worst-case number of guesses. One million numbers need only 20 guesses, because 2^20 is more than one million.
  • This proves the difficulty table is fair: MEDIUM and HARD give exactly as many attempts as a perfect player needs.

Separate Game Logic From Input and Output

The final game has three classes. The first two contain no Scanner and no System.out, so the rules can be checked without typing anything.

The Difficulty Enum

package com.gocourse.guess;

/** Each level sets the range of the secret number and how many guesses are allowed. */
public enum Difficulty {
    EASY(50, 10),
    MEDIUM(100, 7),
    HARD(1000, 10);

    private final int maxNumber;
    private final int maxAttempts;

    Difficulty(int maxNumber, int maxAttempts) {
        this.maxNumber = maxNumber;
        this.maxAttempts = maxAttempts;
    }

    public int maxNumber() { return maxNumber; }
    public int maxAttempts() { return maxAttempts; }

    /** Accepts "1", "easy", "E" and similar answers. */
    public static Difficulty parse(String text) {
        String value = text.strip().toUpperCase();
        for (Difficulty level : values()) {
            if (value.equals(String.valueOf(level.ordinal() + 1))
                    || level.name().equals(value)
                    || level.name().startsWith(value) && !value.isEmpty()) {
                return level;
            }
        }
        throw new IllegalArgumentException("Choose 1, 2 or 3");
    }
}

How it works:

  • ordinal() is the position of the constant (0, 1, 2), so ordinal() + 1 matches the menu numbers 1, 2 and 3.
  • startsWith(value) lets the player type e, me or HARD. The empty-string check stops a blank line from matching EASY.

The GuessGame Class

package com.gocourse.guess;

import java.util.random.RandomGenerator;

/** One round of the game. It has no Scanner or System.out, so it is easy to test. */
public class GuessGame {
    public enum Result { TOO_LOW, TOO_HIGH, CORRECT, GAME_OVER }

    private final Difficulty difficulty;
    private final int secret;
    private int attemptsUsed = 0;
    private boolean finished = false;

    public GuessGame(Difficulty difficulty, RandomGenerator random) {
        this.difficulty = difficulty;
        this.secret = random.nextInt(1, difficulty.maxNumber() + 1);
    }

    public Result guess(int value) {
        if (finished) {
            throw new IllegalStateException("This round is already over");
        }
        if (value < 1 || value > difficulty.maxNumber()) {
            throw new IllegalArgumentException("Guess between 1 and " + difficulty.maxNumber());
        }
        attemptsUsed++;   // only valid guesses use up an attempt
        if (value == secret) {
            finished = true;
            return Result.CORRECT;
        }
        if (attemptsUsed == difficulty.maxAttempts()) {
            finished = true;
            return Result.GAME_OVER;
        }
        return value < secret ? Result.TOO_LOW : Result.TOO_HIGH;
    }

    public int attemptsUsed() { return attemptsUsed; }
    public int attemptsLeft() { return difficulty.maxAttempts() - attemptsUsed; }
    public boolean isFinished() { return finished; }
    public Difficulty difficulty() { return difficulty; }

    /** Revealed only when the round is over, so the UI cannot leak it early. */
    public int secret() {
        if (!finished) throw new IllegalStateException("No peeking!");
        return secret;
    }
}

How it works:

  • The constructor receives a RandomGenerator instead of creating one. The app passes a real random generator, while tests pass new Random(7) to get a known secret. This technique is called dependency injection.
  • An out-of-range guess throws an exception before attemptsUsed++, so typing mistakes do not cost the player an attempt.
  • The secret field is private and the getter refuses to answer until the round is finished, a small example of encapsulation.

Check the Game Rules Without a Keyboard

Because the logic is separate, a short program can confirm that the rules work.

package com.gocourse.guess;

import java.util.Random;

public class GuessGameCheck {
    public static void main(String[] args) {
        // Random(7) always picks 37 for MEDIUM, so the expected results are known
        GuessGame game = new GuessGame(Difficulty.MEDIUM, new Random(7));
        System.out.println(game.guess(50) + ", attempts left " + game.attemptsLeft());
        System.out.println(game.guess(30) + ", attempts left " + game.attemptsLeft());
        System.out.println(game.guess(37) + ", finished " + game.isFinished());
        System.out.println("secret = " + game.secret());

        try {
            game.guess(40);
        } catch (IllegalStateException e) {
            System.out.println("After the round: " + e.getMessage());
        }

        GuessGame fresh = new GuessGame(Difficulty.EASY, new Random(7));
        try {
            fresh.secret();
        } catch (IllegalStateException e) {
            System.out.println("Before the end: " + e.getMessage());
        }
    }
}
TOO_HIGH, attempts left 6
TOO_LOW, attempts left 5
CORRECT, finished true
secret = 37
After the round: This round is already over
Before the end: No peeking!

How it works:

  • The seed makes the secret predictable, so every line of output can be checked by eye or, later, with JUnit assertions.
  • The two try blocks prove the safety rules: no guessing after the round ends, and no reading the secret before it ends.

Build the Java Number Guess Game Console App

GuessGameApp handles the menu, the input and the best scores. It adds a --seed option so a whole session can be replayed exactly.

package com.gocourse.guess;

import java.util.EnumMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import java.util.random.RandomGenerator;

/** Console front end: java -jar number-guess-game.jar [--seed N] */
public class GuessGameApp {
    private final Scanner scanner = new Scanner(System.in);
    private final RandomGenerator random;
    private final Map<Difficulty, Integer> bestScores = new EnumMap<>(Difficulty.class);

    GuessGameApp(RandomGenerator random) {
        this.random = random;
    }

    public static void main(String[] args) {
        RandomGenerator random = (args.length == 2 && args[0].equals("--seed"))
                ? new Random(Long.parseLong(args[1]))   // repeatable games for testing
                : RandomGenerator.getDefault();
        new GuessGameApp(random).run();
    }

    void run() {
        System.out.println("=== GOCOURSE Number Guess Game ===");
        do {
            Difficulty level = askDifficulty();
            if (level == null) break;
            playRound(new GuessGame(level, random));
        } while (askYesNo("Play again? (y/n): "));
        printBestScores();
        System.out.println("Thanks for playing!");
    }

    private void playRound(GuessGame game) {
        Difficulty level = game.difficulty();
        System.out.printf("I picked a number from 1 to %d. You have %d attempts.%n",
                level.maxNumber(), level.maxAttempts());
        while (!game.isFinished()) {
            String line = readLine("Guess #" + (game.attemptsUsed() + 1) + ": ");
            if (line == null) return;
            try {
                GuessGame.Result result = game.guess(Integer.parseInt(line));
                switch (result) {
                    case TOO_LOW -> System.out.println("  Higher! (" + game.attemptsLeft() + " left)");
                    case TOO_HIGH -> System.out.println("  Lower! (" + game.attemptsLeft() + " left)");
                    case CORRECT -> {
                        System.out.println("  Correct! You needed " + game.attemptsUsed() + " attempts.");
                        recordScore(level, game.attemptsUsed());
                    }
                    case GAME_OVER -> System.out.println("  Out of attempts! It was " + game.secret() + ".");
                }
            } catch (NumberFormatException e) {
                System.out.println("  '" + line + "' is not a whole number.");
            } catch (IllegalArgumentException e) {
                System.out.println("  " + e.getMessage());
            }
        }
    }

    private void recordScore(Difficulty level, int attempts) {
        Integer best = bestScores.get(level);
        if (best == null || attempts < best) {
            bestScores.put(level, attempts);
            System.out.println("  New best score for " + level + "!");
        }
    }

    private Difficulty askDifficulty() {
        while (true) {
            String line = readLine("Difficulty: 1) Easy 2) Medium 3) Hard > ");
            if (line == null) return null;
            try {
                return Difficulty.parse(line);
            } catch (IllegalArgumentException e) {
                System.out.println("  " + e.getMessage());
            }
        }
    }

    private boolean askYesNo(String prompt) {
        String line = readLine(prompt);
        return line != null && line.toLowerCase().startsWith("y");
    }

    private String readLine(String prompt) {
        System.out.print(prompt);
        return scanner.hasNextLine() ? scanner.nextLine().strip() : null;
    }

    private void printBestScores() {
        if (bestScores.isEmpty()) return;
        System.out.println("Best scores:");
        bestScores.forEach((level, attempts) ->
                System.out.println("  " + level + ": " + attempts + " attempts"));
    }
}

How it works:

  • The do ... while loop plays at least one round, then repeats while the player answers y.
  • NumberFormatException is caught before IllegalArgumentException. The order matters because NumberFormatException is a subclass of IllegalArgumentException; reversing them would not compile.
  • EnumMap stores one best score per level and prints them in enum order (EASY, MEDIUM, HARD). A lower attempt count is a better score.
  • readLine returns null when input ends (Ctrl+D), and every caller handles that, so the game never crashes with NoSuchElementException.

Real-World Example: Package and Play number-guess-game.jar

The project layout follows the same structure as the earlier projects:

number-guess-game/
└── src/
    └── com/
        └── gocourse/
            └── guess/
                ├── Difficulty.java
                ├── GuessGame.java
                └── GuessGameApp.java
cd number-guess-game
javac -d out src/com/gocourse/guess/*.java
jar --create --file number-guess-game.jar --main-class com.gocourse.guess.GuessGameApp -C out .
java -jar number-guess-game.jar --seed 7

With seed 7, the first MEDIUM secret is always 37 and the next EASY secret is always 15, so this session can be repeated exactly:

=== GOCOURSE Number Guess Game ===
Difficulty: 1) Easy 2) Medium 3) Hard > 2
I picked a number from 1 to 100. You have 7 attempts.
Guess #1: 50
  Lower! (6 left)
Guess #2: abc
  'abc' is not a whole number.
Guess #2: 200
  Guess between 1 and 100
Guess #2: 25
  Higher! (5 left)
Guess #3: 37
  Correct! You needed 3 attempts.
  New best score for MEDIUM!
Play again? (y/n): y
Difficulty: 1) Easy 2) Medium 3) Hard > 4
  Choose 1, 2 or 3
Difficulty: 1) Easy 2) Medium 3) Hard > easy
I picked a number from 1 to 50. You have 10 attempts.
Guess #1: 25
  Lower! (9 left)
Guess #2: 12
  Higher! (8 left)
Guess #3: 18
  Lower! (7 left)
Guess #4: 15
  Correct! You needed 4 attempts.
  New best score for EASY!
Play again? (y/n): n
Best scores:
  EASY: 4 attempts
  MEDIUM: 3 attempts
Thanks for playing!

A losing round on HARD, played without binary search (seed 1):

=== GOCOURSE Number Guess Game ===
Difficulty: 1) Easy 2) Medium 3) Hard > 3
I picked a number from 1 to 1000. You have 10 attempts.
Guess #1: 1
  Higher! (9 left)
Guess #2: 2
  Higher! (8 left)
...
Guess #10: 10
  Out of attempts! It was 986.
Play again? (y/n): n
Thanks for playing!

How it works:

  1. Invalid input is free. abc and 200 printed errors, but the prompt still said Guess #2, because only valid guesses count as attempts.
  2. Flexible menu input. 2, easy and e all select a level, while 4 shows a clear message and asks again.
  3. Binary search wins. Guessing 50, then 25, then 37 (the middle each time) found the MEDIUM number in 3 attempts. Counting up one by one on HARD ran out after 10.
  4. Repeatable testing. --seed 7 produced the same secrets every run, so the whole session above can be piped from a file with java -jar number-guess-game.jar --seed 7 < session.txt and compared with the expected output.
  5. Clean ending. After the last round, the best scores print in level order and the program exits normally.

The next project, the Java Student Manager, moves from a single number to a whole collection of records, with searching, sorting and saving to a file.

0 Comments

Reviewed before they appear

No comments yet.

Java
Java Introduction Java Features Java Syntax Java Comments Java Statements Java Output Java Variables Java Data Types Java Type Casting Java Operators Java Strings Java Numbers Java Math Java Booleans Java User Input Java Conditions Java If Else Java Switch Java While Loop Java For Loop Java Break Java Continue Java Arrays Java Methods Java Parameters Java Return Values Java Scope Java Recursion Install Java Install JDK Java IDEs Java JDK Java JRE Java JVM Java Compiler Java File Compile Java Run Java JShell Basics Java Packages Java OOP Java Classes Java Objects Class Methods Constructors Constructor Overload this Keyword static Keyword final Keyword Encapsulation Inheritance Polymorphism Abstraction Access Modifiers super Keyword Method Overload Method Override Instanceof Operator Nested Classes Inner Classes Anonymous Classes Enums Records Array Basics Array Length Loop Arrays Multidimensional Arrays Array Copy Array Sorting Array Search ArrayList LinkedList HashSet TreeSet HashMap TreeMap Queue Interface Deque Interface Stack Class Iterator List Interface Set Interface Map Interface Collections Class Comparable Comparator Generics Basics Generic Classes Generic Methods Wildcards String Basics String Length String Methods String Concatenation String Compare String Search String Replace String Split String Format StringBuilder StringBuffer Text Blocks Regular Expressions Number Types Integer Class Float Class Double Class BigInteger BigDecimal Math Class Random Numbers Number Format Date Basics LocalDate LocalTime LocalDateTime ZonedDateTime Date Formatting Date Parsing Period Class Duration Class Java Instant Class Java Exception Basics Java try...catch Java Multiple Catch Blocks Java finally Block Java throw Keyword Java throws Keyword Java Checked Exceptions Java Unchecked Exceptions Java Custom Exceptions Java try-with-resources Java Exception Chaining Java File Basics Java Create Files Java Read Files Java Write Files Java Delete Files Java File Paths Java File Class Java BufferedReader Java BufferedWriter Java FileInputStream Java FileOutputStream Java Object Streams Java Directory Handling Java NIO Basics Java Files API Java Input Java Scanner Class Java Console Input Java PrintStream Java InputStream Java OutputStream Java Reader Class Java Writer Class Java Buffered Streams Java Data Streams Java Generics Introduction Java Generic Types Java Generic Methods Java Bounded Types Java Wildcards Java Type Erasure Java Generic Interfaces Java Generic Collections Java Lambda Basics Java Lambda Syntax Java Functional Interfaces Java Method References Java Stream API Java Stream Creation Java Stream Filter Java Stream Map Java Stream Reduce Java Stream Sort Java Stream Collect Java Collectors Class Java Optional Class Java Parallel Streams Java Threads: Thread Basics Create a Thread in Java Java Thread Class Java Runnable Interface Java Thread States Java Thread Sleep Java Thread Join Java Thread Priority Java Synchronization Java Thread Safety Java Race Conditions Java Deadlocks Java Executor Service Java Thread Pools Java Callable Interface Java Future Interface Java CompletableFuture Java Concurrent Collections Java Atomic Classes Java Virtual Threads Java Networking Basics Java URL Class Java URI Class Java HttpClient Java HTTP Requests Java HTTP Responses Java Socket Basics Java ServerSocket Java DatagramSocket Java WebSocket Basics Java JDBC Basics Java JDBC Setup Java Database Connection Java JDBC Connection Interface Java JDBC Statement Java PreparedStatement Java ResultSet Java JDBC CRUD Operations Java JDBC Transactions Java JDBC Batch Update Java Connection Pooling with HikariCP Java JPA Basics: Entities, EntityManager and JPQL Java Hibernate Basics: SessionFactory, Session and HQL Package in Java: Basics Explained with Examples Create Package in Java: Step-by-Step Guide with Examples Import Package in Java: The import Statement Explained Access Control in Java: Packages, Classes and Members JAR File in Java: Create, Run and Inspect JAR Files Java Modules: Introduction to the Java Module System module-info in Java: Every Module Directive Explained Java Module Path: How --module-path Finds Your Modules Java Classpath: How -cp and CLASSPATH Find Your Classes Java Annotations: Basics of @ Metadata in Java Java Built-in Annotations: @Override, @Deprecated and More Java Custom Annotations: Create Your Own @interface Java Annotation Targets: @Target and ElementType Explained Java Reflection API: Inspect and Use Classes at Runtime Java Class Metadata: Names, Modifiers, Hierarchy and Generic Java Dynamic Objects: Create Objects Dynamically With Reflec Java Dynamic Proxy: Intercept Method Calls With Proxy and In Java Security Java Secure Coding Java Password Hashing Java Input Validation Java Cryptography Basics Java KeyStore Basics Java TLS Basics Java SecureRandom Java JUnit Basics Java JUnit Test Methods JUnit Assertions JUnit Test Fixtures JUnit Parameterized Tests Mockito in Java Java Mock Objects Java Integration Testing Java Code Coverage Maven in Java Create a Maven Project in Java Maven Dependencies Maven Plugins Gradle in Java Gradle Build Gradle Dependencies Build Executable JAR in Java Build WAR File in Java HTTP Basics in Java Java Servlet Basics Servlet Lifecycle in Java HttpServletRequest in Java HttpServletResponse in Java JSP in Java JSTL in JSP REST API in Java JSON in Java Java Web Application Spring Framework Basics Spring Boot Tutorial Spring MVC Spring Data JPA Spring Security Spring Boot REST API Jakarta EE Basics Java Deployment JAR Deployment Java WAR Deployment Run Java as a Service Docker Java: Dockerize a Java Application Java Environment Variables and Configuration Java Logging Basics Java Production Setup Java JVM Options Java JVM Monitoring Java Hello World App Java Calculator App Java Number Guess Game Java Student Manager Java Library System Java Bank App Java Todo App Java File Manager Java Quiz App Java REST API Project Java Chat Server Java Employee Manager Java E-commerce API
Ask about this post
AI Ask about this post

Ask questions about Java Number Guess Game and get answers drawn from it.

Signed-in readers only.