views:

1047

answers:

5

So many server side and the mobile Java applications use the native Java language for Java. Can we use Jython instead to build the enterprise applications, e.g. websites, application servers etc.

Also what do you feel about Java ME applications in Jython.

P.S. Comments on question also welcome.

+3  A: 

No, Jython cannot replace Java, because Python is dynamically typed. Yes, Jython can be used for server applications.

Jython is not good for Java ME, because Java ME has very limited resources. Maybe several years later.

Edit: dynamically typed, not weakly

stepancheg
Python is strongly typed. The difference is that its variable are dynamic, meaning variables are really labels around the objects. http://shriphani.com/blog/2008/05/11/python-variables/
gregturn
+3  A: 

No, Jython is not a suitable replacement for Java. Consider, for instance, that it provides no way to implement interfaces without writing the interface in Java and then writing a class leveraging it in Jython.

What's needed is a JVM-targeted equivalent to Boo. Boo is a language targeting the .NET CLR which is roughly inspired by Python but not compatible, and which fully exposes the CLR's functionality (thus being feature-equivalent with C#). There presently is no Pythonic language with feature parity with Java -- and such a language would necessarily be incompatible with Python, as Python simply doesn't provide a way to express some of the relevant concepts (such as interface typing information).


Since there have been some questions about this, yet me clarify:

Jython is not a replacement for Java in the sense that you can't take an arbitrary Java project, decide to implement a random subset of that project in Jython instead, and not have anyone else on the development team know or care. Certainly, Jython is suitable for many of the same classes of projects that Java is, except when you're building an interface which will be called from Java, rather than the reverse. Given as "enterprise applications" tend to have a lot of components which operate closely with each other, being able to build a class with an arbitrary external interface is important... and is something which isn't readily done in pure Jython.

Charles Duffy
-1 Assumes without any support that interfaces are necessary. Not that Jython could or should replace Java, but this is arbitrary reasoning.
Jesse Dhillon
@Jesse - The fact that Java-the-language can be used to create an externally-visible interface which Jython cannot means that Jython has less expressive power with respect to being able to access all functionality of the Java object system. If language A can express only a subset of the things language B can express, how can you call it a replacement?
Charles Duffy
@Charles, If I said to you that cars could not possibly replace horse-drawn carriages because cars cannot produce manure, nor do they provide you a means of reducing your stores of horse feed, what would your response be?
Jesse Dhillon
@Jesse - The question was not whether Jython could be used in place of Java under any circumstances, but whether it was *a replacement* for Java. An unqualified replacement must be suitable in all respects -- including, in the case of a horse, manure production. If one were to ask if Jython could replace Java in a specific context, that would be a different question.
Charles Duffy
@Jesse - More to the point, if I commit to doing a project in pure Jython, and someone asks me to code to an interface for which I need to drop into Java (very plausible if the component I'm building is a library intended for use from native Java code!), I suddenly have some explaining to do.
Charles Duffy
@Charles, fine Jython cannot be used as a replacement in situations where one is requested or required to use the Java language (duh!) It can, however, be used "to build the enterprise applications, e.g. websites, application servers etc."
Jesse Dhillon
@Jesse not just cases where one is "requested or required to use the Java language", but cases where one is "requested or required to implement a specific library API for consumption from the Java language"; a very important difference. Building components intended to be called by (not merely being able to cleanly call) native-Java frameworks and libraries, or collaborating with teams building Java-native components, tends to be a necessary aspect of building large enterprise applications within the Java ecosystem.
Charles Duffy
@Jesse - by the way, a bit of personal background; I flipping hate Java-the-language for its tendency to throw up roadblocks to getting things done. Likewise, when given a random job to do, I more often than not tend to land on Python. Just because I happen to like Python, though, doesn't mean that Jython suddenly becomes a full semantic superset of Java; it simply isn't. Fortunately, I have enough other languages in my toolbox that when I do need to bidirectionally interoperate with JVM bytecode I can find something that fits. Pragmatism beats purity, after all -- it's right there in PEP-20.
Charles Duffy
@Charles, I guess you are reading a lot more into the question than I am. But thanks for explaining your reasoning.
Jesse Dhillon
A: 

You can use Jython for that domains. Obviously, the world for web development is moving towards dynamically typed languages as Python or Ruby. Jython is nice in this domain, since it allows to use the complete "Java stack" (App server, Tomcat, deployment and testing infrastructure,...) in enterprises. You can also implement your business logic in Java.

However, Jython is not a replacement for Java as it is C#. You (may) gain programmer productivity, but you lose performance and compile time checks. The languages are really different and are "optimized" for different tasks. I would propose to evaluate Jython for smaller, non-critical tasks, e.g. by starting to implement some test cases in it.

I doubt that Jython is useful for Java ME development. The reasons are given in the other posts: Resource constraints.

dmeister
"The languages are really different and are "optimized" for different tasks."Which tasks you find better?
Xolve
+1  A: 

Yes. The Dynamic languages are the future. I heard this from SUN representatives about one yar ago. The amazing part about Jython is "native" usage of java libraries. Services and other components may remain in Java but integration layer will move for sure in the dynamic languages direction. I think Python is natively object oriented like Java that's why they match so good. I don't expect something like that from other scripting languages like Perl but for sure Ruby and Groovy are also good alternatives.

+3  A: 

It depends largely what your requirements are. All languages have their strengths and weaknesses. There is no perfect language and making intelligent decisions about language choice is an important skill for a programmer.

I disagree with Charles that Jython can't replace Java because you can't implement Interfaces. In dynamic languages, it's seen as a feature that you don't need Interfaces (see duck typing).

Jython takes the great language features of Python and combines it with easy access to huge collection of Java libraries. However it does have a price in terms of overhead, and being a fairly new language you have less programmers and support to back you up.

The nice thing about Jython is that you can rewrite individual modules in Java if performance is a problem. The speed issue is less notable on servers where you can throw hardware at the problem. On mobile phones, performance is still key and I can't see Jython making a big impact there in the near future.

So will Jython replace Java? No, I don't think it will - the momentum behind Java is too great. But we will see increasingly more software with parts written in Jython and other languages targeting the JVM.

Peter Gibson
@Peter - I agree that interfaces are an evil hack. If you're building an API for consumption by code written in native Java, however, that hack tends to become necessary. If we're talking true "enterprise applications", after all, you want to be able to outsource parts to the lowest bidder... and low bidders are much more likely to know Java than Python.
Charles Duffy
@Charles, that's the beauty of Jython - the outsourced components can be Java, and you can use them from Jython with no additional effort. As I said I don't think it will replace Java, but it is useful none the less.
Peter Gibson
@Peter - only if the outsourced component isn't trying to call Jython code natively. If the calling convention is one-way rather than bidirectional, yes, there's not a problem.
Charles Duffy