How can I tell if I'm running in 64-bit JVM or 32-bit JVM (from within a program)?

前端 未结 12 1804
滥情空心
滥情空心 2020-11-22 09:39

How can I tell if the JVM in which my application runs is 32 bit or 64-bit? Specifically, what functions or properties I can used to detect this within the program?

12条回答
  •  太阳男子
    2020-11-22 10:10

    For certain versions of Java, you can check the bitness of the JVM from the command line with the flags -d32 and -d64.

    $ java -help
    ...
        -d32          use a 32-bit data model if available
        -d64          use a 64-bit data model if available
    

    To check for a 64-bit JVM, run:

    $ java -d64 -version
    

    If it's not a 64-bit JVM, you'll get this:

    Error: This Java instance does not support a 64-bit JVM.
    Please install the desired version.
    

    Similarly, to check for a 32-bit JVM, run:

    $ java -d32 -version
    

    If it's not a 32-bit JVM, you'll get this:

    Error: This Java instance does not support a 32-bit JVM.
    Please install the desired version.
    

    These flags were added in Java 7, deprecated in Java 9, removed in Java 10, and no longer available on modern versions of Java.

提交回复
热议问题