12

In the Java world, we often talk about the JVM, and when Java was new it had the supposedly killer feature of "Write Once, Run Anywhere."

From the way people talk and write, this seems different from the way that Python, for example, works. Yet I've not been aware of any way that Python code that I've written would work differently on another machine. (Though I haven't written that much Python.)

So what am I missing? How is the JVM different from a Python interpreter? Is there a way that Python lacks Java's platform independence? Or is this just a cultural difference?

Frank Shearar
  • 16,751
Eric Wilson
  • 12,111

5 Answers5

17

Java does a very good job on isolating you from the underlying OS and gives you the same exact tools on most platforms it works on to talk to things in the underlying OS.

Python on the other hand does not do as good of a job in isolating you from the underlying OS, It does not have a standard way of handling between process communications (look at the differences in the sys module and os module between a windows and *nix implementation of Python for example.)

I have written code in python that would only work on a *NIX box or Windows box using just Python available API calls, where in Java it would be very difficult to write code that was just Java API that would not work the same on both a Windows box or *NIX box

mangelo
  • 669
3

Topically and just from a language runtime, there is little difference. The JVM in particular is designed not just as an interpreter but also a runtime compiler, code inference, an instrumental virtualization layer that can have dynamic hooks applied, various GC semantics and the ability to describe virtualization ergonomics, to name a few. Python can run in a JVM? Can Java run in a Python interpreter?

Most interpreters are runtime language/token interpreters, JVMs (and others) as you know interpret/compile/run intermediate code. IBM for instance has been doing this for decades outside of Java, it is nothing new. Even VB ran in intermediate code for some time I believe?

The WORA is mostly passé now as many interpreted languages run just about anywhere unchanged.

Jé Queue
  • 3,917
3

When Java was new, WORA was something to boast about - specifically, that you could compile on one platform and run that (compiled bytecode) on other platforms.

Of course, interpreted languages run pretty much similarly regardless on what platform the interpreter runs on (as long as the interpreter is available for that platform). However, file systems, permission issues, encodings, line endings and countless other small but irritating issues can cause headaches. Some platform-dependent things aren't easy to abstract away.

1

Does Python have a platform independent GUI?

Anyway, the WORA feature was - again - to lure C programmers over, as C tended to model the underlying platform closely, and as platforms were different (size of word? endianess?) creating fully portable C programs required great care and attention.

The Java promise was that all this tediousness did not have to be done, as the platform is very well defined and you KNOW that a char is 16 bit etc. Also the GUI is written in Java and also 100% portable, which means that your program can run on a computer you've never heard of and even run correctly.

-4

Except that Java is emphatically not WORA. I've seen Java software that broke after Java has been upgraded to a higher version on the minor version number. IMHO, WORA is just a marketing gimmick.

zvrba
  • 3,480