RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
May 3, 2021

Finding the OS Architecture in Java using System.getProperty

When creating a program, you may find that you need to figure out which Operating System architecture a computer is running on. Is it a 32 or 64 OS architecture, for example. Java allows you to find out the Operating System version using the System.getProperty method and then make informed decisions based on the return value.

Below you will find an example of using Java code to figure out which OS architecture a system is using and a sample of how to use the System.getProperty method:


public class OsArchitecture{

	public static void main(String []args){
		OsArchitecture osArchitecture = new OsArchitecture();

	private void proceed()
		String osArch = System.getProperty("os.arch");
			osArch.indexOf("32") != -1 
			?"32 bit architecture":osArch.indexOf("64") != -1 
			?"64 bit architecture":"Can't determine");


The following output should be the result of running the Java code above, showing the result of using the System.getProperty method to find out the user’s Operating System version:

$java OsArchitecture
64 bit architecture
MS Sridhar
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date