SlideShare una empresa de Scribd logo
1 de 22
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

[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
 

Destacado (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?
 

Similar a 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
 

Similar a 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
 

Más de 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
 

Más de 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
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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