Skip to content

Latest commit

 

History

History
43 lines (35 loc) · 2.8 KB

index.md

File metadata and controls

43 lines (35 loc) · 2.8 KB
title
Home

What is Jython?

Jython is a Java implementation of Python that combines expressive power with clarity. Jython is freely available for both commercial and non-commercial use and is distributed with source code under the PSF License v2. Jython is complementary to Java and is especially suited for the following tasks:

  • Embedded scripting - Java programmers can add the Jython libraries to their system to allow end users to write simple or complicated scripts that add functionality to the application.
  • Interactive experimentation - Jython provides an interactive interpreter that can be used to interact with Java packages or with running Java applications. This allows programmers to experiment and debug any Java system using Jython.
  • Rapid application development - Python programs are typically 2-10x shorter than the equivalent Java program. This translates directly to increased programmer productivity. The seamless interaction between Python and Java allows developers to freely mix the two languages both during development and in shipping products.
Here is an example of running Python code inside a simple Java application
import org.python.util.PythonInterpreter;

public class JythonHelloWorld {
  public static void main(String[] args) {
    try(PythonInterpreter pyInterp = new PythonInterpreter()) {
      pyInterp.exec("print('Hello Python World!')");
    }
  }
}
Here is an example of using Java from Python code
from java.lang import System # Java import

print('Running on Java version: ' + System.getProperty('java.version'))
print('Unix time from Java: ' + str(System.currentTimeMillis()))

Ready to get started? Head over to Downloads

Who uses Jython?

Jython is embedded in lots of projects. See some from MVNRepository

  • IBM Websphere - Use Jython to provide administrative scripting capabilities.
  • Apache PIG - Use Jython to support user defined functions.
  • ImageJ - Use Jython to provide scripted image processing.
  • GDA - Use Jython to script scientific experiments.
  • Robot Framework - A generic test automation framework for acceptance testing and acceptance test-driven development (ATDD) which runs on Jython.
  • TigerJython - An educational programming environment that is based on Jython.
  • JEM/JythonMusic - An environment for music making and creative programming using Jython.