Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Jython: Integrating Python and Java

11 344 vues

Publié le

This was a talk I gave at the Salem Java Users Group on 2/5/08.

Publié dans : Technologie
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Jython: Integrating Python and Java

  1. 1. Jython: Integrating Python and Java Charles Anderson Western Skies Consulting Western Oregon University charles@western-skies.us / andersc@wou.edu
  2. 2. 10 Second Summary • Jython is the Python interpreter implemented in Java
  3. 3. Outline • Python • Scripting and embedded languages • Jython • Other Java scripting languages
  4. 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. 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. 6. Hello World • print “hello world” • that’s it - no semicolons, no main function, no curly braces, etc.
  7. 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. 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. 9. More Syntax if x < 0: print ‘negative’ try: z=y/x except ZeroDivisionError, msg: print msg
  10. 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. 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. 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. 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. 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. 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. 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. 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
  18. 18. Demos • Interactive • GUI
  19. 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. 20. Possible Uses • Command prompt for controlling app • Interactive workbench for experimenting • One-off utility work - e.g., data loading • Flexible “business” rules
  21. 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. 22. Jython Information • www.jython.org • There are a couple of Jython books • “Scripting: Higher Level Programming for the 21st Century” - Ousterhout

×