Reputation: 4917
This is a common enough question and always seems to throw up the usual arguments between using sun.arch.data.model" OR "os.arch" as a way of telling.
for example this post .... How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?
I have put this quick method together, can anyone spot any loop holes as I want to cover all possibilities as our app may be deployed on AWS servers or standalone machines
private static boolean is64BitJVM()
{
String jvmBitSizeUsingSunProperty = System.getProperty("sun.arch.data.model");
if( jvmBitSizeUsingSunProperty != null && jvmBitSizeUsingSunProperty.length() > 0)
{
return jvmBitSizeUsingSunProperty.contains("64");
}
else
{
String jvmBitSizeUsing_os_Property = System.getProperty("os.arch");
if( jvmBitSizeUsing_os_Property != null && jvmBitSizeUsing_os_Property.length() > 0)
{
return jvmBitSizeUsing_os_Property.contains("64");
}
}
return false;
}
Upvotes: 1
Views: 100
Reputation: 533530
Instead of doing
if (test)
{
return true;
}
else
{
return false;
}
you can just do
return test;
Upvotes: 1