1

Maybe I am asking a very obvious and stupid question here, but I couldn't get anything on Google so here I go:

Why there is so much gung-ho about the fact that Java is Platform Independent and some other languages aren't. I mean, the total difference, as far as my understanding goes, is just the presence/absence of a compilation step, isn't it?

In Java, you don't have to compile the code again when you are running the bytecode on a different platform, whereas in C or C++, you will have to compile the code again, in order to run it on a different platform(Am I wrong here?).

So, being platform dependent just means one more additional step of compiling. Is this too much? I don't have much experience in programming so maybe I am missing some obvious practical point here.

amsquareb
  • 148
  • 10
  • 1
    There is more too it than that. One program might require significant changes when recompiled on a different platform/archetecture. For example a Windows executable that makes calls to the windows kernel will not run on Linux with a simple recompile. There will have to be significant code changes to port the program from Windows to Linux. – JJF Jan 21 '18 at 17:37
  • Is there really so much gung-ho about platform independence these days? I remember it being touted back in the days, but that's something like a decade ago. – Kayaman Jan 21 '18 at 17:38

1 Answers1

1

There are different grades of platform independence:

  • Binary platform independence: the same compiled executable can be run on different platforms without any additional step (e.g. Java).
  • Source code platform independence: the same source code can be compiled for different platforms (possible e.g. for well-designed C++ programs).
  • Multi-platform code: the source code contains multiple versions of platform-dependent code elements that can be selected by setting the relevant switches before compiling (typical for UNIX-style C programs).
  • Platform dependent code: source code only compiles to a functioning executable on one specific platform, e.g. Windows 32-bit. Targeting a different platform means to rewrite significant amounts of code.

So, the question is what platforms you want to cover and how much effort you want to devote to the variety of platforms.

For the client, you have Windows 32 and 64 bit, Macintosh, Linux variants, Android and iOS, to name the most popular ones. Alas, because of the different user interaction styles with smartphones and tablets, it's difficult to cover all these platforms with the same source code. Out of the box, Java only covers the classical desktops. HTML 5 and Javascript promise to cover the whole client range.

On the server side, there are mainly Linux versions and Windows 64 bit, and here Java's platform independence really rocks. And that's the reason why many web and application servers are Java-based. But other technologies can do the same here.

Ralf Kleberhoff
  • 6,990
  • 1
  • 13
  • 7
  • There is nothing like platform independence in programming, you have to create something platform dependent (like virtual machine or browser) which is dependent on platform and then only it will give feel of platform independence. This is not true platform independence. Only OS can be platform independent. But OS can't be machine independent, they are machine dependent softwares. – Rakesh Solanki Aug 12 '23 at 06:11