简体   繁体   中英

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. The only difference you may experience is at runtime, but once again, no Java construct can discern it. 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. The difference between a 32-bit and 64-bit JDK is, you're guessing already, in the JVM part.

Java is specifically designed to shield the users of it from things such as the word length of the platform, whether 32bit or 64bit. 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.

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.

The Java Compiler is not aware of the underlying hardware.

Java Source ----> Java Compiler ------> Bytecode (Hardware Independent)

Bytecode -------> Java Runtime --------> Machine Level Code (Platform/Hardware dependent)

So its not possible for Java code that runs on one hardware to not work on other.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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