Comparison of JRE versions with Java
Many programs adopt JDK Development of Higher versions. These programs may use higher versions.
The features of the JDK version cannot be run on the JDK of a lower version or are displayed properly.
To determine the JRE version in the current system
This section provides a version judgment class.
Versionchecker. Java
Import java. util. stringtokenizer;
Public class versionchecker
{
Public void check (string desiredversion)
{
String CurrentVersion = system. getproperty ("Java. Version ");
Boolean isok;
Try
{
Isok = versioncompare (CurrentVersion,
Desiredversion)> = 0; // if the current version is higher than the required version, run
}
Catch (numberformatexception exception)
{
Isok = false;
}
If (isok)
{
// Do what you want
System. Out. println ("Current JRE version is OK! ");
}
Else
{
System. Out. println ("the current JRE version is not match! ");
}
}
Public static int versioncompare (string V1,
String V2)
{
Stringtokenizer T1 = new stringtokenizer (V1 ,"._");
Stringtokenizer t2 = new stringtokenizer (V2 ,"._");
While (t1.hasmoretokens ())
{
If (! T2.hasmoretokens () return 1;
Int n1 = integer. parseint (t1.nexttoken ());
Int n2 = integer. parseint (t2.nexttoken ());
Int d = N1-N2;
If (D! = 0) return D;
}
Return t2.hasmoretokens ()? -1: 0;
}
Public static void main (string ARGs []) {
Versionchecker Vc = new versionchecker ();
VC. Check ("1.4.0 ");
}
}