views:

531

answers:

4

We're talking about uses; not static vs. dynamic typing, whitespace indentation, etc.

It seems Python and Java are similar in that they are both cross-platform and used in the desktop programming and server programming arts. How is Python being used like Java? Is it another good way to write your cross-platform software?

+1  A: 

They're both Turing-complete general purpose programming languages that run on a variety of platforms. You will find Java and Python both used for everything from Web applications to desktop applications to server applications.

As such the choice of one over the other will come down to personal preference and the quality and availability of relevant libraries for your particular task.

Perhaps the only area where you won't see Python (or at least more Java) is on mobile devices by virtue of J2ME but that's an example of a library/framework availability issue. Even that gap is diminishing. Android will run Jython on the VM and IIRC you can do some form of Python for the iPhone.

cletus
...and Nokia offers Python on their S60 line of Symbian phones (though I don't know of any way to run Python on an iPhone unless by jailbreaking the latter, the same applies to Java;-).
Alex Martelli
A: 

I actually used to use Python for my own applications (along with wxPython for the GUI).

I rather liked its simplicity.

But, everything I do nowadays is in Java (with Swing or SWT for the GUI) since it's a more marketable skill in the workplace, especially for webwork - J2EE can be found in far more corporate environments than Python.

Other than that, I found no real difference between them. They both have a huge supporting library for data structures and such, which speeds up your delivery schedule a lot. They're both cross-platform. I have no idea of the speed issue since most apps I write spend 90% of their time waiting for the user (and almost everything else can be designed to run in the background). In either case, both have access to native code if necessary (but I've never had to use it).

paxdiablo
A: 

Python

Python is really good for prototyping, but it doesn't mean it's not for a serious system. With python it's just really fast getting things done. Building a web application with Python is seriously easy as there is less things to set-up compared to Java because it would require you to setup a lot of configuration in a lot framework.

Java

Java is really good for backend system that demands scalability and high performance. Making a webservice or an API with Java is really good because it is type safety and it has formal interface so you would rarely have anyone do monkey patching. This is really important in building an API, as you would want to know and restrict what is coming in to your system.


If you want developer productivity, you would use python. But if you want scalability, you would use Java.

jpartogi
+2  A: 

As others have pointed out, the potential uses are nearly the same. They're both modern, general-purpose programming languages suitable for just about anything you can imagine. And yes, Python is usually a good way to write cross-platform software. I'll point out these differences and their implications, though:

  • As others have pointed out, Python helps you get things done quickly. There's less ceremony in throwing together a small application, so it's probably a better choice for scripting and for developing small command line tools.
  • Java has vastly better tools support, especially with respect to IDE's. This is at least partially due to the fact that Java is statically typed. Java's also a lot more verbose than Python, so you have a greater need for those tools with Java than you might with Python.
  • Want multithreading? Go with Java. Java's shared memory model of concurrency is far from perfect, but you're almost certainly going to see better throughput than you would with Python. Java's concurrency libraries since 1.5 are pretty nice, too. On the surface Python seems to offer a lot of the same functionality with its threading module, but thanks to GIL you usually end up hurting your performance... but you won't have as many problems with deadlocks either.
  • Both have lots of choices in web frameworks, and some of them are actually quite good. Personally I prefer Python's offerings, but that's probably more due to my areas of greatest experience (Django vs. Struts really isn't much of a contest).

My personal experience is that, unless there's some particular library that I need to use in one language, I often start out preferring to work in Python. Once the project starts to climb up into thousands of lines of code, I find myself yearning for Java's tools. Of course, you can get a lot more done with a thousand lines of Python than you can with a thousand lines of Java.

If you really want to use Python but want some Java library or concurrency support, just try Jython.

Jeff
Struts is only a web framework, django is a full stack. You would have to combine struts with many other frameworks to make it like django.
jpartogi
This is true. Thanks for pointing that out. I've used Hibernate good bit and I quite like it, and I combined it with Struts in a couple of projects. In terms of the web framework aspects of django, however, I must say I prefer those (URL mappings in regular old Python, views, etc.) to the Struts equivalents.
Jeff