SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Jython: Integrating
   Python and Java
            Charles Anderson
         Western Skies Consulting
        Western Oregon University
charles@western-skies.us / andersc@wou.edu
10 Second Summary


• Jython is the Python interpreter
  implemented in Java
Outline

• Python
• Scripting and embedded languages
• Jython
• Other Java scripting languages
Python Background
• Python is a object-oriented scripting
  language - runs on many platforms
• Mature but still evolving: version 1.0 -
  1994, current version: 2.5, 3.0 under
  development
• Huge user base including Google,Yahoo,
  YouTube, Industrial Light & Magic
Python Overview
• Python is a scripting language - no compile
• Dynamic typing - no variable declarations,
  but strictly typed at runtime
• Simple syntax - large library rather than
  cryptic syntax (c.f., Perl)
• Often a refuge from other languages
Hello World

• print    “hello world”



• that’s it - no semicolons, no main function,
  no curly braces, etc.
Language Features

• Object oriented: hybrid/not pure, multiple
  inheritance - c.f., C++
• Polymorphism without inheritance - “duck
  typing”
• Very dynamic - introspection/reflection is
  simple and powerful - c.f., Java
Syntax

• Pretty simple - familiar to Java programmers
  c = sqrt(a*a, b*b)
  emp = Employee(‘Bob’, ‘Jones’)
  employees[‘Bob’] = emp
  import sys, email.mime.text
More Syntax
if x < 0:
  print ‘negative’
try:
  z=y/x
except ZeroDivisionError, msg:
  print msg
Class Definition
class Point2D:
  def __init__(self, x, y):
    self.x = x
    self.y = y
  def distance(self):
    return math.sqrt(
              self.x**2+self.y**2)
Syntax Notes
• The block structure of code is determined
  by indentation - what you see is what the
  compiler sees
  • No dangling curly braces
• Python favors libraries over fancy, terse
  syntax - c.f., Perl

  • When needed, __method__
Embedded Languages
• TCL was developed to provide a common
  command language for tools written in C
• Adding command line to tools
• Extending TCL to add commands from C
  to TCL
• Similar to Unix shell - C functions instead
  of executable programs
Extending TCL
• TCL uses a simple interface between TCL
  and C code: int argc, char** argv

• Programmer writes thin layer of interface
  functions to expose functionality to TCL
  •   Programmer has to choose functions to be
      exposed

• Can be automated - swig
Scripting a Program
• Do the real work in C (or whatever) and
  glue it together with TCL
 •   Provides extensibility of C tool to users

• Performance of script language doesn’t
  really matter - Pareto principal
 •   E.g., Numeric Python at LLNL

• Can prototype in scripting language
Python Interpreter
• Python is an interpreted language - need an
  interpreter to execute Python code
• Originally written in C - “CPython”
• Code is compiled to byte codes at runtime
• Python can be interfaced with existing C
  code similar to TCL
Jython Interpreter

• Jython is Python interpreter written in Java
• Python code is compiled to Java byte codes
• Aside: Iron Python is interpreter written
  to .Net CLR
Jython Ramifications
• Interpreter written in Java - so what?
• Jython interfaces directly to Java w/o any
  explicit coding
  •   Uses Java introspection/reflection

  •   All Java classes on class path are immediately
      available from Python code

  •   Interactive command line for Java
Demos


• Interactive
• GUI
Java Python Integration

• Python can call Java code
• Java code can call out to Python - possibly
  in a new Python interpreter (sandbox)
• Python code can sub-class Java classes
Possible Uses

• Command prompt for controlling app
• Interactive workbench for experimenting
• One-off utility work - e.g., data loading
• Flexible “business” rules
Scripting Java

• Groovy - groovy.codehaus.org
• JACL (TCL in Java) - tcljava.sourceforge.net
• JRuby - jruby.codehaus.org
• JSR 223 Scripting the Java Platform -
  Java 6 SE
Jython Information

• www.jython.org
• There are a couple of Jython books
• “Scripting: Higher Level Programming for
  the 21st Century” - Ousterhout

Weitere ähnliche Inhalte

Was ist angesagt?

Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI Programming
Ranel Padon
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
Kanchilug
 

Was ist angesagt? (20)

Python Programming - XIII. GUI Programming
Python Programming - XIII. GUI ProgrammingPython Programming - XIII. GUI Programming
Python Programming - XIII. GUI Programming
 
Python
PythonPython
Python
 
PyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fastPyPy 1.2: snakes never crawled so fast
PyPy 1.2: snakes never crawled so fast
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Python Flavors
Python FlavorsPython Flavors
Python Flavors
 
What is Python? An overview of Python for science.
What is Python? An overview of Python for science.What is Python? An overview of Python for science.
What is Python? An overview of Python for science.
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
Golang for OO Programmers
Golang for OO ProgrammersGolang for OO Programmers
Golang for OO Programmers
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Why I Love Python
Why I Love PythonWhy I Love Python
Why I Love Python
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
 
Come With Golang
Come With GolangCome With Golang
Come With Golang
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Python for All
Python for All Python for All
Python for All
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd round
 

Andere mochten auch

[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
Jerry Chou
 
Ruby vs python
Ruby vs pythonRuby vs python
Ruby vs python
Igor Leroy
 

Andere mochten auch (20)

Jython 2.7 and techniques for integrating with Java - Frank Wierzbicki
Jython 2.7 and techniques for integrating with Java - Frank WierzbickiJython 2.7 and techniques for integrating with Java - Frank Wierzbicki
Jython 2.7 and techniques for integrating with Java - Frank Wierzbicki
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
From Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeFrom Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndrome
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
 
Jython
JythonJython
Jython
 
SyPy IronPython
SyPy IronPythonSyPy IronPython
SyPy IronPython
 
KScope14 Jython Scripting
KScope14 Jython ScriptingKScope14 Jython Scripting
KScope14 Jython Scripting
 
Jython
JythonJython
Jython
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Learn 90% of Python in 90 Minutes
Learn 90% of Python in 90 MinutesLearn 90% of Python in 90 Minutes
Learn 90% of Python in 90 Minutes
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Introduction to jython
Introduction to jythonIntroduction to jython
Introduction to jython
 
Git and github introduction
Git and github introductionGit and github introduction
Git and github introduction
 
Hiring_Data_Scientist
Hiring_Data_ScientistHiring_Data_Scientist
Hiring_Data_Scientist
 
Python y Flink
Python y FlinkPython y Flink
Python y Flink
 
Automating and Accelerating Application Deployments to IBM WebSphere without ...
Automating and Accelerating Application Deployments to IBM WebSphere without ...Automating and Accelerating Application Deployments to IBM WebSphere without ...
Automating and Accelerating Application Deployments to IBM WebSphere without ...
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
The .NET developer's introduction to IronPython
The .NET developer's introduction to IronPythonThe .NET developer's introduction to IronPython
The .NET developer's introduction to IronPython
 
Ruby vs python
Ruby vs pythonRuby vs python
Ruby vs python
 
Why Learn Python?
Why Learn Python?Why Learn Python?
Why Learn Python?
 

Ähnlich wie Jython: Integrating Python and Java

Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
gabriellekuruvilla
 
3150 Chapter 2 Part 1
3150 Chapter 2 Part 13150 Chapter 2 Part 1
3150 Chapter 2 Part 1
Mole Wong
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
deimos
 
J Ruby Power On The Jvm
J Ruby Power On The JvmJ Ruby Power On The Jvm
J Ruby Power On The Jvm
QConLondon2008
 

Ähnlich wie Jython: Integrating Python and Java (20)

AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8AOT-compilation of JavaScript with V8
AOT-compilation of JavaScript with V8
 
C Language
C LanguageC Language
C Language
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
3150 Chapter 2 Part 1
3150 Chapter 2 Part 13150 Chapter 2 Part 1
3150 Chapter 2 Part 1
 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
 
Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
J Ruby Power On The Jvm
J Ruby Power On The JvmJ Ruby Power On The Jvm
J Ruby Power On The Jvm
 
Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)Hack Like It's 2013 (The Workshop)
Hack Like It's 2013 (The Workshop)
 
Os Lattner
Os LattnerOs Lattner
Os Lattner
 
Creating a reasonable project boilerplate
Creating a reasonable project boilerplateCreating a reasonable project boilerplate
Creating a reasonable project boilerplate
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 
Introduction to Go for Java Developers
Introduction to Go for Java DevelopersIntroduction to Go for Java Developers
Introduction to Go for Java Developers
 
C tutorial
C tutorialC tutorial
C tutorial
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
C tutorial
C tutorialC tutorial
C tutorial
 
Introduction Of C++
Introduction Of C++Introduction Of C++
Introduction Of C++
 
Number of Computer Languages = 3
Number of Computer Languages = 3Number of Computer Languages = 3
Number of Computer Languages = 3
 

Mehr von Charles Anderson

A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
Charles Anderson
 

Mehr von Charles Anderson (10)

Modern php
Modern phpModern php
Modern php
 
Literate Programming
Literate ProgrammingLiterate Programming
Literate Programming
 
Inrastructure as Code
Inrastructure as CodeInrastructure as Code
Inrastructure as Code
 
How to get a Software Job w/o Experience
How to get a Software Job w/o ExperienceHow to get a Software Job w/o Experience
How to get a Software Job w/o Experience
 
Docker - Hack Salem! - November 2014
Docker - Hack Salem! - November 2014Docker - Hack Salem! - November 2014
Docker - Hack Salem! - November 2014
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
 
A Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVMA Shallow Survey of Alternative Languages on the JVM
A Shallow Survey of Alternative Languages on the JVM
 
How to Get a Software Job w/o Experience
How to Get a Software Job w/o ExperienceHow to Get a Software Job w/o Experience
How to Get a Software Job w/o Experience
 
How To Protect Yourself and Your Computer Online
How To Protect Yourself and Your Computer OnlineHow To Protect Yourself and Your Computer Online
How To Protect Yourself and Your Computer Online
 
Groovy a Scripting Language for Java
Groovy a Scripting Language for JavaGroovy a Scripting Language for Java
Groovy a Scripting Language for Java
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Jython: Integrating Python and Java

  • 1. Jython: Integrating Python and Java Charles Anderson Western Skies Consulting Western Oregon University charles@western-skies.us / andersc@wou.edu
  • 2. 10 Second Summary • Jython is the Python interpreter implemented in Java
  • 3. Outline • Python • Scripting and embedded languages • Jython • Other Java scripting languages
  • 4. Python Background • Python is a object-oriented scripting language - runs on many platforms • Mature but still evolving: version 1.0 - 1994, current version: 2.5, 3.0 under development • Huge user base including Google,Yahoo, YouTube, Industrial Light & Magic
  • 5. Python Overview • Python is a scripting language - no compile • Dynamic typing - no variable declarations, but strictly typed at runtime • Simple syntax - large library rather than cryptic syntax (c.f., Perl) • Often a refuge from other languages
  • 6. Hello World • print “hello world” • that’s it - no semicolons, no main function, no curly braces, etc.
  • 7. Language Features • Object oriented: hybrid/not pure, multiple inheritance - c.f., C++ • Polymorphism without inheritance - “duck typing” • Very dynamic - introspection/reflection is simple and powerful - c.f., Java
  • 8. Syntax • Pretty simple - familiar to Java programmers c = sqrt(a*a, b*b) emp = Employee(‘Bob’, ‘Jones’) employees[‘Bob’] = emp import sys, email.mime.text
  • 9. More Syntax if x < 0: print ‘negative’ try: z=y/x except ZeroDivisionError, msg: print msg
  • 10. Class Definition class Point2D: def __init__(self, x, y): self.x = x self.y = y def distance(self): return math.sqrt( self.x**2+self.y**2)
  • 11. Syntax Notes • The block structure of code is determined by indentation - what you see is what the compiler sees • No dangling curly braces • Python favors libraries over fancy, terse syntax - c.f., Perl • When needed, __method__
  • 12. Embedded Languages • TCL was developed to provide a common command language for tools written in C • Adding command line to tools • Extending TCL to add commands from C to TCL • Similar to Unix shell - C functions instead of executable programs
  • 13. Extending TCL • TCL uses a simple interface between TCL and C code: int argc, char** argv • Programmer writes thin layer of interface functions to expose functionality to TCL • Programmer has to choose functions to be exposed • Can be automated - swig
  • 14. Scripting a Program • Do the real work in C (or whatever) and glue it together with TCL • Provides extensibility of C tool to users • Performance of script language doesn’t really matter - Pareto principal • E.g., Numeric Python at LLNL • Can prototype in scripting language
  • 15. Python Interpreter • Python is an interpreted language - need an interpreter to execute Python code • Originally written in C - “CPython” • Code is compiled to byte codes at runtime • Python can be interfaced with existing C code similar to TCL
  • 16. Jython Interpreter • Jython is Python interpreter written in Java • Python code is compiled to Java byte codes • Aside: Iron Python is interpreter written to .Net CLR
  • 17. Jython Ramifications • Interpreter written in Java - so what? • Jython interfaces directly to Java w/o any explicit coding • Uses Java introspection/reflection • All Java classes on class path are immediately available from Python code • Interactive command line for Java
  • 19. Java Python Integration • Python can call Java code • Java code can call out to Python - possibly in a new Python interpreter (sandbox) • Python code can sub-class Java classes
  • 20. Possible Uses • Command prompt for controlling app • Interactive workbench for experimenting • One-off utility work - e.g., data loading • Flexible “business” rules
  • 21. Scripting Java • Groovy - groovy.codehaus.org • JACL (TCL in Java) - tcljava.sourceforge.net • JRuby - jruby.codehaus.org • JSR 223 Scripting the Java Platform - Java 6 SE
  • 22. Jython Information • www.jython.org • There are a couple of Jython books • “Scripting: Higher Level Programming for the 21st Century” - Ousterhout