简体   繁体   English

任何只能使用64位JDK编译的示例代码

[英]Any example code that will only compile with a 64Bit JDK

是否有任何Java代码构造只能在使用64位JDK时进行编译,或者在Java世界中是否可以这样做?

Definitely not at the compilation level. 绝对不是在编译级别。 Java compiler has no idea what kind of JVM it is going to run in and there is nothing JVM-specific in the .class files. Java编译器不知道它将在哪种JVM中运行,并且.class文件中没有任何特定于JVM的JVM。 The only difference you may experience is at runtime, but once again, no Java construct can discern it. 您可能遇到的唯一区别是在运行时,但再一次,没有Java构造可以辨别它。 You can read the architecture system property, but I'm quite sure that is not what you are aiming for. 您可以阅读体系结构系统属性,但我确信这不是您的目标。

As for your "next question" in the comment, a JDK contributes the full Java stack, including source code, compiled bytecode, and the JVM. 至于评论中的“下一个问题”,JDK提供完整的Java堆栈,包括源代码,编译的字节码和JVM。 The difference between a 32-bit and 64-bit JDK is, you're guessing already, in the JVM part. 在JVM部分中,您已经猜到了32位和64位JDK之间的区别。

Java is specifically designed to shield the users of it from things such as the word length of the platform, whether 32bit or 64bit. Java专门用于保护用户免受平台字长的影响,无论是32位还是64位。 Generally, it is impossible to construct anything in the language that is sensitive to this. 通常,不可能用对此敏感的语言构造任何东西。

Therefore all code written in Java should compile on any platform. 因此,用Java编写的所有代码都应该在任何平台上编译。

Additionally, the compilers should be able to run on any platform, but as they could be written in native code, it is technically feasible that there could be a bug preventing one of them running on a certain platform. 此外,编译器应该能够在任何平台上运行,但由于它们可以用本机代码编写,因此技术上可行的是可能存在阻止其中一个在某个平台上运行的错误。

Using JNI (Java Native Interface) there can be some problems, but this would generally be in the C/C++ code calling and being called from Java. 使用JNI(Java Native Interface)可能会遇到一些问题,但这通常是在C / C ++代码调用和从Java调用。

The Java Compiler is not aware of the underlying hardware. Java编译器不了解底层硬件。

Java Source ----> Java Compiler ------> Bytecode (Hardware Independent) Java Source ----> Java编译器------> 字节码(硬件独立)

Bytecode -------> Java Runtime --------> Machine Level Code (Platform/Hardware dependent) 字节码-------> Java运行时--------> 机器级代码(取决于平台/硬件)

So its not possible for Java code that runs on one hardware to not work on other. 因此,在一个硬件上运行的Java代码不可能在其他硬件上运行。

The answer to your second question is that for creating the machine level code for the bytecode the Runtime has to know what operations are supported by the underlying hardware. 第二个问题的答案是,为了创建字节码的机器级代码, 运行时必须知道底层硬件支持哪些操作。

Instructions for 32 and 64 bit machines are different. 32位和64位机器的说明不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM