File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes portability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "portability" Watch "portability" New topic


Padma Anand

Joined: Apr 14, 2004
Posts: 3
when I write a java program on win2k and compile it, will the compiled byte code run on any OS? or any necessary precautions need to be taken to make the code run on all the OSs. I was told by somebody that though java claims "write once and run everywhere" still some precautions have to be taken to run the code on different VMs. Can somebody let me know what precautions are necessary to make the code truly portable?
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
Hello Padma,
What you have heard is 100% correct. The Java programs run on top of the Virtual Mechine(VM). So you do not have to write different applications to different Operating Systems(O/S). So you can 'Write Once and Run Any Where'.But the precausions upto my knowledge are, things like the slashes which are used when specifying the path etc...
Hope you get some kind of an idea from this....

SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Ransika is quite correct. As long as you don't use any platform (operating system/hardware/etc.) code inside your Java classes they should work without change on any computer that has a JVM installed on it (if that JVM is of a version that supports code generated by your javac compiler of course, typically that means the same version or a newer one).
You can look up the documentation for java.lang.System which contains info on how to get the path separators etc. for the platform on which your application is running.

I agree. Here's the link:
subject: portability
It's not a secret anymore!