Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Intro to Jython, Part 1: Java programming made easier

Barry Feigenbaum, Sr. Consulting IT Architect, IBM

Dr. Barry Feigenbaum is a member of the IBM Worldwide Accessibility Center, where he is part of team that helps IBM make its own products accessible to people with disabilities. Dr. Feigenbaum has published several books and articles, holds several patents, and has spoken at industry conferences such as JavaOne. He serves as an Adjunct Assistant Professor of Computer Science at the University of Texas, Austin.

Dr. Feigenbaum has more than 10 years of experience using object-oriented languages like C++, Smalltalk, the Java programming language, and Jython. He uses the Java language and Jython frequently in his work. Dr. Feigenbaum is a Sun Certified Java Programmer, Developer, and Architect.


Acknowledgements

I would like to acknowledge Mike Squillace and Roy Feigel for their excellent technical reviews of this tutorial.

Summary:  This is the first in a two-part tutorial that will introduce you to the Jython scripting language and provide you with enough knowledge to begin developing your own Jython-based applications. In this first half of the tutorial, you'll learn the concepts and programming basics of working with Jython, including access options and file compilation, syntax and data types, program structure, procedural statements, and functions.

Date:  08 Apr 2004
Level:  Introductory PDF:  A4 and Letter (1165 KB | 65 pages)Get Adobe® Reader®

Activity:  85509 views
Comments:  

About this tutorial

What is this tutorial about?

Develop skills on this topic

This content is part of a progressive knowledge path for advancing your skills. See Explore alternative languages for the Java platform

This two-part tutorial will introduce you to the Jython scripting language, and provide you with enough knowledge to begin developing your own Jython-based applications. Jython is an implementation of Python that has been seamlessly integrated with the Java platform. Python is a powerful object-oriented scripting language used primarily in UNIX environments.

Jython is extremely useful because it provides the productivity features of a mature scripting language while running on a JVM. Unlike a Python program, a Jython program can run in any environment that supports a JVM. Today, this means most major computing systems, including Microsoft Windows, Mac OS, most UNIX variants including all Linux systems, and all IBM systems.

This tutorial covers Jython in progressive detail. In this first half of the tutorial, we'll cover the concepts and programming basics of working with Jython, including access options and file compilation, syntax and data types, program structure, procedural statements, and functions. The second half of the tutorial will start with a conceptual introduction to object-oriented programming in Jython. From there, we'll move on to a more hands-on discussion, encompassing class statements, attributes, and methods, abstract classes, and operator overloading. This advanced discussion will also include debugging, string processing, file I/O, and Java support in Jython. The tutorial will conclude with a step-by-step demonstration of how to build a working GUI app in Jython.

The example code will be very simple in the beginning of the tutorial, but by the end of the second half you will be up and running with complete functions, classes, and programs. Included with the tutorial is a set of appendices detailing the inner workings of Jython.


Should I take this tutorial?

This tutorial is oriented towards software developers at all levels, from casual dabblers to professionals. It is especially oriented towards Java developers who want to leverage the productivity advantages of a scripting language. It is also targeted towards Visual Basic and C++/C# programmers who want an easier entry into the Java development world.

Together, we will cover the following aspects of scripting with Jython:

Part 1

  • Download and installation
  • A conceptual introduction to Jython
  • Working from the command-line vs source files
  • Syntax and data types
  • Program structure
  • Procedural statements
  • Functions

Part 2

  • Object-oriented programming with Jython
  • Debugging
  • Java support
  • String processing
  • File IO
  • Building a GUI application in Jython

To benefit from the discussion, you should be familiar with at least one procedural programming language and the basic concepts of computer programming, including command-line processing. To fully utilize Jython's features you should also be familiar with the basic concepts of object-oriented programming. It will also be helpful to have a working knowledge of the Java platform, as Jython runs on a JVM; although this is not a requirement of the tutorial.

Note that this tutorial is oriented towards Windows systems. All command examples will employ Windows syntax. In most cases similar commands perform the same functions on UNIX systems, although these commands will not be demonstrated.


Tools, code, and installation requirements

You must have Jython 2.1 or higher installed on your development system to complete this tutorial. Your development system may be any ASCII text editor (such as Windows Notepad) combined with the command prompt. The tutorial includes detailed instructions for getting and installing Jython on your system.

To use Jython you must also have a Java Runtime Environment (JRE) installed on your system. It is recommended that you use the latest JRE available (1.4.2 at the time of writing), but any version at or beyond Java 1.2 should work fine. If you are going to use Jython from a browser (that is, as an applet), you must have at least a JRE 1.1 available to the browser. See Resources to download the latest version of the Java development kit (JDK).

All code examples in this tutorial have been tested on Jython running on the Sun Java 1.4.1 JRE on Windows 2000. Examples should work without change on any similar configuration on other operating systems.

1 of 16 | Next

Comments



static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java technology
ArticleID=131933
TutorialTitle=Intro to Jython, Part 1: Java programming made easier
publish-date=04082004
author1-email=feigenba@us.ibm.com
author1-email-cc=jaloi@us.ibm.com