243.html ( File view )

  • By 2010-08-21
  • View(s):12
  • Download(s):0
  • Point(s): 1
			






Safari | Python Developer's Handbook -> Welcome to JPython





< BACKMake Note | BookmarkCONTINUE >
152015024128143245168232148039196038240039088173205162105045222218068074148024146197222

Welcome to JPython

JPython is a Java implementation of the object-oriented scripting language called Python that has been certified as 100% pure Java. In other words, JPython does not use any of the C code of the original Python implementation. It is a version of Python that runs on top of the Java Virtual Machine. Thus, it allows you to run Python on any Java platform and enables your JPython applications to have access to any Java library that you might need.

JPython offers the same language as Python, but it has a different implementation. Python is a scripting language whose interpreter is written in C, which means that this implementation is called CPython. On the other hand, JPython re-implements the Python parser and interpreter in Java. Actually, the interpreter is available as a Java application, which allows Python programs to be created and seamlessly integrated with the Java platform. Note however that both types of implementation (Python and JPython) have their own pace. Efforts are made to keep them in sync, but it is not guaranteed that this will always happen.

JPython carries a license that complies with the Open Source definition. It is freely available for both commercial and non-commercial use and is distributed with source code.

JPython was designed by Jim Hugunin, who is also the main author of the Numeric Python extensions. He has joined Guido at CNRI in 1998, leaving in mid-1999 to join the Xerox PARC team in California. When he left, Barry Warsaw took care of the JPython project, and he is the main person responsible for the project since then. Currently, JPython is maintained by Warsaw at BeOpen Python Labs.

At the Web site, you can always obtain the latest information about this implementation and download info. In case you are interested in downloading the source code, it is available via CVS. The latest version of JPython was released in January of 2000. Check out the JPython Official Web site at

http://www.jpython.org/

If you want to be in touch with other users, JPythoners have their own mailing list that you can use to discuss JPython, ask questions, and help other users as well. Check out the jpython-interest mailing list at

http://www.python.org/mailman/listinfo/jpython-interest

JPython Features

JPython's core is an interpreter engine, similar to CPython's, that provides support to the greater part of the Standard Python Library. JPython has a set of features that includes

  • High-level built-in data types

  • Dynamic typing

  • Optional static compilation (which allows the creation of beans, applets, servlets, and so forth)

  • Java classes and packages support

  • A set of support libraries

  • Interactive compilation direct to Java bytecodes (which enables JPython programs to run directly on a JVM, including running as applets in Web browser windows).

JPython uses the Java's introspection mechanism to understand the contents of the package, which means that when you want to import a Java library, say something such as

						
import java.awt

					

JPython first tries to find a Python package named java. And in case it doesn't find one, it uses the Java mechanism to search in the CLASSPATH system variable for a .class or .jar file that meets the requirement.

Another important aspect of JPython is that you can create JPython classes that subclass Java classes, extending JPython functionality without the need for using wrapper generators (such as SWIGSimplified Wrapper and Interface Generator), provided the functionality is already implemented in Java code. Otherwise, you probably need to use the JNI interface to make the code available to JPython. This allows you to easily use the same set of classes that a regular Java application has access to. The opposite is also true. Java has total integration with JPython, and because JPython is 100% pure Java certified, you might embed JPython in your Java applications without any worries of compromising the portability of your application. If necessary, you can even pass JPython object instances back to Java (executing callbacks), and manipulate these instances in the Java application because any Java code that processes Java objects is also able to process JPython objects.

Sometimes, you might find JPython useful for testing your Java components. As JPython has total integration to the Java implementation, you can use it to call, test, and debug the functionality of Java functions through the interpreter. JPython is the perfect choice for controlling Java through an interactive language.

JPython also handles memory management with care in order to remove from you the responsibility of being worried about object circular references. To do so, it uses the power of the Java memory management mechanism, a mechanism that implements a garbage collector, which is executed at runtime.

JPython's performance is still not as good as the performance of CPython, but there is a lot of effort going on in order to make JVMs run faster.

CPython Versus Jpython

Both CPython and JPython are implementations of the same language: Python. Even though the development team tries to make both codes as compatible as possible, differences are inevitable. Each one of these languages is written using a different programming language: C and Java, respectively. This primary difference is more than enough to cause both codes to have many distinctive characteristics that are unlikely to disappear soon. The following is a short list of differences between both implementations:

Sponsored links
  • Sent successfully!
  • 1 point

243.html (1.65 MB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D