Languages
[Edit]
EN

Java - detect operating system name (Windows, Linux, macOS)

4 points
Created by:
Payne
654

In this short article, we would like to show how to detect used operating system in Java application.

Quick solution:

or:

Where: SystemUtils should be attached as dependecy (Maven dependency is avaialble here).

 

Operating system name detection

Edit

In this section, you can find information what os.name property should return on specific operating system.

 

Operating system type detection

Edit

Knowledge about operating system name may be requred when some operating system uses specific configuration or resources. In this section we would like to show different aproaches to detect operating system type.

 

1. Apache Commons library

Edit

Using this approach it is required to attach commons-lang3 library provided by Apache Software Foundation.

Usage example (it was run under Windows 10):

Hint:

Using commons-lang3 library we are able to detect more precised OS version, e.g. SystemUtils.IS_OS_WINDOWS_8, SystemUtils.IS_OS_WINDOWS_10, etc.

Example output:

 

Maven dependency:

Source: https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.12.0

 

2. Custom solution

Edit

In this section, you can find simple custom solution that lets to detect Windows, Linux or Mac operating system. For more precised detection it is recommended to use commons-lang3 library.

Usage example (it was run under Windows 10):

Example output:

 

Example SystemUtils.java file:

 

References

Edit
  1. System.getProperty - java docs
  2. https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.12.0

Alternative titles

  1. Java - check operating system name (Windows, Linux or Mac OS)
  2. Java - detect OS name
  3. Java - check OS name (Windows, Linux or Mac OS)
  4. Java - get operating system name
  5. Java - get operating system name (Windows, Linux or Mac OS)
  6. Java - get OS name
  7. Java - get OS name (Windows, Linux or Mac OS)
  8. Java - detect OS type
  9. Java - get OS type
  10. Java - check OS type
  11. Java - determine operating system
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join