How to Get Type of Operating System in Java


In this example we will show how to get the type of operating system in Java.

Source Code

package com.beginner.examples;

public class OSType {

  public static void main(String[] args){
    String os = System.getProperty("os.name");
    if (osName.startsWith("Mac OS")) {
      System.out.println("Mac OS"); // Mac OS
    } else if (osName.startsWith("Windows")) {
      System.out.println("Windows"); // Windows
    } else {
      System.out.println("Other"); // other
    }
  }
}

Output:

Windows
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments