[英]Does “Hello World!” program compiled by JDK 7u3 runs with an older JREs (eg. JRE 6)?
Does Hello World!
Hello World!
program compiled by JDK 7u3 runs with an older JREs (eg. JRE 6)? JDK 7u3编译的程序是否与较旧的JRE(例如JRE 6)一起运行?
If the answer is YES
, When a java program doesn't run with an older JRE? 如果答案是
YES
是YES
,则Java程序不能与较早的JRE一起运行吗?
By default the class files produced by javac will have a version number appropriate for the JDK they were produced on. 默认情况下,由javac生成的类文件将具有与其所基于的JDK相适应的版本号。 To produce class files for earlier versions you will need to specify
-target
and to do that you will also need -source
. 要为早期版本生成类文件,您需要指定
-target
并且还需要-source
。 -source 1.6 -target 1.6
say. -source 1.6 -target 1.6
说。
However, you will still be picking up the current Java library, which contain classes, methods (possibly overloads), etc., that were not in the previous version. 但是,您仍将选择当前的Java库,其中包含类,方法(可能是重载)等,而不是先前版本中的类。 To sort that out, use
-bootclasspath
to point to the rt.jar
of the target JRE. 要解决此问题,请使用
-bootclasspath
指向目标JRE的rt.jar
。
Nope. 不。 You will get classloader exception complaining about non supported class version.
您将得到classloader异常,抱怨不支持的类版本。 Unless of course you specifically target lower version when compiling
除非您当然在编译时特别针对较低版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.