Home Page Icon
Home Page
Table of Contents for
IV. Appendix
Close
IV. Appendix
by Robert W. Bill
Jython for Java Programmers
Copyright
Dedication
About the Author
About the Technical Reviewers
Acknowledgments
Tell Us What You Think
Introduction
What Is Jython?
Why Jython?
Seamless Access to Java Classes
Efficiency
Dynamic Types
Introspection and Dynamic Execution
First-Class Functions and Functional Programming
Short Learning Curve
Write Once, Run Anywhere
Java Security
Code Clarity
Unicode and Internationalization
Hotspot and Development Efficiency
What You Can Expect from This Book
Who This Book Is For
Who This Book Isn’t For
Additional Resources
I. Jython
1. Jython Syntax, Statements, and Comments
The Interactive Console
Line Separators and Block Indentation Syntax
Semicolon
Backslash
Open Groupings
Code Blocks
Comments
Documentation Strings
Statements
Simple Statements
assert
assignment
break
continue
del
exec
global
import
pass
print
raise
return
Compound Statements
class
def
for
if
try
while
Comparing Jython and Java
2. Operators, Types, and Built-In Functions
Identifiers
Jython Data Objects
Numeric Objects
Sequence Objects
PyString—The String Object
PyTuple
PyList
Mapping Objects
PyDictionary
PyStringMap
PyNone
Operators
Arithmetic Operators
Shift Operators
Comparison Operators
Boolean Operators
Sequence Operators
Built-Ins
Introspection Functions
Numeric Functions
Type Conversion Functions
The Built-in File Function
Sequence Functions
Dynamic Language Functions
Attribute Tools
Functional Tools
Miscellaneous Functions
Comparison of Jython Data Types and Java Data Types
Java Types
3. Errors and Exceptions
Jython Exceptions
Exception Handling
The raise Statement
Tracebacks
The assert Statement and the __debug__ Variable
The Warnings Framework
Comparing Jython and Java
4. User-Defined Functions and Variable Scoping
Defining Functions
Indentation
Return Values
Documentation Strings
Function Attributes
Parameters
Positional Parameters
Default Values
*params and Handling an Unknown Number of Positional Parameters
Keyword Pairs as Parameters
**kw params and Handling Unknown Key-Value Pairs
Namespaces
Two Static Scopes
Statically Nested Scopes
Special Variables in User-Defined Functions
Recursion
Built-In Functional Programming Tools
lambda
map()
filter()
reduce()
zip()
List Comprehension
The Functional Programming Idiom
Synchronization
5. Modules and Packages
The import Statement
import X
import X as Y
from X import Y
from X import Y as Z
A Comparison of Jython and Java
Python’s package.module Hierarchy
The sys.path Variable
What Is a Module?
Special Module Variables
What Are Packages?
Java’s package.class Hierarchy
Reloading
6. Classes, Instances, and Inheritance
Encapsulation, Abstraction, and Information Hiding
Defining Jython Classes
Jython Class and Instance Attributes
Constructors
Finalizer or Destructor
Inheritance
Subclassing Jython Classes
Subclassing Java Interfaces
Subclassing a Java Class
Method Overloading
Sample Classes
Singletons
File grep Utility
HTTP Headers
Trees
7. Advanced Classes
Pre-Existing Class Attributes
__name__
__doc__
__module__
__dict__
__bases__
Pre-Existing Instance Attributes
__class__
__dict__
Special Methods for General Customization
__init__
__del__
__repr__
__str__
Dynamic Attribute Access
__getattr__
__setattr__
__delattr__
The Callable Hook—__call__
Special Comparison Methods
Three-Way, or Poor, Comparisons
Rich Comparisons
__hash__
Object “Truth”
Emulating Built-In Data Objects
Emulating Sequences
__len__
__getitem__
__setitem__
__delitem__
Sequence Concatenation and Multiplication
Slices
__contains__
UserList
Emulating Mappings
Emulating Numeric Types
II. Jython Internals and Integrating Jython With Java
8. Compiling Jython with jythonc
What Is jythonc?
Compiling a Module with jythonc
Paths and Compiled Jython
Set the python.home Property in the JVM
Explicitly Add Directories to sys.path Within Modules
Add to the python.path or python.prepath Property
Freeze an Application
Write a Custom __import__() Hook
jythonc Options
Java-Compatible Classes
An Example Java-Compatible Jython Class
Module-Global Objects and Java-Compatible Classes
9. Embedding and Extending Jython in Java
Embedding Jython
PythonInterpreter
Initialization
Properties and Initialization
Instantiating the Interpreter
Setting Output and Error Streams
PySystemState
Using the Interpreter
exec
execfile
eval
Compiling Code Object for Later Use
Handling Exceptions in the Interpreter
The set and get Methods
set
get
__tojava__
The getLocals and setLocals Methods
imp and the Top-Level Script
Embedding the InteractiveInterpreter
Embedding an InteractiveConsole
Extending Jython
ClassDictInit
__doc__ Strings
Exceptions
Parameters
Importing Jython Modules in Java
Working with PyObjects
Writing Jython Classes in Java
Adding a Java Class as a Built-In Jython Module
III. Applications with Jython
10. GUI Development
Comparing a Java and Jython GUI
Bean Properties and Events
Bean Properties
Bean Properties and Tuples
Bean Events
Name Priorities
The pawt Package
GridBag
colors
test
pawt.swing
Examples
Simple AWT Graphics
Adding Events
Images
Menus and Menu Events
Drag and Drop
Swing
11. Database Programming
DBM Files
Serialization
The marshal Module
The pickle and cPickle Modules
Shelves
PythonObjectInputStream
Database Management Systems
MySQL
PostgreSQL
JDBC
Connecting to the Database
JDBC URLs
JDBC Connection
Connection Scripts
Connection Dialog
DatabaseMetaData
Statements
The ResultSet
Prepared Statements
Transactions
zxJDBC
Connecting to the Database
Cursor
zxJDBC and MetaData
Prepared Statements
Errors and Warnings
dbexts
12. Server-Side Web Programming
Jython Servlet Containers
Defining Simple Servlet Classes
A Simple Java Servlet
A Simple Jython Servlet
Testing the Java and Jython Servlets
Installing Tomcat
Installing the Java Servlet
Installing the Jython Servlet
Compiling a Jython Servlet with jythonc
Adding jython.jar to the classpath
Making Jython’s lib Directory Available to Servlets
Testing the Jython Servlet
More About GenericServlet
init(ServletConfig) Method
service(ServletRequest, ServletResponse) Method
destroy() Method
HttpServlet
HttpServlet Methods
HttpServlet Example
HttpServletRequest and HttpServletResponse
PyServlet
Installing PyServlet
Testing PyServlet
Cookies
Sessions
Databases and Servlets
JSP
jythonc-Compiled Classes and JSP
Embedding a PythonInterpreter in JSP
A Jython Taglib
BSF
IV. Appendix
A. Jython Statements and Built-In Functions Quick Reference
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
12. Server-Side Web Programming
Next
Next Chapter
A. Jython Statements and Built-In Functions Quick Reference
Part IV. Appendix
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset