SlideShare uma empresa Scribd logo
1 de 18
Baixar para ler offline
.

Jython
.

Python on the JVM
Robert Bachmann
JSUG Meeting #49

1
Outline

•
•
•
•

Use Cases
Limitations
Usage & javax.script / JSR223
A (short) case study

2
Python?

• Scripting language
• Dynamically typed
• Standard interpreter: (C)Python

3
A broader view…

• JRuby (Ruby on the JVM)
• Groovy (native JVM language)
• CLR: IronPython & IronRuby

4
Use cases

•
•
•
•
•
•

Re-use of Java libraries
Re-use of Java infrastructure
Adding scripting abilities to a Java software
Prototyping
Test scripting
Performance improvements w.r.t (C)Python

5
Limitations

•
•
•
•

Not a Java replacement (cf. Scala)
No current compiler
Can not use Python modules with C code
Jython lags behind (C)Python & IronPython
Jython: 2.5.3 stable / 2.7a2 alpha
(C)Python: 2.7 stable
IronPython: 2.7 stable

• Performance worse than Java

6
Usage

•
•
•
•
•

“Hello World” with Jython
Using Java from Jython
Using Jython with javax.script
Using Jython from Java
Deployment options

7
Hello World

# program.py
print ”Hello␣World”

$ jython program.py
Hello World

8
Hello World with classes and modules
### demo.py
class Hello:
def greet(self, name):
print ”Hello␣” + name
### program.py
from demo import Hello
h = Hello()
h.greet(”JSUG”)
# or:
import demo
h = demo.Hello()
h.greet(”JSUG”)

9
Using Java from Jython – Example

# Hello World with Swing
from javax.swing import JOptionPane
JOptionPane.showMessageDialog(None, ”Hello!”)

10
Using Java from Jython – Notes

• Jython classes can
implement Java interfaces
extend Java classes
• Classpath
import uses classpath via sys.path
Add JARs via sys.path.append()

11
javax.script

• JSR223: Scripting for the JavaTM Platform
• API for using scripting languages with Java
• Central class: ScriptEngine

12
javax.script

ScriptEngineManager factory =
new ScriptEngineManager();
ScriptEngine engine =
factory.getEngineByName(”python”);
engine.eval(”print␣’Hello,␣World’”);
engine.put(”x”, 10)
engine.eval(”y␣=␣x␣*␣2”);
Object y = engine.get(”y”)
System.out.println(y)

13
Using Jython classes from Java

• Steps:
Derive from Java class / interface
Use JythonInterperter to create an
instance
Call the instance’s __tojava__ method
• Complete solution:
http://www.jython.org/jythonbook/en/1.0/
JythonAndJavaIntegration.html

14
Deployment options

• Servlet Contaier
org.python.util.PyServlet
WSGI via modjy
• Standalone .jar

15
Case study

• Scenario: A C library with Java and .Net
wrappers
• Challenge: Automated testing of all libraries
• Solution: Single-source test automation
with Jython/IronPython

16
Questions?

17
Thanks
Twitter

@robertbachmann

Email rb@

—

.at

18

Mais conteúdo relacionado

Mais procurados

Enjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfEnjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProf
mametter
 
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
Igalia
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
mametter
 
Domain Attention with an Ensemble of Experts
Domain Attention with an Ensemble of ExpertsDomain Attention with an Ensemble of Experts
Domain Attention with an Ensemble of Experts
Hiroki Ouchi
 

Mais procurados (12)

Enjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProfEnjoy Ruby Programming in IDE and TypeProf
Enjoy Ruby Programming in IDE and TypeProf
 
Pharo Arm Status
Pharo Arm StatusPharo Arm Status
Pharo Arm Status
 
Erlang os
Erlang osErlang os
Erlang os
 
Performance Testing with JMeter, Taurus & Jenkins
Performance Testing with JMeter, Taurus & JenkinsPerformance Testing with JMeter, Taurus & Jenkins
Performance Testing with JMeter, Taurus & Jenkins
 
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
ARB_gl_spirv implementation in Mesa: status update (XDC 2018)
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3A Static Type Analyzer of Untyped Ruby Code for Ruby 3
A Static Type Analyzer of Untyped Ruby Code for Ruby 3
 
Ruby Introduction
Ruby IntroductionRuby Introduction
Ruby Introduction
 
Domain Attention with an Ensemble of Experts
Domain Attention with an Ensemble of ExpertsDomain Attention with an Ensemble of Experts
Domain Attention with an Ensemble of Experts
 
Effective C++
Effective C++Effective C++
Effective C++
 
A Plan towards Ruby 3 Types
A Plan towards Ruby 3 TypesA Plan towards Ruby 3 Types
A Plan towards Ruby 3 Types
 
Flutter 2
Flutter 2Flutter 2
Flutter 2
 

Destaque (20)

Mixing Python and Java
Mixing Python and JavaMixing Python and Java
Mixing Python and Java
 
Jython: Integrating Python and Java
Jython: Integrating Python and JavaJython: Integrating Python and Java
Jython: Integrating Python and Java
 
Java 8
Java 8Java 8
Java 8
 
Google's Guava
Google's GuavaGoogle's Guava
Google's Guava
 
JNA
JNAJNA
JNA
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
Garbageayush anubhav
Garbageayush anubhavGarbageayush anubhav
Garbageayush anubhav
 
halloween
halloweenhalloween
halloween
 
Power de pepe
Power de pepePower de pepe
Power de pepe
 
Power mª dolores
Power mª doloresPower mª dolores
Power mª dolores
 
COSTOS
COSTOSCOSTOS
COSTOS
 
Otd mro
Otd mroOtd mro
Otd mro
 
Power rosana
Power rosanaPower rosana
Power rosana
 
Money laundry-rAzik's
Money laundry-rAzik'sMoney laundry-rAzik's
Money laundry-rAzik's
 
Power asun
Power asunPower asun
Power asun
 
копия Svad me pitch
копия Svad me pitchкопия Svad me pitch
копия Svad me pitch
 
Tambang pasir gue
Tambang pasir gueTambang pasir gue
Tambang pasir gue
 
копия Svad me pitch
копия Svad me pitchкопия Svad me pitch
копия Svad me pitch
 
Parque de bomberos 2ª parte 4º b
Parque de bomberos 2ª parte 4º bParque de bomberos 2ª parte 4º b
Parque de bomberos 2ª parte 4º b
 
Notary Mama - Documents at your Doorstep
Notary Mama - Documents at your DoorstepNotary Mama - Documents at your Doorstep
Notary Mama - Documents at your Doorstep
 

Semelhante a Jython

JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
elliando dias
 

Semelhante a Jython (20)

Java performance monitoring
Java performance monitoringJava performance monitoring
Java performance monitoring
 
Java platform
Java platformJava platform
Java platform
 
Cucumber presenation
Cucumber presenationCucumber presenation
Cucumber presenation
 
Java-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdfJava-light-speed NebraskaCode.pdf
Java-light-speed NebraskaCode.pdf
 
White and Black Magic on the JVM
White and Black Magic on the JVMWhite and Black Magic on the JVM
White and Black Magic on the JVM
 
Introduction to Robot Framework – Exove
Introduction to Robot Framework – ExoveIntroduction to Robot Framework – Exove
Introduction to Robot Framework – Exove
 
GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28GraalVM - JBCNConf 2019-05-28
GraalVM - JBCNConf 2019-05-28
 
Polygot Java EE on the GraalVM
Polygot Java EE on the GraalVMPolygot Java EE on the GraalVM
Polygot Java EE on the GraalVM
 
Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
How the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java CodeHow the HotSpot and Graal JVMs execute Java Code
How the HotSpot and Graal JVMs execute Java Code
 
Why JVM will outlive java?
Why JVM will outlive java?Why JVM will outlive java?
Why JVM will outlive java?
 
Lifecycle of a JIT compiled code
Lifecycle of a JIT compiled codeLifecycle of a JIT compiled code
Lifecycle of a JIT compiled code
 
Keep GCC running: 2019 update (BlinkOn 10)
Keep GCC running: 2019 update (BlinkOn 10)Keep GCC running: 2019 update (BlinkOn 10)
Keep GCC running: 2019 update (BlinkOn 10)
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on Raspberry
 
JCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of JavaJCConf 2018 - Retrospect and Prospect of Java
JCConf 2018 - Retrospect and Prospect of Java
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 
Java Programming Environment,JDK,JRE,JVM.pptx
Java Programming Environment,JDK,JRE,JVM.pptxJava Programming Environment,JDK,JRE,JVM.pptx
Java Programming Environment,JDK,JRE,JVM.pptx
 
What’s expected in Java 9
What’s expected in Java 9What’s expected in Java 9
What’s expected in Java 9
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
 
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...Customize and Secure the Runtime and Dependencies of Your Procedural Language...
Customize and Secure the Runtime and Dependencies of Your Procedural Language...
 

Último

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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
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
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
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
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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, ...
 
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...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
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
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
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...
 

Jython