Jython is an implementation of Python for the JVM.
It takes the Python programming languages syntax and enables it to run on the Java Platform.
Most of the Python modules will run without changes under Jython, but if they use extensions then they will probably not work.
3. History
It was initially created in late 1997 to replace C with Java for performace
intensive.
It moves to SourceForge in October, 2000.
The Python Software Foundation awarded a grant in January 2005.
Jython 2.5 was released in June 2009
4. Introduction
â—Ź Python is an easy to learn, powerful programming language.
â—Ź Jython is an implementation of Python for the JVM.
â—Ź It takes the Python programming languages syntax and enables it to run
on the Java Platform.
â—Ź Most of the Python modules will run without changes under Jython, but if
they use extensions then they will probably not work.
6. There are certain libraries written in Java languages to be included with Jython
(especially modules written in C).
â—Ź Introduction
â—Ź Built-in Functions
â—Ź Built-in Constants
â—Ź Built-in Objects
â—Ź Built-in Types
â—Ź Built-in Exceptions
â—Ź String Services
â—Ź Data Types
â—Ź Numeric and Mathematical
Modules
â—Ź File and Directory Access
â—Ź Data Persistence
â—Ź Data Compression and
Archiving
â—Ź File Formats
â—Ź Cryptographic Services
â—Ź Generic Operating System
Service
â—Ź Optional Operating System
â—Ź Interprocess Communication
and Networking
â—Ź Many More...
7. Installation
Download Jython 2.7 and execute below command to start installation GUI.
java -jar jython_installer-2.*.*.jar
We can add --console to start the installation in non GUI.
JYTHON_HOME=/home/vijay/jython2.7.0; export JYTHON_HOME
PATH=$PATH:$JYTHON_HOME/bin
10. Jython Basic Data Type
â—Ź It sees everything, including all data and code, as an object.
â—Ź Jython Types Summary
â—Ź Common Operators
â—Ź Boolean Types
â—Ź Numeric Types
â—Ź Additional Methods and Operations
12. Sequence Types
1. All sequences are zero-indexed. It is similar to C and Java Arrays.
2. All sequences support indexing (or subscripting) to select sub-elements.
3. It support an extension of indexing, called slicing, which selects a range of
elements.
4. It also support reverse slicing.
5. Slicing Reference
6. Sequence Operators
7. Sequence Function
13. Strings
1. A string is an immutable sequence of characters treated as a value.
2. String Methods
3. It doesn’t have a character type. Character are represented by strings of
length one.
4. Escape Character
5. Format Code
14. Tuples
1. Tuples are immutable lists of any type.
2. It can be of any length and can contain any type of object.
3. Tuple Example
15. Ranges
1. Jython uses immutable sequence of increasing integers, called ranges.
2. It can be easily created by
a. range({start}, end,{inc}) creates a small range. All element of the range exist.
b. xrange({start}, end, {inc}) creates a large range. Elements are created only as needed.
3. Default start is 0 and default inc is 1.
16. Lists
1. Lists Method
2. We can use List as Stack and Queue.
3. Stack is easy to implement using append() and pop().
4. To implement Queue we use collections.queue
5. It can also be created via advance notation, called list comprehensions.
17. Map and Dictionaries
We work only with subtypes of Map. Most commonly we used dictionary.
Dictionary Example
18.
19. Modules and Importing
â—Ź Jython breaks program down into separate files, called modules.
â—Ź Jython Modules Library
â—Ź A module is an executable Jython file that contains definitions.
â—Ź Jython packages are implemented as directories that can contain one or
more than one modules and a special file __init__.py, that executed before
first module of the package is executed.
â—Ź import module {as alias} OR from module import name {as alias}
â—Ź From module import *
â—Ź Import is executable