get Java Version - Android Android OS

Android examples for Android OS:OS Version

Description

get Java Version

Demo Code

/**//w  w  w .  j  av  a2 s .  c  o  m
 *******************************************************************************
 * Copyright (C) 2001-2015, International Business Machines Corporation and
 * others. All Rights Reserved.
 *******************************************************************************
 */
//package com.java2s;

public class Main {
    public static int getJavaVersion() {
        int ver = -1;
        String verstr = System.getProperty("java.version");
        if (verstr != null) {
            String[] numbers = verstr.split("\\.");
            try {
                ver = Integer.parseInt(numbers[1]);
            } catch (NumberFormatException e) {
                ver = -1;
            }
        }
        return ver;
    }
}

Related Tutorials