English 中文(简体)
Jython - Overview
  • 时间:2024-12-22

Jython - Overview


Previous Page Next Page  

Jython is the JVM implementation of the Python programming language. It is designed to run on the Java platform. A Jython program can import and use any Java class. Just as Java, Jython program compiles to bytecode. One of the main advantages is that a user interface designed in Python can use GUI elements of AWT, Swing or SWT Package.

Jython, which started as JPython and was later renamed, follows closely the standard Python implementation called CPython as created by Guido Van Rossum. Jython was created in 1997 by Jim Hugunin. Jython 2.0 was released in 1999. Since then, Jython 2.x releases correspond to equivalent CPython releases. Jython 2.7.0 released in May 2015, corresponds to CPython 2.7. Development of Jython 3.x is under progress.

Difference between Python and Java

Following are the differences between Python and Java −

    Python is a dynamically typed language. Hence, the type declaration of variable is not needed. Java on the other hand is a statically typed language, which means that the type declaration of variable is mandatory and cannot be changed.

    Python has only unchecked exceptions, whereas Java has both checked and unchecked exceptions.

    Python uses indents for scoping, while Java uses matching curly brackets.

    Since Python is an interpreter-based language, it has no separate compilation steps. A Java program however needs to be compiled to bytecode and is in turn executed by a JVM.

    Python supports multiple inheritance, but in Java, multiple inheritance is not possible. It however has implementation of an interface.

    Compared to Java, Python has a richer built-in data structures (psts, dicts, tuples, everything is an object).

Difference between Python and Jython

Following are the differences between Python and Jython −

    Reference implementation of Python, called CPython, is written in C language. Jython on the other hand is completely written in Java and is a JVM implementation.

    Standard Python is available on multiple platforms. Jython is available for any platform with a JVM installed on it.

    Standard Python code compiles to a .pyc file, while Jython program compiles to a .class file.

    Python extensions can be written in C language. Extensions for Jython are written in Java.

    Jython is truly multi-threaded in nature. Python however uses the Global Interpreter Lock (GIL) mechanism for the purpose.

    Both implementations have different garbage collection mechanisms.

In the next chapter, we will learn how to import the Java pbraries in Jython.

Advertisements