Java's "os.arch" System Property is the Bitness of the JRE, NOT the Operating System

| No TrackBacks
If you ever use Java to check if a system is 32 or 64-bit, you should know that Java's "os.arch" system property returns the bitness of the JRE, not the OS itself.  Sites like this are WRONG; any resource that claims Java's "os.arch" property returns the real "architecture of the OS" is lying.  Case in point, I recently ran this tiny program on a 64-bit Windows 7 machine, with a 32-bit JRE:

import com.sun.servicetag.SystemEnvironment;

public class OSArchLies {

public static void main(String[] args) {

// Will say "x86" even on a 64-bit machine
// using a 32-bit Java runtime
SystemEnvironment env =
SystemEnvironment.getSystemEnvironment();
final String envArch = env.getOsArchitecture();

// The os.arch property will also say "x86" on a
// 64-bit machine using a 32-bit runtime
final String propArch = System.getProperty("os.arch");

System.out.println( "getOsArchitecture() says => " + envArch );
System.out.println( "getProperty() says => " + propArch );

}

}

The output from this tiny app on a 64-bit box:

#/> java OSArchLies
getOsArchitecture() says => x86
getProperty() says => x86

In this case, one would expect to see something like "x86_64" or "amd64" instead of just "x86".  Bottom line, don't believe what you read online about "os.arch" and other Java system properties.  They are usually properties of the JRE/JDK itself, and not necessarily the real properties of the underlying OS or architecture.  If you need to check if a system is actually 32 or 64-bit, you should look elsewhere in the system registry or write your own native app and call it from Java.

Did You Find this Helpful?

Did you find this post helpful, or at least, interesting?

  

Send Mark a Direct Message

If you'd like to send me a direct message, please do so below. However, I do not publicly post comments or messages submitted directly to me. So, if you're going to try to SPAM me, or my blog, you're pretty much wasting your time.

400 characters remaining

Error

About Mark

A Silicon Valley native, Mark Kolich is a full-time Software Engineer, a casual entrepreneur, and a consultant for hire. A web technologies expert, his current focus is on building powerful and robust cloud-driven web-applications using Java, PHP, Perl, AJAX, DHTML, CSS, and JavaScript. His favorite programming languages are PHP, Java and JavaScript. He uses Linux, enjoys biking to work, loves building great software, and always writes elegant, readable, and maintainable code.

No TrackBacks

No trackbacks attached to this entry.

Twitter (@markkolich)

Translate

About this Entry

This page contains a single entry by Mark Kolich published on October 19, 2009 11:15 AM.

Onyx: My Custom Solution to the Digital Clutter Problem was the previous entry in this blog.

Reliably Checking Windows Bitness (32-bit or 64-bit) With a Tiny C++ App is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.