Find operating system name java

Find operating system name java

Sometimes you would like to find out operating system name using java in your code to perform some business logic. Below is sample code to find operating system name java:

package com.javahonk.system;

public class FindOperatingSystem {

    public static void main(String[] args) {

    String operatingSysName = System.getProperty("os.name");

    if (operatingSysName.equalsIgnoreCase("Windows 7")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else if (operatingSysName.equalsIgnoreCase("Windows XP")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else if (operatingSysName.equalsIgnoreCase("Windows 2000")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else if (operatingSysName.equalsIgnoreCase("Windows Server 2003")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else if (operatingSysName.equalsIgnoreCase("Windows Server 2008 R2")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else if (operatingSysName.equalsIgnoreCase("Linux")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else if (operatingSysName.equalsIgnoreCase("Unix")) {
        System.out.println("Operating System name: " + operatingSysName);
    } else {
        System.out.println(System.getProperty("os.name"));
    }

    }

}

 

Output:

Find operating system name java

Leave a Reply

Your email address will not be published. Required fields are marked *