 | Page & Feed Options Bookmark This  |
 Table of Contents 
|
Getting Started To get started with Jython you need two things, Java and
Jython itself. First, you need to get a Java Runtime
Environment* (JRE). Any environment that is based on at least
JDK 1.1 will work; this includes all versions of the Java 2
Platform. Both Microsoft's non-standard version that previously
shipped with Visual J++* and IBM's Developer Kit for Windows*
will work fine. This also means that Jython programs will run
fine in Internet Explorer* and Netscape* browsers without using
the Java plug-in.
Jython Setup Once you have a JRE, you can install Jython. Get the
latest version, 2.1 as of the time of this writing, from
SourceForge. Jython comes as a single .class file that
is actually an installable program. Save the class file
(jython-21.class) to the directory locally. Once saved,
run the class to start the installer. If the current directory
is in your classpath, just run it as follows:
If the current directory is not in your classpath, you'll
need to include it:
java -classpath . jython-21 or java -cp . jython-21
|
The installation window displays. 
Figure 1. Jython Installation Window.
You'll be prompted for various options including installation
type (pick at least Standard) and directory (we'll assume
C:\jython-2.1 for the purpose of this article). On the
final installation screen click the Go button and you'll be all
set.
After the installation is complete, place the installation
directory in your path. With C:\jython-2.1 in your path,
you'll be able to just type jython to launch the
interactive console. You're now ready to get started with
Jython. Hello, Jython The typical first program in any language is called
"Hello, World." It just prints out a little message. Here,
we'll print out "Hello, Jython" instead. To start the console,
type jython. The first time you launch Jython, some processing
will happen of preinstalled libraries for your JRE. After the
first time, it won't be necessary again. Once Jython loads, you
get a >>> prompt.
The equivalent to a System.out.println call in Python is just
print. So, if you want to print a message to the console,
follow the command with a quoted string, as shown here. The
string is immediately displayed since the console is
interactive, interpreting each command as it is entered.
>>>print "Hello, Jython"
Hello, Jython
|
Exit the environment with Ctrl-Z.
If you're not interested in typing the command each time, you
can save it to a file:
# file hello.py
print "Hello, Jython"
|
Launch Jython with the filename, as shown here:
|