Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question
1  
The primary difference is the strictness of the JVM specification. It is simply very well defined how it must (not should) behave. –  user1249 Oct 25 '11 at 9:30

5 Answers 5

up vote 12 down vote accepted

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

share|improve this answer
    
It's not at all difficult to write Java code that works only on Windows; just hard-code a Windows file path like "C:\MyApp\data" –  kevin cline Jan 2 at 7:06
    
@kevincline Hardcoded paths are a bad practice on any operating system. But Java doesn't require you to do this, because it offers OS-independent methods to retrieve common directories like the user directory or the install path of the current program. –  Philipp Sep 6 at 21:51

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.

share|improve this answer

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.

share|improve this answer

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.

share|improve this answer
3  
Python has several platform independent GUI alternatives: docs.python.org/faq/… –  Joonas Pulakka Oct 30 '10 at 5:44

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.

share|improve this answer
    
This isn't really an answer to the question. –  Eric Wilson Oct 29 '10 at 21:02
    
-1 because Java is WORA for all practical purposes. It will work if you avoid system-specific hacks and obviously native stuff like JNI. I've had 50,000+ line applications run perfectly across Windows, Mac and Linux, no changes, first time, with the same compiled .jar file. If you stick to pure Java it all just works. –  mikera Jun 10 '11 at 0:20
    
It appears you have misunderstood what WORA mean. –  user1249 Oct 25 '11 at 9:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.