Saturday, July 3, 2010

OO Hello World - Jython



Let’s have a look at the hello world program in Jython which is the Java implementation of the Python programming language for the JVM runtime.

The code is identical to the previous post of IronPython. This is because at the end, both are written in the Python programming language. Nevertheless, I decided to create separate posts for those developers looking for their preferred platform and also because of the “Jython Info” section, which of course differs between the two implementations. In the future, if I post about IronPython or Jython I will be using their respective libraries and frameworks, so it makes sense to differentiate.


By the way, you can see my previous post here: http://carlosqt.blogspot.com/2010/06/oo-hello-world.html
where I give some details on WHY these "OO Hello World series" samples.

Version 1 (Minimal):
The minimum you need to type to get your program compiled and running.

class Greet(object):   
 name = ''  
 def __init__(self, name):  
  self.name = name.capitalize()  
 def salute(self):  
  print 'Hello', name, '!'  
  
# Greet the world!  
g = Greet('world')  
g.salute()

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
import java

class Greet(object): 
 name = ''
 def __init__(self, name):
  self.name = name.capitalize()
 def salute(self):
  print 'Hello', self.name, '!'

# Greet the world!
def main():
 g = Greet('world')
 g.salute()
 
main()

The Program Output:









Jython Info:
“Jython is an implementation of the Python programming language which is designed to run on the Java(tm) Platform. It consists of a compiler to compile Python source code down to Java bytecodes which can run directly on a JVM, a set of support libraries which are used by the compiled Java bytecodes, and extra support to make it trivial to use Java packages from within JPython. JPython has been renamed and superseded by Jython.” Taken from: (http://wiki.python.org/jython/JythonFaq/GeneralInfo)

Appeared:
1997-1999
Current Version:
Developed by:
Jim Hugunin > Barry Warsaw > Samuele Pedroni > Brian Zimmer > Frank Wierzbicki, Ted Leung
Creator:
Jim Hugunin
Influenced by:
Python (Guido van Rossum)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
JVM
Latest Framework Target:
JDK 6
Mono Target:
No
Allows Unmanaged Code:
Yes (using native Python/C libraries)
Source Code Extension:
“.py”
Keywords:
31
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
No
Latest IDE Support:
NetBeans 6.9
Eclipse
IntelliJ IDEA
Language Reference:
Extra Info:


1 comment:

  1. We are ERPTREE Leading oracle fusion HCM Online Training institute. We are providing online training services since 1999. still we are adding more oracle related courses as the technology changes. 2000+ online courses are available. we all ways achieve our goal in satisfying students in result we
    have global recognition to our site. we have best faculty for all of our online courses.


    Oracle fusion HCM Online Training

    Oracle Fusion HCM Training

    ReplyDelete