Jython for Java Programmers (Landmark)

Jython for Java Programmers (Landmark)
Authors
Robert Bill
ISBN
0735711119
Published
28 Dec 2001
Purchase online
amazon.com

Robert Bill's Jython for Java Programmers from New Riders is an essential introduction to the complexities of the merger between two popular object-oriented languages, Python and Java. It is directed toward Java programmers who want to incorporate Python rather than vice versa, but the utter symmetry of merging two object-oriented languages creates an Escheresque problem in perspective. It is like two snakes gobbling each other up.Let's sort this out historically.

Page 2 of 2
  1. Editorial Reviews
  2. Customer Reviews

Customer Reviews

calvinnme said
This book is designed for those who know Java or are learning Java. The Java-specific meaning of terms such as classpath, garbage collection, and interface appear without explanation, but no more than rudimentary Java knowledge is required. Specifically, Java developers desiring accelerated development, embedded interpreters, and increased flexibility will most appreciate this book. Although Jython is a complete programming language, it is unique in its ability to complement Java development rather than appear as an alternative to Java.

Chapter 1, "Jython Syntax, Statements, and Comments," introduces syntax and statements. Python's syntax is an essential part of what constitutes the coined word pythonic, an important descriptor of those details that make Python and Jython code clear, simple, and distinct. Python's use of indentation to delimit code blocks and newlines to delimit statements is new to most programmers, and Chapter 1 details the rules that apply to indentation, newlines, and statements. Additionally, Chapter 1 introduces the interactive interpreter, a Jython mode that immediately evaluates statements as you enter them. This chapter applies to Python in general with no references to material unique to Jython.

Chapter 2, "Operators, Types, and Built-In Functions," covers Jython's data object, operators, and built-in functions. Data objects, or types, are especially interesting because of Jython's ability to use both Python and Java objects. The Python language specification defines Python's, and therefore Jython's types, but types are where Jython-specific details emerge. One such detail is the conversion between Jython and Java types. Chapter 2 also defines Jython's built-in functions, which are those functions that are available without any import statements and that account for a sizable portion of Jython's functionality.

Jython's errors, exceptions, and warnings appear in Chapter 3, "Errors and Exceptions." Chapter 3 contains the definitions of Jython's built-in exceptions as well as a detailed look at the try/except and try/finally statements used to handle exceptions. Working with exceptions is of course important to Jython, but it is also an important step to working with Java classes and the exceptions they may raise.

Java does not have functions, but they are an important part of Jython. Chapter 4, "User-Defined Functions and Variable Scoping," shows how to define and use Jython functions and how to use Jython's functional programming tools. Functions are callable objects not defined within a class, but functional programming has a less succinct definition. Functional programming revolves around finding the results of an expression. Jython supplies all the tools required to learn and use functional programming, and these tools appear in Chapter 2.

Jython has modules, another unit that Java does not have, and Chapter 5, "Modules and Packages," describes Jython's modules. Jython also has packages, as does Java, but Jython packages differ from the Java counterpart as Chapter 5 explains. With Jython packages, modules, and classes as well as Java packages and classes, the details of the import statement quickly become important. Chapter 5 clarifies the import statement along with modules and packages.

Chapter 6, "Classes, Instances, and Inheritance," introduces the definition and use of Jython classes. This includes the subclassing of Java classes, the use of Java interfaces and Java abstract classes, and the implications of Java's access modifiers such as public, private, and protected. Jython classes do differ from Java classes, however, and Chapter 6 clarifies these differences.

Chapter 7, "Advanced Classes," extends the information on Jython classes to include Jython's special class attributes. Special attributes in Jython are those that follow a special naming convention and provide specific functionality. These special attributes let you customize a class's behavior and makes creating advanced classes relatively easy.

Chapter 8, "Compiling Jython with jythonc jythonc," details Jython's complicated jythonc tool. jythonc compiles Jython code to Java byte-code. jythonc lets you use classes written in Jython within Java frameworks, and even lets you create class files that you can import and use from within Java.

Chapter 9, "Embedding and Extending Jython in Java," describes how to embed a Jython interpreter. Compiling Jython to Java byte-code is extremely useful, but embedding a Jython interpreter within Java applications has many advantages. Embedding gives you total control over Jython's system state and allows you to use all of Jython's features and modules within a Java application. The amazing part is how simple it is to embed a Jython interpreter. A basic embedded interpreter requires only two lines of Java code, and adding additional configuration to an embedded interpreter is equally easy. An embedded interpreter allows you to write Jython modules to extend or implement features of Java applications without having to compile modules with jythonc. It is my impression that embedding Jython is the foremost advantage of Jython. It allows multi-level language development, leverages all that is good in Java and Python within a single application, and allows rapid development and extensibility. There is already a number of projects that embed Jython, and the trend to do so will likely continue.

Chapter 10, "GUI Development," describes how to develop graphical applications with Jython. The focus is on Java's Abstract Windowing Toolkit (AWT) and Swing application programmer's interface. Jython allows rapid development of graphical applications because of its addition of automatic bean properties and events. Chapter 10 covers the details of automatic bean properties and events, but the basic idea is that Jython automatically searches a component for these features and adds shortcuts to establishing properties and event handlers. The shortcuts leverage Jython syntax features to simplify and accelerate development. Chapter 10 also includes information on creating Java applets with Jython.

