我在Java中以编程方式确定操作系统?

huangapple go评论60阅读模式
英文:

I programmatically determine operating system in Java?

问题

我学到的系统特性如下:

System.getProperty("os.arch")

64位计算机的输出:amd64

但当我在64位计算机上使用32位Java版本时,结果是:x86

即使我在64位计算机上安装了32位Java,我该如何获取正确的结果?

谢谢

英文:

I learn the system features as follows:

System.getProperty("os.arch")

Output for 64 bit computer: amd64

but when I use a 32 bit java version on a 64 bit computer, the result is: x86

How can I learn the correct result even though I have java 32 bit java installed on a 64 bit computer?

Thank you

答案1

得分: 2

这个主题在Oracle的Java教程中有详细介绍。

  • "os.arch" 操作系统架构
  • "os.name" 操作系统名称
  • "os.version" 操作系统版本

关于os.arch的值在维基百科上有解释。

  • x86 表示最初由Intel开发的32位架构。
  • amd64 表示该架构的64位扩展,由AMD首创,后来被Intel采用。

(顺便说一句,还存在其他架构,比如ARM。)

第一种情况表示Java在32位机器上运行,或者Java在64位机器上以32位兼容模式运行。

第二种情况表示Java在64位机器上以64位模式运行。

> 即使我在64位计算机上安装了32位Java,我如何知道正确的结果?

(A)我不知道。 (B)你的问题无关紧要。 32位JVM在64位机器上运行时具有32位机器的限制。 从Java的角度来看,主机硬件和操作系统可能是64位的事实是无关紧要的。

英文:

This topic is covered by the Java Tutorials from Oracle.

  • "os.arch" Operating system architecture
  • "os.name" Operating system name
  • "os.version" Operating system version

The values for os.arch are explained on Wikipedia.

  • x86 signifies the 32-bit architecture originally from Intel.
  • amd64 signifies the 64-bit extension of that architecture, invented by AMD, later adopted by Intel as well.

(By the way, other architectures exist, such as ARM.)

The first means Java is running on a 32-bit machine, or Java is running on a 64-bit machine in 32-bit compatibility mode.

The second means Java is running in 64-bit mode on a 64-bit machine.

> How can I learn the correct result even though I have java 32 bit java installed on a 64 bit computer?

(A) I don’t know. (B) Your Question is moot. The 32-bit version of the JVM running on a 64-bit machine has the constraints of a 32-bit machine. The JVM only sees what appears to be a 32-bit machine. From the perspective of Java, the fact that the host hardware and OS may be 64-bit is irrelevant.

huangapple
  • 本文由 发表于 2020年8月7日 14:43:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/63296556.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定