Java
  Home arrow Java arrow Page 3 - What's So Good About Jython?
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

What's So Good About Jython?
By: Simon White
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2003-07-11

    Table of Contents:
  • What's So Good About Jython?
  • What is Python?
  • Jython Reuse From Java
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    What's So Good About Jython? - Jython Reuse From Java


    (Page 3 of 4 )

    The example above has shown how you can access Java classes from Jython. Now I should explain how you can use Jython code from Java.

    The answer really is quite simple. Since Jython is an implementation of Python in Java, it needs to compile the Python functions that you write down to Java bytecode before it can run them. Normally it avoids a lengthy compilation step by doing the compilation ‘on the fly’, but you can also compile your Jython classes down to Java .class files or .jar archives that you can place on the classpath of your ‘master’ application.

    You perform the compilation by using the jythonc compiler provided with Jython. This compiler first generates Java source files from the Jython code., then compiles them using a standard Java compiler. If you generate .class files, then you need to remember to put the jython.jar runtime on the Java classpath when you run the master application, as the Java source files that jythonc generates have dependencies on the Jython runtime. If you generate a jar file using jythonc, however, there are options to include files from the Jython runtime within the jar. For example, if the Jython source code for the example given above is contained in the file MyExample.py, then it can be jar’ed up with the following command:

    jythonc -c -j myjar.jar MyExample.py

    This creates a jar file containing the compiled Java version of the Jython code we wrote as well as files from the Jython runtime. The jar file also contains a manifest, which makes the jar executable. You can run the jar by typing:

    java -jar myjar.jar

    Why Isn't Everybody Using Jython?

    This is the hard part! Jython is an incredibly powerful tool, and I think there are many developers out there who would love to use it, if only they could. It’s one of those few languages that delights the developer, because the language is so powerful and you get results quickly. However, it is still very much a ‘niche’ language, used only by forward-thinking organisations and entrepreneurs.
    Here are some of the possible reasons for the low adoption rate of Jython:

    • Two Technologies, One Developer
      It won’t have escaped your notice that to understand a Jython program (or to be more precise a Jython program that uses Java classes) you need a solid understanding of both Java and Python. This places demands on the skills of the developer at a time when most managers prefer to simplify code development by choosing the technology that is the common denominator across their applications.
    • Learning Curve and Project Pressures
      Most developers come to Jython from Java, so have to learn about Python. They probably have to learn Python before being able to convince  colleagues and managers that Jython will save time in the long run. And the time to learn a new language in the midst of project pressures and approaching deadlines is simply not available. It’s a vicious circle that needs to be broken, and I’m confident that for many, an investment in Jython will pay off.
    • Old Habits Die Hard
      If you’re a Java developer, you are probably quite satisfied developing Java. It’s a good, well established, programming language and you’re familiar with the idioms, patterns and style of the language that make it elegant. Why should you change? Well, I think you should at least consider using Jython, because firstly, Python, too, is a good programming language with a strong following. Secondly, a good developer should always be on the look-out for ways of becoming more productive, and I believe Jython is a good candidate. Lastly, technologies in the IT sector are always changing, so you should constantly re-evaluate your technology choices to be sure that you use your chosen technologies for the right reason, instead of ‘choosing’ them by default because “that’s what you do”.
    • Perception of an “Experimental Technology”
      Jython is not an “Experimental Technology” — It is industrial-strength and stable. If you’re not confident enough to use it for your main application straight away, then use it for writing test scripts and developing prototypes. Often, developers will begin with the intention of writing a prototype in Jython and later migrating to Java, only to find later that the migration is not necessary.
    • Jython is Slow
      To say that Jython is unsuitable for your application because it is an interpreted language and therefore too slow is almost certainly false. There are very few applications these days for which execution speed is such a major concern. And if you do find a bottleneck in your code you can always migrate that section of code to Java as necessary. As a developer, you should be more concerned about the speed of development than the speed of execution, and in this respect, Jython is fast!

    More Java Articles
    More By Simon White


     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT