Results 1 to 5 of 5
  1. #1
    jitheshmenon is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default retrieve OS architecture

    Hi All,

    How do I know whether a machine is a 32 bit one or a 64 bit one using java code?

    I tried using System.getProperties(os.arch)
    But it actually gives the JRE's one rather than the machine's actual one.

    i.e. in my 64-bit machine I have 32-bit JRE installed
    The os arch value obtained is x86.

    Is there a way to do this?

    I thought of checking the size of integer?How do we do this in java and will it help?

    Thanks in advance
    Jith

  2. #2
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    Well, you could use set a String to equal the property, and check if it contains a value:
    Java Code:
    String s = System.getProperty("os.arch");
    if (s.contains("86") || s.contains("64")){
    //This is a 64 bit OS
    }
    else if (s.contains("i")){
    //this is 32 bit. I have it search for 'i' because it could be i386, i586 or i686 
    }
    else {
    //Unknown or other arch
    }
    cheers,
    Crikey

  3. #3
    jitheshmenon is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    Hi Crikey..

    I used the same technique which you mentioned..

    May be you didnot read my question completely..

    When we use System.getpropertes(Os.arch), it actually gives the JRE's bitness.. This is not what i want

    I need the actual processor's "bitness" value

    Hope that clear my question

    Jith

  4. #4
    Prajin's Avatar
    Prajin is offline Senior Member
    Join Date
    Jun 2010
    Location
    Ktm, Nepal
    Posts
    120
    Rep Power
    0

    Default

    hi,
    System.getProperty("os.arch");
    this code always return OS architecture and from your 1st post your OS is x86(32-bit). it didn't mean you PC is 32-bit.

    64-bit PC can have 32-bit OS, like you have 32-bit jdk in ur 64-bit PC.

    How do I know whether a machine is a 32 bit one or a 64 bit one using java code?
    I can't be done by System.getProperty(); and probably not by Java.

    -regards

  5. #5
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Location
    Canada
    Posts
    684
    Rep Power
    5

    Default

    os.arch.data.model property ?
    Properties : Java Glossary

    but that probably is not going to hint if 64 bit machine when running a 32 bit os.

    Kind of platform specific, for example, on linux if you look in the file "/proc/cpuinfo", maybe open it and parse the flags : value, there will be "lm" flag to mean long mode, to mean the CPU is working in 64 bit mode. But that does nothing for you on Windows. Perhaps, try to detect the "C:\Program Files" and separate "C:\Program Files (x86)" folders to infer 64 bit OS.

Similar Threads

  1. Question about architecture
    By sdmente in forum Advanced Java
    Replies: 7
    Last Post: 07-28-2010, 01:07 PM
  2. Architecture Rules 2.1.1
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-11-2008, 02:39 PM
  3. Architecture Rules 2.1.0
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 07-05-2008, 06:18 PM
  4. Architecture Rules 2.0-rc2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-14-2007, 06:27 PM
  5. Architecture of Any IDE...
    By vikki_pu in forum Other IDEs
    Replies: 5
    Last Post: 10-30-2007, 01:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •