SlideShare a Scribd company logo
TechTalk: Communication between Java and Python Anastasia Eifer, DLR Simulations- und Softwaretechnik 03.06.2008
Contents Introduction Motivation Communication through bindings (JPE, JPI) Jython (JPython)  Jepp JPype Client-server communication (SPYRO, Pyro) Summary
Introduction (1/4)  Java Object-oriented Platform-independent Robust Distributed  Secure One of the most popular programming languages today
Introduction (2/4)  Python Dynamic multi-paradigm programming language  Object-oriented Functional Aspect-oriented Scripting language … Remarkably clean syntax  Short development time Extensive standard libraries  Highly readable language  Can be learned in a few days
Introduction (3/4) "Hello World!"-Code Java Python print("Hello World!") public class HelloWorld {        public static void main(String[] args) {            System.out.println("Hello World!");        }   }  
Introduction (4/4) Print the integers from 1 to 9   Java Python for (int i = 1; i < 10; i++)  {   System.out.println(i);   }   for i in range (1,10):        print i 
Motivation Java and Python: a perfect couple   Building software from existing components Combination of a system programming language (Java) and a scripting language (Python) Rapid application development  Creating automated tests  Embedded scripting
Communication through bindings JPE  Java-Python Extension JNI-based wrapper Integration of Java and standard Python (CPython) http://jpe.sourceforge.net/ JPE project does not appear to be active JPI Java-Python Interface   JNI-based wrapper JPI  project is no longer developed
Jython (1/4)  What is Jython?   Complete re-implementation of the Python programming language in Java Embedded scripting  Interactive experimentation  Rapid application development  Home http://www.jython.org
Jython (2/4)  Interactive experimentation C:\jython>jython Jython 2.0 on java1.2.1 Type &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. >>> from java.util import Random >>> r = Random() >>> r.nextInt()-790940041 >>> for i in range(3): ...     print r.nextDouble() ... 0.23347681506123852 0.8526595592189546 0.3647833839988137 >>>
Jython (3/4)  Running Python scripts   import org.python.util.PythonInterpreter; import org.python.core.*; class TestPython { public static void main ( String[] args ) {   try {   org.python.util.PythonInterpreter python =  new org.python.util.PythonInterpreter();   python.execfile ( &quot;testscript.py&quot; );   } catch ( Exception e ) {   System.out.println ( &quot;An error was encountered.&quot; );   } } }
Jython (4/4)  Current state of development   The current release is Jython-2.2.1  It is equivalent to the 2.2 release of CPython  CPython 2.5 is targeted for the next release  Jython-2.2.1  supports a large majority of the standard Python library Jython-2.2.1 doesn't support a number of Python's built-in modules ! (e.g. those that are written in C for CPython)
Jepp (1/4) What is Jepp? Java Embedded Python   Embeds CPython in Java Communication through interfacing at the native level in both Virtual Machines Home http://jepp.sourceforge.net /
Jepp (2/4) Using Jepp from within Java „ Hello World!“-Code Running Python scripts Jep jep = new Jep(); jep.eval(&quot;print 'Hello World!'&quot;); jep.close();  Jep jep = new Jep(false); jep.runScript(&quot;C:\\tempguatda.com/cmx.p\\testscript.py&quot;); jep.close();
Jepp (3/4) Features Using the console ( console.py  script)  Creating new exception types on the fly  $ java -jar jep.jar console.py >>> from java.lang import * >>> s = String('do crazy stuff') >>> print String(s.toCharArray()[3:8]) crazy   >>> from java.io import FileInputStream >>> try: ...  FileInputStream('no such file') ... except(jep.FileNotFoundException): ...  print 'File not found.' ... File not found.
Jepp (4/4) Summary Very good scripting solution for Java  Run your existing Python scripts from Java Access to high-quality Python extensions Jepp's console provides an easy way to examine scripts and learn how to use new APIs
JPype (1/3) What is JPype? JNI-based wrapper   Communication through interfacing at the native level in both Virtual Machines Full access to java class libraries  Home http://jpype.sourceforge.net /
JPype (2/3) „ Hello World!“-Code from jpype import * startJVM(path to jvm.dll, &quot;-ea&quot;)  java.lang.System.out.println(&quot;Hello World&quot;) shutdownJVM()
JPype (3/3) Running Python scripts  import jpype #start JVM with class path startJVM(path to jvm.dll, &quot;-ea&quot;)  #create reference to java package javaPackage = jpype.JPackage(&quot; JavaPackageName &quot; )  #create reference to java class  javaClass = javaPackage. JavaClassName  #create instance of java class javaObject = javaClass() #call java methods javaObject. JavaMethodName()  #shutdown JVM jpype.shutdownJVM()
Client-server communication SPIRO Simple Python Interface to Remote Objects   Handy bridge between CPython and Java (via Jython)  http://www.freenet.org.nz/python/spiro Pyro  Python Remote Objects http://pyro.sourceforge.net /
Python  Interpreter Python  Interpreter Java Virtual Machine (JVM) Java Code (Anwendung) Jepp JNI Python  Code JPype Jython Python  Code Interface/Protokoll Python  Code Python  Code (Autor: Andreas Schreiber)
Summary Reimplementation of Python (Jython) (+) Very tight integration with Java (+) One runtime environment (-) Jython-2.2.1 doesn't support a number of Python's built-in modules, it is slower in comparison to CPython Communication through Virtual Machines (JPype, Jepp, JPE) (+) CPython‘s speed (+)  Access to high-quality Python extensions (-) Two runtime environments Client-server communication (+) System- and language independence (-) Significant overhead, development time-consuming
Links Exploring Python   Markus Nix (Hrsg.), Markus Nix, Martin Grimme, Torsten Marek, Michael Weigend, Wolfgang Weitz ( Download )  Communication   between  Java and Python

More Related Content

PDF
Log analysis with the elk stack
PPTX
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
PPTX
Troubleshooting MySQL from a MySQL Developer Perspective
PPTX
Background processing with hangfire
PPTX
Elk with Openstack
PDF
Where Site Migrations Go Wrong & Sabotage SEO
PPTX
Dynamic filtering for presto join optimisation
PDF
Nick Fisk - low latency Ceph
Log analysis with the elk stack
Exactly-Once Financial Data Processing at Scale with Flink and Pinot
Troubleshooting MySQL from a MySQL Developer Perspective
Background processing with hangfire
Elk with Openstack
Where Site Migrations Go Wrong & Sabotage SEO
Dynamic filtering for presto join optimisation
Nick Fisk - low latency Ceph

What's hot (20)

PDF
Data engineering zoomcamp introduction
PDF
Running Apache NiFi with Apache Spark : Integration Options
PDF
Advanced RAC troubleshooting: Network
PDF
Mikrotik Load Balancing with PCC
PPTX
Introduction to Storm
PDF
分散DB Apache Kuduのアーキテクチャ DBの性能と一貫性を両立させる仕組み 「HybridTime」とは
PPTX
SQL Server 2016 - Always On.pptx
PPTX
Introduction to ELK
PDF
JJUG CCC 2018 Spring - I-7 (俺が)はじめての Netty
PDF
Apache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
PDF
Delta: Building Merge on Read
PPTX
From cache to in-memory data grid. Introduction to Hazelcast.
PDF
PPTX
ELK Stack
PPTX
An Introduction to Elastic Search.
PDF
Apache Kylin: Speed Up Cubing with Apache Spark with Luke Han and Shaofeng Shi
KEY
Introduction to memcached
PDF
Introduction to MongoDB
PDF
楽天のプライベートクラウドを支えるフラッシュストレージ
PDF
Optimizing RocksDB for Open-Channel SSDs
Data engineering zoomcamp introduction
Running Apache NiFi with Apache Spark : Integration Options
Advanced RAC troubleshooting: Network
Mikrotik Load Balancing with PCC
Introduction to Storm
分散DB Apache Kuduのアーキテクチャ DBの性能と一貫性を両立させる仕組み 「HybridTime」とは
SQL Server 2016 - Always On.pptx
Introduction to ELK
JJUG CCC 2018 Spring - I-7 (俺が)はじめての Netty
Apache Spark Data Source V2 with Wenchen Fan and Gengliang Wang
Delta: Building Merge on Read
From cache to in-memory data grid. Introduction to Hazelcast.
ELK Stack
An Introduction to Elastic Search.
Apache Kylin: Speed Up Cubing with Apache Spark with Luke Han and Shaofeng Shi
Introduction to memcached
Introduction to MongoDB
楽天のプライベートクラウドを支えるフラッシュストレージ
Optimizing RocksDB for Open-Channel SSDs
Ad

Similar to Communication between Java and Python (20)

PPT
Mixing Python and Java
PDF
Jython 2.7 and techniques for integrating with Java - Frank Wierzbicki
PPTX
Integrating Java with python
PDF
Jython: Integrating Python and Java
PDF
PDF
Jython
PDF
Jython-Introduction
PPT
Introduction to jython
PPTX
IPT 2.pptx
PDF
Jython on Django
PPTX
Jython for Embedded Software Validation
ZIP
An Introduction to PyPy
PPTX
python.pptx
PPT
Python Introduction
PPT
What do you mean it needs to be Java based? How jython saved the day.
PDF
Jython in workflow and rules engines
ODP
Django on Jython, PyCon 2009
ODP
Django On Jython (for Portland and Boulder Python user groups presentations)
Mixing Python and Java
Jython 2.7 and techniques for integrating with Java - Frank Wierzbicki
Integrating Java with python
Jython: Integrating Python and Java
Jython
Jython-Introduction
Introduction to jython
IPT 2.pptx
Jython on Django
Jython for Embedded Software Validation
An Introduction to PyPy
python.pptx
Python Introduction
What do you mean it needs to be Java based? How jython saved the day.
Jython in workflow and rules engines
Django on Jython, PyCon 2009
Django On Jython (for Portland and Boulder Python user groups presentations)
Ad

More from Andreas Schreiber (20)

PPTX
Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
PPTX
Visualization of Software Architectures in Virtual Reality and Augmented Reality
PPTX
Provenance as a building block for an open science infrastructure
PPTX
Raising Awareness about Open Source Licensing at the German Aerospace Center
PDF
Open Source Licensing for Rocket Scientists
PDF
Interactive Visualization of Software Components with Virtual Reality Headsets
PPTX
Provenance for Reproducible Data Science
PPTX
Visualizing Provenance using Comics
PPTX
Quantified Self Comics
PPTX
Nachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
PPTX
Reproducible Science with Python
PPTX
Python at Warp Speed
PPTX
A Provenance Model for Quantified Self Data
PPTX
Open Source im DLR
PDF
Tracking after Stroke: Doctors, Dogs and All The Rest
PPTX
High Throughput Processing of Space Debris Data
PDF
Bericht von der QS15 Conference & Exposition
PPTX
Telemedizin: Gesundheit, messbar für jedermann
PDF
Big Python
PDF
Quantified Self mit Wearable Devices und Smartphone-Sensoren
Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
Visualization of Software Architectures in Virtual Reality and Augmented Reality
Provenance as a building block for an open science infrastructure
Raising Awareness about Open Source Licensing at the German Aerospace Center
Open Source Licensing for Rocket Scientists
Interactive Visualization of Software Components with Virtual Reality Headsets
Provenance for Reproducible Data Science
Visualizing Provenance using Comics
Quantified Self Comics
Nachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
Reproducible Science with Python
Python at Warp Speed
A Provenance Model for Quantified Self Data
Open Source im DLR
Tracking after Stroke: Doctors, Dogs and All The Rest
High Throughput Processing of Space Debris Data
Bericht von der QS15 Conference & Exposition
Telemedizin: Gesundheit, messbar für jedermann
Big Python
Quantified Self mit Wearable Devices und Smartphone-Sensoren

Recently uploaded (20)

DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
sap open course for s4hana steps from ECC to s4
The AUB Centre for AI in Media Proposal.docx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Programs and apps: productivity, graphics, security and other tools
The Rise and Fall of 3GPP – Time for a Sabbatical?
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Dropbox Q2 2025 Financial Results & Investor Presentation
Chapter 3 Spatial Domain Image Processing.pdf
sap open course for s4hana steps from ECC to s4

