Results 1 to 14 of 14
  1. #1
    Kapil Gupta is offline Member
    Join Date
    Jun 2008
    Posts
    9
    Rep Power
    0

    Default 32 bit machine or 64 bit machine

    Hi All,
    Is there any way that java can find out whether it is running on 64bit architecture or 32 bit?

    I have searched net and found two possible workarounds:

    boolean is64bit;
    String osArch = System.getProperty("os.arch").toLowerCase();
    is64bit = osArch.indexOf("64") >= 0;

    OR

    String bits = System.getProperty("sun.arch.data.model", "?");
    if (bits.equals("64")) {
    is64bit = true;
    }
    else if (bits.equals("?")) {
    // probably sun.arch.data.model isn't available
    // maybe not a Sun JVM?
    // try with the vm.name property
    is64bit = System.getProperty("java.vm.name").toLowerCase().i ndexOf("64") >= 0;
    }
    // probably 32bit
    else
    is64bit = false;

    but both of them not working in my case. (Vista 64 bit and XP 64 bit).
    Depending on the architecture I have to browse some different folders.
    Is there any robust method to find out the architecture of the machine?

    Thanks in anticipation,
    Kapil

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Did you try to get the model using sun.arch.data.model property? It gives the data model/data transfer model.

  3. #3
    Kapil Gupta is offline Member
    Join Date
    Jun 2008
    Posts
    9
    Rep Power
    0

    Default

    Thanks Eranga for your reply.

    I have already tried:
    String bits = System.getProperty("sun.arch.data.model", "?");
    if (bits.equals("64")) {
    is64bit = true;
    }
    .....

    but this explains the JVM type 64 bit or 32 bit.
    Isn't there anyway to find out the processor type ( 64 or 32 ).

    I thought of getting output of dos command systeminfo to get the processor type
    System type: X86-based PC/x64-based PC

    Is there any other workaround?

    Thanks,
    Kapil

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Really, I think it related to OS. Anyway I have one idea, that OS bit model and H/W bit model should be same right?

    If so, we can find the OS bit model, and use it to processing.

  5. #5
    Kapil Gupta is offline Member
    Join Date
    Jun 2008
    Posts
    9
    Rep Power
    0

    Default

    Eranga,
    Can you help me with finding "OS bit model" using java?
    How can I find this?

    Thanks,
    Kapil

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    Kapil Gupta is offline Member
    Join Date
    Jun 2008
    Posts
    9
    Rep Power
    0

    Default

    Hi Eranga,

    Actually I was testing the above two workarounds with a jar file. I was double clicking the jar and was not able to get the output for os.arch and sun.arch.....

    But when I ran the jar from command prompt by using command

    java -jar -cp . Filename.jar ,

    both of these methods are showing proper results for 64 bit machine. Can somebody explain why is this so ?

    Thanks,

    Kapil

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  9. #9
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    You could always exec to some shell/os command and parse it.

    But I know of no way to tell if you are running on a 64 bit processor that happens to be running a 32 bit OS. And these days, it is safe to assume that most 64 bit AMD/Intel processors are running a 32 bit OS.

    More importantly, isn't the point of Java to make hardware implementation details unimportant?

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by fishtoprecords View Post
    More importantly, isn't the point of Java to make hardware implementation details unimportant?
    This is interesting for me. Even me, never worried about such h/w implementations on working with Java. And also I never comes with such issues before.

  11. #11
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    Part of the reason that Java defines 'long' and Long separate from int and Integer is to make the language independent of the processor. A proper Java JVM will execute the code and get the right answer on a 8 bit, 32 bit or 64 bit machine.

    A lot of embedded systems are 8 bit processors, or 16, so in general its not safe to assume that you have 32 or 64 bits.

    Long ago, there were many more flavors, systems with 7 bit characters, or 10 six bit characters, per "word" of memory. Most folks don't remember that stuff, since all PCs used the IBM mainframe convention of 8 bits per byte, and byte-based memory.

    With network protocols, you have to worry about big-endian and little-endian, but internal register size is rarely an issue these days.

    I guess that if you really wanted to have an array of 5gb of data, you would care, since a 32 bit machine can only address 4gb.

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  13. #13
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Hi folks,
    This is interesting to find out something new other than core java as we do always.

    Kapil try this out:
    System.getProperties().list(System.out);
    The above stmt prints u some info related to OS such as version architecture n all.

    If that is what u dont want then use JNI(Java native Interface), i am nt sure about its API's.

    If taht wouldnt work out, the last thing u can do is find out a command line that will give u this information and java always provides u the way to execute them..

    Hope ur problem is solved. :)
    To finish sooner, take your own time....
    Nivedithaaaa

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. How to get URL from network machine
    By Mir in forum Networking
    Replies: 1
    Last Post: 04-02-2008, 12:08 AM
  2. Getting name/ip of a machine
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-02-2008, 07:11 PM
  3. Turing machine Help please!!
    By bladeb2k in forum Java Applets
    Replies: 1
    Last Post: 08-15-2007, 09:47 PM
  4. Too many virtual Machine
    By davantmay in forum Java Applets
    Replies: 1
    Last Post: 07-06-2007, 10:53 PM
  5. Virtual Machine To Pda
    By Heather in forum Advanced Java
    Replies: 2
    Last Post: 06-30-2007, 03:11 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
  •