Question

I have been using java for long time but this question came to my mind recently and has been troubling me since.

I am aware about some conditions where platform agnosticism may be affected in java world via.

  1. code for interaction with file system
  2. using platform dependent libraries in the code.
  3. Also floating point numbers

Are there any more cases where java platform agnosticism may fail? Say a case where my file compiled on Solaris may fail to run on RedHat Linux.

Any help on the topic is appreciated.

Was it helpful?

Solution

Platform specific methods such as

  • Runtime.exec() is platform specific.
  • Anything under sun.* or com.sun.* may or may not be there, or do the same thing.
  • Some system properties are supposed to differ based on the system. e.g. There was one application which expected certain vendors which failed when the VM Vendor changed to Oracle. ;)
  • Anything which depends on System.getenv()
  • using native libraries

OTHER TIPS

You need to be careful with paths, e.g. using \ and / between Windows and UNIX is asking for trouble. Also, newline may be tricky: Windows is CR+LF, UNIX just CR (if I recall correctly). Java does provide mechanisms to handle such issues, but naive/new developers may miss them.

Also, I believe OS file locking is different, e.g. on Windows you may be blocked/denied access for something which on UNIX you wouldn't be.

Some libraries, which are not platform dependent, use JVM defaults. For example JVM may choose a different cryptography algorithm if you request AES on two machines. In this case you should be more specific when choosing the algorithm, for instance AES/ECB/PKCS5Padding. See Java default Crypto/AES behavior.

So in general, be careful when docs says that there is some default and don't use defaults.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top