Java has become very prominent in database programming, and Jython is able to leverage all of Java's success in this area while adding its own advantages. Chapter 11, "Database Programming," introduces the use of Jython in database programming. Chapter 11 includes information on hashed database files as well as the MySQL and PostgreSQL relation database management systems (object-relation for PostgreSQL). Jython also has the advantage of being able to use Java's JDBC database connectivity or the Python database application programmer's interface implemented with zxJDBC. Chapter 11 discusses both of these APIs.

Chapter 12, "Server-Side Web Programming," describes web programming with Jython. For Jython, this means servlets, Java Server Pages (JSP), and taglibs. In other words, server-side web development with Jython coincides with the popular (standard) Java web development paradigm. Chapter 12 addresses using jythonc -compiled classes as servlets as well as an embedded Jython Servlet mapping and IBM's bean scripting framework (BSF).

Java programmers wishing to add a high-level language as a tool in their existing arsenal is the primary audience for this book, but is equally applicable to those seeking an alternative to Java, yet bound to an organization dedicated to Java-based technology. A secondary audience is those beginning Python programmers wishing to extent their Python facility within Java frameworks. Because this book assumes some knowledge of Java basics, this secondary audience may require an additional source for Java fundamentals. If you have no interest in Java, or you are already an advanced Python programmer, then this book is probably not for you.

Anonymous said
It's a great book, I use Jython for the power of making unit testing, you save very much time on creating new objects. Moreover, when you override the methods equals and hashCode (which is a good practice) Jython makes easy to test for equality, the book is a great help to get into more details about the tool.

Anonymous said
Robert W. Bill did an excellent job in introducing Jython which is the combination of two programming languages. The merging of Java and Python. Although intended for programmers with sufficient background in Java programming, this book can be a great tool for learning another high-level language. This book includes topics on: seamless access to Java classes, efficiency,dynamic types, introspection and dynamic execution, first-class functions and functional programming, Java security, and code clarity.

Jython for Java Programmers is like a book for beginners trying to lear a new programming language. Each chapter has sufficient samples of codes with a corresponding syntax for a particular example. At the end of each chapter, the author was able to clearly compare Jython to Java. Such comparisons include: statements, typecodes, types, and classes, errors and exceptions, synchronization, packages, GUI development, as well as instances and inheritance. The last two chapters provided topics on database programming and server-side web programming. The Jython programmer is given sample codes on how to make use MySQL, PostgreSQL, and JDBC in their Jython program. The book focused on Servlets and JSP in its last chapter. Although it is equally effective with all the Java technologies on developing web applications.

Jython can be an added high-level language for Java programmers. But the book assumes its audience has previous Java knowledge. So that discussions on class, instance, encapsulation, polymorphism, and inheritance were briefly mentioned. Thus, cannot be sufficient as an introduction to programming. Jython-related Internet resources were listed in the Introduction section. An educational advantage of this book is that it supports functional programming as well as object-oriented programming.

akempo said
An excellent book overall, this book accomplishes what it sets out to do: teach Jython to Java Programmers. Like many who were unfamiliar it, I was under the impression that Jython was simply a Java version of Python, which it is not. Jython is a language in its own right, and this book serves not only as an introduction to Jython, but to Python as well, and a very good one at that.
Although I did not do every example in the book, as that would have taken some time, I did most of the examples from the first 6 chapters, and with one exception they all worked. I have enough confidence in the author that I believe most, if not all the following examples will work as written also. Another thing I appreciate was the author's notes regarding versions scheduled to come out, so that if my Jython version behaved differently, I knew why.
From an organizational standpoint, the book follows the standard teaching conventions of showing syntax and data types and moving up from there until classes have been discussed. The middle part of the book is spent talking about how to combine Java and Jython, a much simpler process than any other two languages I've seen, and then he discusses practical applications of Jython and Java. Although the examples are too simplistic for a real world scenario, they convey enough information to provide a model from which to develop.
My only real complaint with the book was the number of grammatical errors, which distracted me from time to time as I puzzled out what the author was trying to say. A good book, and one which the publisher should re-edit to make it even better.

said
I wish all other books could focus on one audience like this one has. Its goal of targeting Java programmers and getting us excited about Jython as a great tool for scripting, glue, testing, prototyping, and lots of other uses was achieved.
It doesn't waste time on details of programming or Java, which you're already supposed to know.

I've been using J(P)ython since the "early" days, mostly as a prototyping and quick testing tool. I'm happy to see some good books about this great language on the market (finally).

Mr. Bill's writing style is easy to follow, and the wealth of code examples almost forces you to read this book in front of a computer, learning more by trying each one as you read about it. I haven't run into any major typos in the code so far. There's so much good stuff in here that I haven't even made it all the way through, but I'll be back to pick up more tips as I need them.

The only reason I don't give this book 5 stars is that it's out of sync with the latest advances in Jython--but since the language is growing at least as quickly as both of its parents, that's to be expected.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan