Java完全独立于平台吗? [英] Is Java completely Platform Independent?

查看:339
本文介绍了Java完全独立于平台吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java是否完全独立于平台?

Is Java completely Platform Independent ?

如果没有,那么需要注意看看用Java编写的代码可以在多平台上运行。基本上它应该适用于Windows(各种版本),Linux(所有版本),Mac和Solaris等目标平台。

if not then, what care needs to be taken to see that your code written in Java can run on Multi Platforms. Basically it should work on Targeted Platforms like Windows (Various versions), Linux (all flavors), Mac and Solaris.

推荐答案

在实践中,大多数编译的字节代码都是独立于平台的,我在Java平台上开发12年的经验告诉我,从平台到平台仍然存在特质。

While in practice, most compiled byte code is platform independent, my experience in my 12 years of developing on the Java platform has taught me that there are still idiosyncrasies from platform to platform.

例如,在为PC和MacOSX开发Java 1.4 Swing应用程序时,如果父框架为空,则对话框的行为会有所不同。

For example, while developing a Java 1.4 Swing application for PC and MacOSX the behavior of dialogs was different if the parent frame is null.

另一个例子可能是使用一般的文件系统和文件。 Java API有一些方法可以帮助保护开发人员免受路径分隔符的差异( / vs \ )。在写入文件时,重要的是按预期使用FileWriter API,以便为正在编写的平台正确生成返回字符等。

Another example might be with working with the file system and files in general. The Java API has methods to help shield the developer from differences in path separators (/ vs \). When writing to a file, it important to use the FileWriter API as intended so that return characters and such are generated properly for the platform that it is being written on.

所以虽然座右铭是一次编写,随处运行,但我的经验是生产环境,它只需编写一次,测试,无处不在。

So while the motto is "write once, run anywhere" my experience has been for production envs it is write once, test, everywhere.

因此,拥有强大的单元和集成测试可以帮助解决这个问题,因为您可以在要分发软件的各种平台上执行这些测试。

As a result, having strong unit and integration tests can help with this, as you can execute those tests on the various platforms you want to distribute your software.

尽管存在一些小问题,但使用相同的JAR在Linux,Unix,Windows和MacOSX(BSD Unix)上运行代码是很酷的。

Despite some minor issues here and there, it is cool to see your code running on Linux, Unix, Windows and MacOSX (BSD Unix) using the same JARs.

这篇关于Java完全独立于平台吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