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 the Average of Two Numbers in Java
- Copy File Content to Another Using Java
- Examples of ArrayList in Java
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.

IT specialist Veteran