问题
Java is supposed to be "write once, run anywhere" and it really can be, but in some cases it turns into "write once, debug everywhere".
What are the most common reasons for problems when moving a Java application from one platform to another?
What are un-common but interesting reasons?
回答1:
- Don't make assumptions about the case (in)sensitivity of the file system
- Don't make assumptions about the path or directory separator
- Don't make assumptions about the line terminator
- Don't use the default platform encoding unless you're really, really sure you mean to
- Don't start "cmd.exe" etc (I know, it sounds obvious - but I've seen it cause problems)
回答2:
Few from UI area:
- Incorrect ordering of buttons like OK/Cancel
- Using absolute layouts
- Different accelerator keys
- Different sizes/rendering of fonts
- Expecing certain keys to be present (Windows key, Meta key)
(These are not Java specific though)
回答3:
I can only speak from personal experience. These are things I've seen:
- Threading is abstracted differently on some architectures, so there are slight differences in delays and possibly ordering. (Which could lead to some race conditions)
- Controlling the keyboard's statuses (caps lock, num lock, etc) doesn't always work as expected (Linux didn't allow me to change the caps lock to disabled v1.5 at the time)
回答4:
Using classes from the com.sun.*
packages that come with the Sun JDK.
回答5:
Assuming you can write to the directory that contains your applications.
回答6:
Using JNI is something that should be looked into. Providing the native library for every target platform can reduce this problem.
回答7:
There are many different JVMs, so depending on which one the client has installed on their box, they may get slightly different results.
回答8:
Off the top of my head...some of these actually happened at work
JNI
Development tool introduced characters into formatted string literals that worked under Windows but didn't work under Linux (this actually happened)
File system inconsistencies (tightly coupling an application to one environment)
Underlying hardware such as available memory or cores could result in a change of behavior
来源:https://stackoverflow.com/questions/453538/what-issues-prevent-java-applications-from-working-on-multiple-platforms