Java example program to get Operating System type or architecture

In java environment we can write java code which will make us enabled to get the operating system type.

Java example program to get Operating System type or architecture

In java environment we can write java code which will make us enabled to get the operating system type.

Java example program to get Operating System type or architecture

Java example program to get Operating System type or architecture

     

java get OS type

In java environment we can write java code which will make us enabled to get the operating system type. We can get the operating system architecture or system type by using the system property.

Here this java example code displays how one can get the current running operating system's type. The property "os.arch" gives operating system version that you are running. We can get this property's value by using the method getProperty() of the java.lang.System .

Here is the full code of GetOSArchitecture.java is as follows:

GetOSArchitecture.java

import java.util.*;
import java.lang.*;

public class GetOSArchitecture
  {
  public static void main(String args[]) {
  try{
  String osType= System.getProperty("os.arch");
  System.out.println("Operating system type =>"+ osType);
  }catch (Exception e){
  System.out.println("Exception caught ="+e.getMessage());
  }
  }
}

Output:

C:\javaexamples>javac GetOSArchitecture.java

C:\javaexamples>java GetOSArchitecture
Operating system type =>x86

Download Source Code