Jython Essentials

Book description

Jython is an implementation of the Python programming language written in 100% pure Java, so it runs under any compliant Java Virtual Machine. The secret to Jython's popularity lies in the combination of Java's librariesand tools with Python's rapid development capabilities. With Jython, you can write Python programs that integrate seamlessly with any Java code. And like Python, Jython can be used interactively, so you can get immediate results as you are programming.Jython Essentials provides a solid introduction to the Python language, offering a brief but thorough tour of the Python concepts you'll need to understand to use Jython effectively. The book makes frequent comparisonsbetween Python and Java, with special emphasis on the different object-oriented semantics of the two languages, so Java programmers can quickly get up to speed with Jython.Jython Essentials also covers the various ways in which Jython and Java can interact. For example, Jython code can create instances of pre-existing Java classes and call methods in those instances. You can write Jython classes that are direct subclasses of existing Java classesand use introspection to discern the capabilities of JavaBeans components. This book provides examples of using Jython with existing Java libraries, including the Swing GUI toolkit, the JDBC database API, the Servlet API, and various XML tools. And finally, the book shows howJython can be used as a scripting language within a Java program.With Jython Essentials, you have everything you need to start creating applications that mix the best of Python's interactivity and Java's robust libraries.

Publisher resources

View/Submit Errata

Table of contents

  1. A Note Regarding Supplemental Files
  2. Foreword
  3. Preface
    1. Audience Expectations
    2. Organization
    3. Further Reading
    4. Conventions Used in This Book
    5. How to Contact Us
    6. Samuele Pedroni’s Acknowledgments
    7. Noel Rappin’s Acknowledgments
  4. 1. Introduction to Jython
    1. Jython Requirements
    2. Welcome to Jython
      1. Starting Jython
      2. Adding Items to the Window
      3. Adding Behavior
    3. What’s Jython Good For?
    4. The Benefits of Jython
      1. For Java Programmers
      2. For Python Programmers
    5. The Speed Question
    6. The Rest of the Book
  5. 2. Jython Basics
    1. Running Jython
    2. Basic Types
    3. Operators
    4. Numeric Types
      1. Integer
      2. Long
      3. Float
      4. Complex
      5. Numerical Functions
    5. Sequences: Lists and Tuples
      1. Sequence Access
      2. Sequence Functions and Functions
      3. Functional Programming
      4. Tuples: Immutable Sequences
    6. Strings
      1. String Formatting
      2. String Functions
    7. Mappings and Dictionaries
    8. Jython Files
  6. 3. Jython Control Flow
    1. Statements and Expressions
    2. Assignment
      1. Unpacking Assignment
      2. Augmented Assignment
    3. Printing
    4. Blocks
    5. Conditional Logic
    6. Loops
    7. List Comprehensions
    8. Exceptions
    9. Evaluating Code Dynamically
  7. 4. Modules and Functions
    1. Modules
    2. Functions
    3. Parameter Passing with Style
      1. Scoping Rules
      2. Flying First Class
    4. Import Statements and Packages
      1. Import Statements
      2. Importing Java Classes
        1. Auto-loading through lookup
      3. Reload
  8. 5. Object-Oriented Jython
    1. Creating Classes
    2. Methods
    3. Classes, Instances, and Access Control
      1. Class and Static Attributes
      2. Access Control
      3. Get and Set Methods
      4. Using __getattr__
      5. Using __setattr__
    4. Inheritance
    5. Special Methods
      1. General Instance Special Methods
      2. Sequences and Mappings
      3. Numbers
  9. 6. Using Java from Jython
    1. Basic Object Usage
    2. Automatic Type Conversion
      1. Managing Overloaded Methods
      2. Basic Data Conversions
      3. Converting Arrays
    3. Java Arrays and the jarray Module
    4. Java-to-Python Types: Automatic Conversion
    5. Collection Wrappers
    6. Avoiding Name Collisions
  10. 7. Inheriting from Java
    1. Basic Mechanics
    2. Java Interoperation and Overriding
    3. Calling Super Methods and Constructors
  11. 8. Reflection and JavaBeans
    1. Bean-Based Reflection
      1. Using Beans in Jython
      2. Indexed Properties
      3. Event Properties
    2. Python-Based Reflection
      1. Reflecting on Java Objects
      2. Active Reflection
  12. 9. Using Swing
    1. Java Versus Jython
    2. A Calculator
    3. An HTML Browser
    4. An HTML Source Browser
  13. 10. Using Java Libraries
    1. JDBC and the Python Database API
      1. Using zxJDBC
      2. Connection Objects
      3. Cursor Objects
    2. Servlets and PyServlet
      1. Using PyServlet
      2. A Python Template Tool
      3. Reloading Servlet Modules
    3. Jython and XML
      1. SAX and DOM
      2. JDOM and Jython
  14. 11. Jython Standard Library
    1. Using Python Modules
    2. System and File Modules
      1. The sys Module
      2. The os Module
      3. The os.path module
      4. File Pattern Matching with glob
    3. Regular Expressions
      1. The re Module
      2. Match Objects
      3. Regular Expression Objects
      4. Special Characters
    4. Serialization and Pickling
    5. Unit Testing with PyUnit
      1. Simple Tests
      2. Tests in Groups
  15. 12. Embedding Jython Inside Java
    1. Setting Up an Interpreter
    2. Executing Code
    3. Accessing the Interpreter Namespace
    4. Using PyObjects
    5. PyObject Subclasses
    6. Catching Exceptions
    7. Embedding Examples
  16. 13. Compiling Jython
    1. Why Compile?
    2. The Compiler in Action
      1. Java Source
      2. Top-Level Java
    3. Packaging in Java Archives
    4. Using Jython in Java
    5. A Simple Applet
  17. A. Installing Jython
  18. B. Jython Options and Registry
    1. Jython Options
    2. Jython Compiler Options
    3. The Jython Registry
  19. C. Jython Exceptions
  20. D. Jython and CPython Differences
    1. Jython Extensions
    2. Major Design Differences
    3. Minor Design Differences
    4. Differences Due to Java Details
    5. Differences Due to Java Limitations
    6. Minor Issues
    7. Java Objects Versus Python Objects
  21. E. Java-to-Python Quick Reference
    1. Basic Data Types
    2. Advanced Data Types
    3. Logical Operators
    4. Arithmetic Operators
    5. Control Statements
    6. Definition Statements
    7. String Methods
    8. List Methods
    9. Dictionary Functions
  22. Index
  23. About the Authors
  24. Colophon
  25. Copyright

Product information

  • Title: Jython Essentials
  • Author(s): Samuele Pedroni, Noel Rappin
  • Release date: March 2002
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596002473