Is Java completely Platform Independent?

后端 未结 8 1611
鱼传尺愫
鱼传尺愫 2020-12-24 12:43

Is Java completely Platform Independent ?

if not then, what care needs to be taken to see that your code written in Java can run on Multi Platforms. Basically it sho

8条回答
  •  自闭症患者
    2020-12-24 12:58

    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.

    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.

    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.

    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.

提交回复
热议问题