DZone
Web Dev Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Web Dev Zone > Getting started with Jython

Getting started with Jython

Simeon Franklin user avatar by
Simeon Franklin
·
Apr. 07, 12 · Web Dev Zone · Interview
Like (0)
Save
Tweet
8.12K Views

Join the DZone community and get the full member experience.

Join For Free

A student in my Python Fundamentals class asked me to demonstrate how to get started with Jython.

I've never used Jython and I'm not a Java programmer (processing doesn't count!) but I agreed to see if I could install it and demonstrate using a Java standard library class for him.

I didn't use my package manager to install but went the manual route, downloading the latest stable version from jython.org. This got me a file called jython_installer-2.5.2.jar. Did I mention I'm not a Java programmer? Still some vague memory prompted me to try:

$ java -jar jython_installer-2.5.2.jar

Aha! This popped up a graphical installer window! I selected my language, accepted the license, accepted the default installation components and chose an installation location of ~/bin/jython2.5.2. Then I was asked to pick a java home directory with the default being the current directory. I had no idea what this meant but noticed a second option of '/usr/lib/jvm/java-6-openjdk/jre' which existed and seemed a plausible choice.

The installer finished and I was off to see what new stuff I had in my install directory.

$ cd ~/bin/jython2.5.2
$ ./jython
Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) 
[OpenJDK Server VM (Sun Microsystems Inc.)] on java1.6.0_20
Type "help", "copyright", "credits" or "license" for more information.
>>>

Of course now I have no idea what I can do with the Java standard library. I googled for "Java standard libary" and found myself at the official docs for Java. Oh yeah - I guess Oracle owns Java now... Let's see: Java.math.BigInteger looks interesting. Can I import it?

>>> from java.math import BigInteger
>>> x = BigInteger("10000000000000000000000")
>>> y = BigInteger("10000000000000000000000") 
>>> x + y
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for +: 'java.math.BigInteger' and 'java.math.BigInteger'
>>> dir(BigInteger)
['ONE', 'TEN', 'ZERO', '__class__', '__copy__', '__deepcopy__',
... snip...
'abs', 'add', 'and', 'andNot', 'bit', ...]
>>> x.add(y)
20000000000000000000000

Yes, that is a big integer!

I also poked around in the demos a bit - Demo/awt/Colors.py is an 18 line Python program that looks pretty simple and running it:

$ jython Demos/awt/colors.py

reveals that it uses the AWT toolkit to put a bunch of labels with color names and the corresponding color in a gui window. Jython seems to do what it says on the label - lets me talk to Java classes but with the Python runtime - and it seems simple enough to get started on. Good luck!

 

Jython

Published at DZone with permission of Simeon Franklin, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Ultra-Fast Microservices in Java: When Microstream Meets Open Liberty
  • How Does the Database Understand and Execute Your Query?
  • How Data and Analysis Can Power Agile Teams
  • Handling Sensitive Data: A Primer

Comments

Web Dev Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo