This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
hi frens ... i m a novice in java.. just beginning on a java tour. i hav learnt tht java is platform independent .Thus once i write a program i shd b able to run it on ny machine(irrespective of the OS )nd get the same output . This is made possible thr JVM -java virtual machine . wat i need to know is IS JVM PLATFORM INDEPENDENT ?if nt then is it guranteed tht diff JVM's will give the same output on running the same bytecode ? thanx in advance 4 nyone who could help me answer the above Qs ..
Hi, Tom, welcome to the ranch! You'll get a lot better results around here with full English instead of, um, whatever phone messaging shorthand that was.
Are JVM's guaranteed to give the same results? Like "or your money back"? They certainly strive to give you the same results for portable code and a vendor might even promise it in advertising but "guarantee" is a very strong word.
There are platform-specific differences like how they mark newlines in text files, whether you use drive letters, forward slashes and back slashes. It is definitely possible to write code that will not port between Windows, Unix, Apple and your phone. But it is largely possible to write code that ports pretty darned well.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Also, some of these differences are more obscure than coding system specific paths and filenames into your application. There are for example differences in the way platforms handle multithreaded applications which MAY lead to your application behaving differently on different platforms. Usually this isn't a problem if you just remember some rules (with multithreading basically the rule is that nothing is guaranteed about the order in which threads are run for example) but things like that can bite you if you're not careful.
The JVM itself can do little about most of those things, they're down to the OS and hardware it runs on.
Of course there's always the possibility for bugs in a particular JVM causing inconsistent output, but that's of course out of the scope of a discussion like this.