-2

It is said that Java has advantage over other languages by being platform independent. But doesn't it makes it dependent as it relies on its JVM for the byte codes to run?

  • 1
    possible duplicate of [How is Java Platform independent when it needs JVM to run?](http://stackoverflow.com/questions/2748910/how-is-java-platform-independent-when-it-needs-jvm-to-run) – Duncan Jones Dec 06 '13 at 10:36
  • 2
    I don't think this is really opinion-based. The facts are quite clear. This should have been closed as a duplicate. – Duncan Jones Dec 06 '13 at 10:55
  • 1
    @Duncan The facts may be clear, but their *interpretation* as to whether they constitute platform independence is primarily opinion-based. – Marko Topolnik Dec 06 '13 at 11:28
  • @MarkoTopolnik I disagree. I think with regards to Java, there is only one way to describe why it is considered by some to be platform independent. Now, the broader question of "What is platform independence?" is opinion-based. As would be the question "Should Java be considered platform independent?" – Duncan Jones Dec 06 '13 at 12:08
  • @Duncan I think OP's question is precisely about the broader topic you describe. – Marko Topolnik Dec 06 '13 at 12:33

2 Answers2

6

Java is not platform independent. But Java code is.

Write and Compile Java code once, it will run everywhere whereas this is not possible in every language like C. And thus your java code becomes platform independent.

Vimal Bera
  • 10,346
  • 4
  • 25
  • 47
  • 1
    actually even the compiled java code will run on every machine that has java installed – LionC Dec 06 '13 at 10:38
  • 1
    You can write C/C++ code once and have it compiled and run on any platform. – Marko Topolnik Dec 06 '13 at 10:38
  • 3
    @MarkoTopolnik but you may need platform-specific constructs in your C/C++ which isn't the case in Java (unless, yes, you want your buttons to do something different on Windows but that's everyone's freedom). – Simeon Visser Dec 06 '13 at 10:40
  • 2
    @MarkoTopolnik Yes, but you need to compile it again. Byte code will not works on other machine. Whereas Java's compiled classes runs every where. – Vimal Bera Dec 06 '13 at 10:40
  • 1
    Let me paraphrase your own answer: `Write C code once, it will compile and run on each and every machine`. – Marko Topolnik Dec 06 '13 at 10:41
  • And with Java, it's `Write Java code once, install Java runtime on each and every machine, and it will run, provided that you have installed the appropriate version`. It's not that different. – Marko Topolnik Dec 06 '13 at 10:46
  • 1
    You should have said something like "*Compile Java code once and it will run on every machine that has a compatible JVM installed*". Then it would distinguish Java from C. – Duncan Jones Dec 06 '13 at 11:00
5

Platform independent in this respect means that
a) VMs are available for all major platforms
b) binaries (Java byte code) can be run on all VMs across platforms without recompilation

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588