Create a Java code to display the operating system of your computer (Core Java Interview Query #259)

The key insight here is that we can use the "System.getProperty" method in Java to retrieve the current operating system of the machine. By passing the argument "" to this method, we can obtain the name of the operating system. This simple code snippet helps us to print out the operating system like a charm! πŸ–₯οΈπŸ”πŸŽ‰

πŸ–₯️ Retrieving Operating System Information in Java

In this session, we will explore the process of writing a Java program to retrieve and print the operating system information currently installed on your machine. This program will be designed to work on various operating systems, such as Mac, Linux, or Windows, and will provide details regarding the specific version of Windows being used.

πŸ› οΈ Using system.getProperty Method

To accomplish this task, we will utilize the system.getProperty method, which is a predefined method of the System class in Java. By providing the argument to this method, we can effectively retrieve the name of the operating system currently installed on the machine.

Practical Demonstration

Let’s take a look at a practical demonstration of how to achieve this functionality using a Java program. First, we will create a new class in an integrated development environment (IDE) such as Eclipse, and then proceed with writing the necessary Java code to retrieve and print the operating system information.

public class MyClass10 {
    public static void main(String[] args) {
        String osName = System.getProperty("");
        System.out.println("Operating System Name: " + osName);

Upon running the above code, the output will display the specific name of the operating system currently installed on the machine. For example, if the system is running Windows 11, the program will print "Windows 11." This approach allows for dynamic retrieval of the operating system information, ensuring that any future system upgrades or changes are accurately reflected in the program output.


In conclusion, the use of the System.getProperty method in Java provides a simple yet effective means of retrieving and displaying the operating system information on a given machine. By following the provided example, developers can easily incorporate this functionality into their Java programs, allowing for seamless access to essential system information.

πŸ“Œ Key Takeaways

  • The System.getProperty method in Java enables the retrieval of operating system information.
  • By specifying the argument, developers can access the name of the current operating system installed on a machine.
  • This approach supports system flexibility, accommodating changes in the operating environment over time.

Thank you for joining this session. We hope you found this practical demonstration helpful in understanding how to retrieve and display operating system information using Java. Goodbye!

About the Author

84.9K subscribers

About the Channel:

The easiest Video Tutorials on Software Testing Concepts and Tools. This channel has free videos on Manual Testing, Selenium Test Automation, Core Java, SQL, HTML, API Automation, Security Testing, Interview Questions and many more.
Share the Post: