How to detect OS and its version in Java

Here is my Java class that detects which type of operating system (OS) you are using now and what is your operating System version.

This code can detect “Windows”, “Mac”, “Unix” and “Solaris”.


public class OSChecker {

    public static void main(String[] args)
    {
                          
          String OS = System.getProperty("os.name");
             
          System.out.println("Your OS is : " + OS);
               
             
          String OSVersion = System.getProperty("sun.arch.data.model");
             
          System.out.println("Your OS version is : " + OSVersion + " bit");
             
                    
   }
}

No comments:

Post a Comment