How to detect OS in java

In this post, we will see how to detect OS which you are using. You can use System.getProperty(“os.name”) to get current OS name. Sometimes , we need to write logic based on OS, so we get use this logic to detect current OS.

Java Program:

I am using Mac os to run above program. When I ran above program, I got below output

Was this post helpful?

Leave a Reply

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