How to Get Operating System Name using Java

In this article, you will learn how to get the operating system’s name that a java program runs on. It’s a reasonably easy code that uses the getProperty() function from the System class and then uses the property os.name to print out the name of the Operation System.

More like this:

Get Operation system Name Using Java

public class Main {

  public static void main(String args[]) {
    try {

      String operationSystemName = "";

      operationSystemName = System.getProperty("os.name");
      System.out.println("You are running a " + operationSystemName + " Operation System.");
    } catch (Exception e) {
      System.out.println(e);
    }
  }

}

Output

You are running a Linux Operation System.

 

Leave a Reply

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