Professional Documents
Culture Documents
Jython
Agenda
What is Jython
Syntax Basics
Example Code
Embedding Jython
Other Scripting Languages for Java
Red Robin Jython Eclipse Plug-in
Q + A
What is Jython?
An implementation of the Python
(2.1) language on the Java Virtual
Machine
Cross-platform (via JVM)
Access to both Python and Java
libraries
Interactive Interpreter
Jython Syntax Overview
Loose, Dynamic Typing
Modular organization
Object Oriented – Everything is an
Object
Supports classes, methods
Functional Programming (List Comp.)
Code blocks defined by indentation
Dynamic dispatch – Reflection made
easy!
Operator Overloading
Jython Syntax Basics
Built-in Data Types:
Numbers (Integers, Float,
Complex)
Strings (immutable sequences)
Sequences (like ArrayList)
Dictionaries (like HashMap)
Many Advanced Types, such as File
Jython Syntax: Sequences
Jython sequence:
list = [1,2,3,4,5]
list[1:3] -> 2
list[2:5] -> [2,3,4] #called “Slicing”
list[1:3] = ‘two’ -> [1,’two’,3,4,5]
if expression:
block
elif expression:
block
else:
block
try:
block
except SomeError:
block
finally:
block
Jython Syntax: Loops
import java.security as sec
import java.lang as lang
providers = sec.Security.getProviders() #sequence
for p in providers:
print p.name
print “-----------------------”
p.list(lang.System.out)
Jython Syntax: F.P.
>>> map(lambda x: 2 * x, [1,2,3])
[2,4,6]
class HelloWorld(Applet):
def paint(self, g):
g.drawString(“Hello World!”, 20, 30)
Example Time
Jython Interpreter
Eclipse – Red Robin Jython IDE
http://home.tiscali.be/redrobin/jython/
Cool Things
Read a whole file in two lines:
file = open(“somefilename.txt”, r+)
file.read()