Class VersionManager

java.lang.Object
com.dianxin.tori.base.utils.VersionManager

public final class VersionManager extends Object
Utility class for querying and validating the Java runtime version.

This class provides helper methods to detect the Java version currently running the application and to verify compatibility against a required minimum Java version.

It is primarily intended to be used during application startup or bootstrap phases to ensure the runtime environment meets the minimum requirements of the framework.

Example usage


 int current = VersionManager.getJavaVersionRunning();

 if (!VersionManager.isCompatibleJavaVersion(21)) {
     throw new UnsupportedOperationException(
         "Java 21 or newer is required"
     );
 }
 

This class is a pure utility class and must not be instantiated.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    Returns the major feature version of the Java runtime currently running the application.
    static String
    Returns the full Java runtime version string.
    static boolean
    isCompatibleJavaVersion(int requiredVersion)
    Checks whether the currently running Java version is compatible with the specified minimum required version.
    static boolean
    isJavaVersionInRange(int min, int max)
    Checks whether the current Java version falls within the given range.
    static boolean
    Checks whether the current Java version is a Long-Term Support (LTS) release.
    static void
    requireJavaVersion(int requiredVersion)
    Ensures that the current Java version meets the required minimum version.
    static void
    requireJavaVersion(int requiredVersion, boolean shutdown)
    Ensures that the current Java version meets the required minimum version.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getJavaVersionRunning

      public static int getJavaVersionRunning()
      Returns the major feature version of the Java runtime currently running the application.

      For example:

      • Java 8 → returns 8
      • Java 11 → returns 11
      • Java 17 → returns 17
      • Java 21 → returns 21
      Returns:
      the major Java version (feature version)
    • getJavaVersionString

      public static String getJavaVersionString()
      Returns the full Java runtime version string.
      Returns:
      the Java runtime version (e.g. "21.0.2")
    • isCompatibleJavaVersion

      public static boolean isCompatibleJavaVersion(int requiredVersion)
      Checks whether the currently running Java version is compatible with the specified minimum required version.

      A version is considered compatible if:

      
       currentVersion >= requiredVersion
       
      Parameters:
      requiredVersion - the minimum required Java version
      Returns:
      true if the current Java version is equal to or greater than the required version, false otherwise
    • requireJavaVersion

      public static void requireJavaVersion(int requiredVersion)
      Ensures that the current Java version meets the required minimum version.
      Parameters:
      requiredVersion - the minimum required Java version
      Throws:
      UnsupportedOperationException - if the Java version is incompatible
    • requireJavaVersion

      public static void requireJavaVersion(int requiredVersion, boolean shutdown)
      Ensures that the current Java version meets the required minimum version.
      Parameters:
      requiredVersion - the minimum required Java version
      Throws:
      UnsupportedOperationException - if the Java version is incompatible
    • isJavaVersionInRange

      public static boolean isJavaVersionInRange(int min, int max)
      Checks whether the current Java version falls within the given range.
      Parameters:
      min - minimum Java version (inclusive)
      max - maximum Java version (inclusive)
      Returns:
      true if current version is within range
    • isLtsVersion

      public static boolean isLtsVersion()
      Checks whether the current Java version is a Long-Term Support (LTS) release.
      Returns:
      true if the Java version is LTS