how to know what current jvm version is running


String version = System.getProperty("java.specification.version");

This method will work in every versions of jre specs, so you can test this with 1.1 applets without problem.
you can get an eye here for more keys to use:
http://java.sun.com/j2se/1.4/docs/api/java/lang/System.html#getProperties()

Someone asked this question in the Newbies section so i posted
a bit mreo code. The main addtion to pepe’s post is how to
load your real main class froma version checking shell by
reflection.

This is necessary if you want to handle garcefuilly running under an earlier runtime that might not have available all the system classes
your real main links to. It delays the resolution of those linkls until after you’ve checked and approved the version.

Thanks for the added features, Jeff.
by the way, here is the link to the original question and your code:
http://www.java-gaming.org/cgi-bin/JGOForums/YaBB.cgi?board=newbies;action=display;num=1035234634

I have some Code written last month for that.
Simply Test the actual Version against the given one.


    /**
     * Test if Java Version equals or is higher on System.

     *
     * @param javaVersion The Version to Test against.
     * @return true/false
     */
    public static boolean isJavaVersionHigherOrEqualInstalled ( double
            javaVersion )
    {
        if ( javaVersion >= 1.0d )
        {
            try
            {
                String installedVersionString = JavaInfo.getJavaVersion () ;
                // ersten punkt suchen ....
                int index = installedVersionString.indexOf ( "." ) ;
                index += 2 ;
                // ben?«Ótigte infos ausschneiden...
                installedVersionString = installedVersionString.substring ( 0 ,
                        index ) ;
                //umwandeln in double objekt
                Double temp = new Double ( installedVersionString ) ;
                // umwandeln in primitive
                double installedVersion = temp.doubleValue () ;
                System.out.println ( "Installed Version:" + installedVersion ) ;
                System.out.println ( "Installed Version die da sein muss:" +
                                     javaVersion ) ;
                //und vergleichen ?
                if ( installedVersion >= javaVersion )
                {
                    return true ;
                }
                return false ;

            }
            catch ( NumberFormatException ex )
            {
                ex.printStackTrace () ;
                return false ;
            }
        }
        return false ;
    }


hmm, any reason java versioning doesn’t work (I haven’t tested this, so I’m not sure if this is how it’s supposed to work…)?


Package javaVersion = java.lang.Package.getpackage("java.lang"); 
// Any core j2se package should work I guess?
boolean ok = javaVersion.isCompatibleWith("1.4.2"); 

Hmm,

interresting, did not know 8) that ! But it is not
specified how the String have to look like (?? my English).

  • Jens

http://java.sun.com/j2se/1.4.2/docs/guide/versioning/spec/versioningTOC.html

That should give you a lot of information :slight_smile:

It’s actually not crystal clear if my suggestion will actually work (information provided be the link seems to contradict the api documentation of isCompatibleWith??)

EDIT: I believe the syntax of the version string is
.[.<“bugfix”>]

i.e. microsoft vm isCompatibleWith(“1.1”) should return true - but
isCompatibleWith(“1.1.9”) should return false (replace 9 with the actual latest bug fix number of the ms vm +1 )

And the current (1.4.2) should return true when given isCompatibleWith(“1.4”) (or 1.4.2, 1.4.1, 1.3.1 etc etc :slight_smile:

I Have some book the Java Lang. Spec. Issue 3.
There were said that if you use the getPropertie
Method from util Package will return Strings in this
this format:

Major.Minor.BugFix

seems to be the Same format :-* as you posted

Interresting to know, so my code ma be a bit “oversized” but should work also on Blackdown VM
or other.
But, this is of course the shortest solution, i will fix that in my Project.

  • Jens