Skip to main content
← All Guides
Performance · 7 min read

Java 21 vs Java 17 for Minecraft Servers, Which to Use?

Complete comparison of Java 21 vs Java 17 for Minecraft servers including version requirements, performance differences, installation steps and common errors.

Which Java Version Does Your Server Need?

The answer depends entirely on which Minecraft version you are running. Mojang periodically bumps the minimum Java requirement when they adopt newer language features in the server codebase. Here is the mapping:

Minecraft VersionMinimum JavaRecommended Java
1.7 – 1.12.2Java 8Java 8
1.13 – 1.16.5Java 8Java 11 or 16
1.17 – 1.17.1Java 16Java 16 or 17
1.18 – 1.20.4Java 17Java 17
1.20.5 – 1.21+Java 21Java 21

If you run Minecraft 1.21 or newer, you must use Java 21. There is no workaround, the server jar will refuse to start on Java 17. If you run 1.18 through 1.20.4, Java 17 is your target. Running Java 21 on a 1.20 server is technically possible and usually works, but it is not officially supported by Paper or Spigot for those versions and may trigger unexpected behavior.

How to Check Your Current Java Version

Before changing anything, find out what you are running now.

java -version

The output will look something like:

openjdk version "17.0.8" 2023-07-18
OpenJDK Runtime Environment (build 17.0.8+7)
OpenJDK 64-Bit Server VM (build 17.0.8+7, mixed mode)