Communication between Java and Python

  • 1. TechTalk: Communication between Java and Python Anastasia Eifer, DLR Simulations- und Softwaretechnik 03.06.2008
  • 2. Contents Introduction Motivation Communication through bindings (JPE, JPI) Jython (JPython) Jepp JPype Client-server communication (SPYRO, Pyro) Summary
  • 3. Introduction (1/4) Java Object-oriented Platform-independent Robust Distributed Secure One of the most popular programming languages today
  • 4. Introduction (2/4) Python Dynamic multi-paradigm programming language Object-oriented Functional Aspect-oriented Scripting language … Remarkably clean syntax Short development time Extensive standard libraries Highly readable language Can be learned in a few days
  • 5. Introduction (3/4) &quot;Hello World!&quot;-Code Java Python print(&quot;Hello World!&quot;) public class HelloWorld {        public static void main(String[] args) {            System.out.println(&quot;Hello World!&quot;);        }   }  
  • 6. Introduction (4/4) Print the integers from 1 to 9 Java Python for (int i = 1; i < 10; i++)  {   System.out.println(i);   }  for i in range (1,10):        print i 
  • 7. Motivation Java and Python: a perfect couple Building software from existing components Combination of a system programming language (Java) and a scripting language (Python) Rapid application development Creating automated tests Embedded scripting
  • 8. Communication through bindings JPE Java-Python Extension JNI-based wrapper Integration of Java and standard Python (CPython) http://jpe.sourceforge.net/ JPE project does not appear to be active JPI Java-Python Interface JNI-based wrapper JPI project is no longer developed
  • 9. Jython (1/4) What is Jython? Complete re-implementation of the Python programming language in Java Embedded scripting Interactive experimentation Rapid application development Home http://www.jython.org
  • 10. Jython (2/4) Interactive experimentation C:\jython>jython Jython 2.0 on java1.2.1 Type &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. >>> from java.util import Random >>> r = Random() >>> r.nextInt()-790940041 >>> for i in range(3): ...     print r.nextDouble() ... 0.23347681506123852 0.8526595592189546 0.3647833839988137 >>>
  • 11. Jython (3/4) Running Python scripts import org.python.util.PythonInterpreter; import org.python.core.*; class TestPython { public static void main ( String[] args ) { try { org.python.util.PythonInterpreter python = new org.python.util.PythonInterpreter(); python.execfile ( &quot;testscript.py&quot; ); } catch ( Exception e ) { System.out.println ( &quot;An error was encountered.&quot; ); } } }
  • 12. Jython (4/4) Current state of development The current release is Jython-2.2.1 It is equivalent to the 2.2 release of CPython CPython 2.5 is targeted for the next release Jython-2.2.1 supports a large majority of the standard Python library Jython-2.2.1 doesn't support a number of Python's built-in modules ! (e.g. those that are written in C for CPython)
  • 13. Jepp (1/4) What is Jepp? Java Embedded Python Embeds CPython in Java Communication through interfacing at the native level in both Virtual Machines Home http://jepp.sourceforge.net /
  • 14. Jepp (2/4) Using Jepp from within Java „ Hello World!“-Code Running Python scripts Jep jep = new Jep(); jep.eval(&quot;print 'Hello World!'&quot;); jep.close(); Jep jep = new Jep(false); jep.runScript(&quot;C:\\tempguatda.com/cmx.p\\testscript.py&quot;); jep.close();
  • 15. Jepp (3/4) Features Using the console ( console.py script) Creating new exception types on the fly $ java -jar jep.jar console.py >>> from java.lang import * >>> s = String('do crazy stuff') >>> print String(s.toCharArray()[3:8]) crazy >>> from java.io import FileInputStream >>> try: ... FileInputStream('no such file') ... except(jep.FileNotFoundException): ... print 'File not found.' ... File not found.
  • 16. Jepp (4/4) Summary Very good scripting solution for Java Run your existing Python scripts from Java Access to high-quality Python extensions Jepp's console provides an easy way to examine scripts and learn how to use new APIs
  • 17. JPype (1/3) What is JPype? JNI-based wrapper Communication through interfacing at the native level in both Virtual Machines Full access to java class libraries Home http://jpype.sourceforge.net /
  • 18. JPype (2/3) „ Hello World!“-Code from jpype import * startJVM(path to jvm.dll, &quot;-ea&quot;) java.lang.System.out.println(&quot;Hello World&quot;) shutdownJVM()
  • 19. JPype (3/3) Running Python scripts import jpype #start JVM with class path startJVM(path to jvm.dll, &quot;-ea&quot;) #create reference to java package javaPackage = jpype.JPackage(&quot; JavaPackageName &quot; ) #create reference to java class javaClass = javaPackage. JavaClassName #create instance of java class javaObject = javaClass() #call java methods javaObject. JavaMethodName() #shutdown JVM jpype.shutdownJVM()
  • 20. Client-server communication SPIRO Simple Python Interface to Remote Objects Handy bridge between CPython and Java (via Jython) http://www.freenet.org.nz/python/spiro Pyro Python Remote Objects http://pyro.sourceforge.net /
  • 21. Python Interpreter Python Interpreter Java Virtual Machine (JVM) Java Code (Anwendung) Jepp JNI Python Code JPype Jython Python Code Interface/Protokoll Python Code Python Code (Autor: Andreas Schreiber)
  • 22. Summary Reimplementation of Python (Jython) (+) Very tight integration with Java (+) One runtime environment (-) Jython-2.2.1 doesn't support a number of Python's built-in modules, it is slower in comparison to CPython Communication through Virtual Machines (JPype, Jepp, JPE) (+) CPython‘s speed (+) Access to high-quality Python extensions (-) Two runtime environments Client-server communication (+) System- and language independence (-) Significant overhead, development time-consuming
  • 23. Links Exploring Python Markus Nix (Hrsg.), Markus Nix, Martin Grimme, Torsten Marek, Michael Weigend, Wolfgang Weitz ( Download ) Communication between Java and Python