2011-12-16 41 views
0

我是“java世界”中的新成员,因此我需要了解有关不同OS和JDK中可移植性的基础知识。我在互联网上看到的是,如果在JDK 1.7上编译程序,它将在任何JDK版本> = 1.7上运行,是不是?谢谢,我对我的英语表示歉意,这不是我的默认语言。Java可移植性不同OS/JDK

+0

“粗略”。当你这样做时,你会遇到(相对较少的)不一致。我记得最常见的问题是使用“平台默认字符集”的“新字符串(byte [])”(以及一些类似的)。只是为了它。当你遇到一个问题......那么,这会产生更多有趣的问题。 – 2011-12-16 05:32:07

回答

1

现在没有在java -target版本选项
它说,...

Generate class files that target a specified version of the VM. Class files will run 
on the specified target and on later versions, but not on earlier versions of the VM. 
Valid targets are 1.1, 1.2, 1.3,1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7). 

     If -source is not specified, the value of -target is 1.7 
     If -source is 1.2, the value of -target is 1.4 
     If -source is 1.3, the value of -target is 1.4 
     If -source is 1.5, the value of -target is 1.7 
     If -source is 1.6, the value of -target is 1.7 
     For all other values of -source, the value of -target is the value of -source. 

所以“如果在JDK 1.7的编译程序,它可以在任何版本的JDK运行> = 1.7,是对的“

+0

其中还需要指定`-source`和`-bootclasspath`选项。幸运的是,Java 7 SDK最终警告`source` /`target`没有`bootclasspath`。 – 2011-12-16 05:43:04

0

你是对的。你写的大多数东西都会自动工作在任何(版本兼容的)JVM中。我将一个重要的Java Swing GUI应用程序从Windows移到Linux,我只需要将配置文件更改为指向不同的目录。它只是工作。

0

是的,除非在新版本中弃用某些东西。弃用可能会导致一些不一致。