The first number is what matters, 17 in this example. If it says 21, you are on Java 21. If it says 1.8 (Java's old versioning scheme), you are on Java 8.

If your startup script uses a full path to the Java binary (like /usr/lib/jvm/java-17-openjdk-amd64/bin/java), the java -version in your terminal might not reflect what the server actually uses. Check the startup script to see the exact path.

Performance Differences: Java 21 vs Java 17

Java 21 is not just a version number bump, it includes genuine performance improvements that benefit Minecraft servers.

Garbage Collection: ZGC Improvements

Garbage collection (GC) is the process that frees unused memory. GC pauses are one of the primary causes of lag spikes on Minecraft servers. Java 21 brings significant improvements to the ZGC garbage collector:

  • Generational ZGC (-XX:+UseZGC -XX:+ZGenerational) splits the heap into young and old generations, which matches Minecraft's allocation patterns well. Short-lived objects (tick calculations, packet data) are collected quickly from the young generation without scanning the entire heap.
  • Pause times are consistently under 1 millisecond, compared to G1GC's typical 10-50ms pauses.
  • Throughput is slightly lower than G1GC in synthetic benchmarks, but the elimination of lag spikes is worth it for Minecraft's tick-sensitive workload.

If you were using the Aikar flags with G1GC on Java 17, consider testing ZGC on Java 21. The difference is most noticeable on servers with 8GB+ of allocated RAM where G1GC pauses can exceed 100ms. Check our optimization guide for specific flag recommendations.

Virtual Threads

Java 21 introduces virtual threads (Project Loom), which allow lightweight concurrent execution without the overhead of OS threads. Minecraft's main game loop is single-threaded, so virtual threads do not directly speed up tick processing. However, they benefit:

  • Plugin I/O operations (database queries, HTTP requests, file reads) that previously blocked platform threads.
  • Async chunk loading in Paper, which uses threads for parallel chunk operations.
  • Network handling, each player connection can use a virtual thread without consuming OS resources.

These benefits are indirect. You will not see "20% more TPS" from Java 21, but you will see smoother performance under load, fewer random lag spikes and better behavior when multiple plugins perform async operations simultaneously.

Other Runtime Improvements

  • JIT compiler improvements in Java 21 produce slightly more optimized machine code for hot paths, which benefits Minecraft's tight game loop.
  • Memory footprint is marginally smaller due to internal JDK optimizations.
  • Startup time is improved, which matters less for long-running servers but helps during restarts.

Installing Multiple Java Versions

You might run servers on different Minecraft versions that need different Java versions. Installing multiple versions side by side is straightforward.

Debian / Ubuntu

# Install both
sudo apt install openjdk-17-jre-headless openjdk-21-jre-headless

# Check installed versions
update-java-alternatives --list

# Java binaries are at:
# /usr/lib/jvm/java-17-openjdk-amd64/bin/java
# /usr/lib/jvm/java-21-openjdk-amd64/bin/java

CentOS / RHEL / Rocky

sudo yum install java-17-openjdk-headless java-21-openjdk-headless

# Binaries at:
# /usr/lib/jvm/java-17-openjdk/bin/java
# /usr/lib/jvm/java-21-openjdk/bin/java

Windows

Download installers from Adoptium (Eclipse Temurin) for both versions. Install them to separate directories and reference the full path in your startup batch file.

Switching Java in Your Startup Script

Instead of changing the system default Java (which can break other applications), reference the specific Java binary in your server's startup script.

# 1.20.4 server using Java 17
/usr/lib/jvm/java-17-openjdk-amd64/bin/java -Xms4G -Xmx4G -jar paper-1.20.4.jar

# 1.21 server using Java 21
/usr/lib/jvm/java-21-openjdk-amd64/bin/java -Xms4G -Xmx4G -jar paper-1.21.jar

This way, each server uses the correct Java version regardless of what java -version shows as the system default.

Pterodactyl and Docker Image Java Versions

If you use Pterodactyl panel (which is common with hosting providers), the Java version is determined by the Docker image configured for your server. You cannot install Java versions inside the container, you need to change the image itself.

  • Go to your server in the Pterodactyl admin panel.
  • Navigate to the Startup tab.
  • Change the Docker Image to one that includes Java 21. Common image names:
    • ghcr.io/pterodactyl/yolks:java_21
    • ghcr.io/pterodactyl/yolks:java_graalvm_21 (GraalVM variant, slightly better JIT performance)
  • Save and restart the server.

If you are a player on a hosted server and cannot access the admin panel, ask your hosting provider to switch the Java version for you. Any competent host will do this quickly.

Common Errors from Wrong Java Versions

Using the wrong Java version produces distinctive error messages. Here is how to diagnose them.

UnsupportedClassVersionError

Exception in thread "main" java.lang.UnsupportedClassVersionError:
  net/minecraft/server/Main has been compiled by a more recent version
  of the Java Runtime (class file version 65.0), this version of the
  Java Runtime only recognizes class file versions up to 61.0

This means your Java is too old. Class file version 65 corresponds to Java 21; version 61 corresponds to Java 17. The error is saying "this jar was compiled for Java 21, but you are running Java 17." Install and use Java 21.

Startup Crash with No Meaningful Error

Running a 1.12.2 server on Java 17 or 21 can cause silent crashes or obscure internal errors because legacy Minecraft code uses APIs that were removed in newer Java versions. For old versions, stick with Java 8.

Plugin Errors After Java Upgrade

Some older plugins were compiled against Java 8 or Java 11 APIs and use internal JDK classes that were removed in later versions. Symptoms include NoClassDefFoundError for javax.xml or sun.misc classes. The fix is to update the plugin, not to downgrade Java. If the plugin is abandoned, find a maintained fork or alternative.

Forge, Fabric and NeoForge Java Requirements

Modded servers have their own Java version requirements that may differ from vanilla or Paper:

  • Forge (1.20.x): Requires Java 17. Forge 1.21+ is largely superseded by NeoForge.
  • NeoForge (1.21+): Requires Java 21, same as vanilla.
  • Fabric: Generally follows Minecraft's Java requirements. Fabric Loader itself supports Java 17+ but individual mods may require specific versions.

Always check the modloader's documentation for the specific Minecraft version you are running. Mod compatibility with Java versions is an additional layer on top of Minecraft compatibility, a mod might work with Minecraft 1.21 but crash on Java 22 if it uses preview features from Java 21.

The Bottom Line

Match your Java version to your Minecraft version using the table at the top of this guide. If you are starting a new server or updating to 1.21, use Java 21, you get better garbage collection, virtual threads and ongoing security patches. If you are staying on 1.18-1.20, stick with Java 17 until you are ready to update both Minecraft and Java together. And if you are running a legacy 1.12.2 or 1.8 server, Java 8 is your only reliable option.

For JVM flag recommendations tailored to each Java version, see the server optimization guide. For help with the actual Minecraft update process, start with our 1.21 update guide.

Need hosting for your network? Astroworld Hosting offers NVMe SSD, Pterodactyl panel, and DDoS protection. See features , plans from €6.39/mo.

Related Tools & Resources

🔧

Minecraft Tools

Calculators, generators & server tools

🧱

Item Database

Browse all Minecraft items, stats & recipes

⚒️

Crafting Recipes

Visual crafting guides for every recipe