How to get OS Information using Java Program

Get OS Information using Java

In this tutorial, We will show you to write program about, How to Get OS Information using Java. The example java program were tested with environment and output is shared in the same post.

OSInformation.java

The following OSInformation class used to get information such as OS Name, OS Version, and OS Architecture etc. In Java we have predefined API`s and methods to get those information using java.lang.System.getProperty(key). by passing the appropriate key we can able to get the value accordingly. You find the sample java program below.

package com.dineshkrish.util;

public class OSInformation {

	public static void main(String[] args) {
		
		String os_name = System.getProperty("os.name");
		String os_version = System.getProperty("os.version");
		String os_arch = System.getProperty("os.arch");
		
		System.out.println("OS Information");
		System.out.println("--------------------------");
		
		System.out.println("OS Name : "+os_name);
		System.out.println("OS Version : "+os_version);
		System.out.println("OS Architecture : "+os_arch);
		
	}
}

Output

—————–

OS Information
————————–
OS Name : Windows 8.1
OS Version : 6.3
OS Architecture : x86

Hello, folks, I am a founder of dineshkrish.com. I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.