Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If it's "Write once run anywhere", why do so many Java programs tell me to pick the version for my OS?

I am fairly new to Java or programming in general. On my journeys through the internet to master this language I have come up the saying "write once run anywhere" multiple times.

But I have found many software that requires you to pick the right version for your OS. Sometimes there is only one version available.

Could you explain to me why that is so?

like image 648
TomTom Avatar asked Jun 22 '14 09:06

TomTom


People also ask

Why people say Java is write once and run anywhere language?

Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. This is all possible because of JVM.

What give Java write once run anywhere?

The JVM (Java virtual machine) is platform dependent i.e its implementation differs from platform to platform (like windows, linux atc.), but these all JVMs can execute the same java bytecode . This is something which can be termed as 'write once and run anywhere' .

What language has slogan write once run anywhere?

Write once, run anywhere (WORA), or sometimes Write once, run everywhere (WORE), was a 1995 slogan created by Sun Microsystems to illustrate the cross-platform benefits of the Java language.

Does Java only need to be compiled once?

Java code needs to be compiled twice in order to be executed: Java programs need to be compiled to bytecode. When the bytecode is run, it needs to be converted to machine code.


1 Answers

[expanded per the comments]

Java runs on a Virtual Machine, the JVM. In an ideal world this means that the Operating System is abstracted away behind this and you only have to make sure your code works with the JVM which will make it work with the underlying OS. This can already be undone by using the wrong path separators or line endings; it is not an absolute truth.

An application can use many Operating System-specific approaches/libraries/functions/etc that might make it not feasible to restrict yourself to one general codebase. Instead they might want to leverage some advantages provided by a platform and create a separate application with it.

The statement should probably be somewhere along the lines of "Write once in a general fashion, run anywhere" but that's not as snappy.

This statement is often linked to Java but there are also other languages that incorporate this: weblanguages like Javascript and HTML will run on any browser because the browser itself forms the abstraction between the language and the underlying OS.

Other languages don't have this (entirely?) since they work differently: C# will use the underlying .NET framework which as it is only exists for Windows. There exists a cross platform variant (Mono) but it would be an overstatement to consider C# truly cross platform.

like image 80
Jeroen Vannevel Avatar answered Sep 25 '22 01:09

Jeroen Vannevel