In this article, we will understand how to determine the name and version of the operating system. This is accomplished using System.getProperty function. The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java.lang.System Class.
Below is a demonstration of the same −
Input
Suppose our input is −
Run the program
Output
The desired output would be −
The operating system being used in the system is : Mac OS X
Algorithm
Step 1 – START Step 2 – Declare a string namely my_os Step 3 – Call the function System.getProperty to fetch the details of operating system and store it in a string Step 4 – Display the result Step 5 – STOP
Example 1
public class OperatingSystem { public static void main(String[] args) { String my_os = System.getProperty("os.name"); System.out.println("The operating system being used in the system is : " +my_os); } }
Output
The operating system being used in the system is : Linux
Example 2
public class OperatingSystem { public static void main(String[] args) { String my_os = System.getProperty("os.name"); System.out.println("The operating system being used in the system is : " +my_os); } }
Output
The operating system being used in the system is : Linux