CSC/ECE 517 Fall 2013/ch1 1w03 ss: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
 
(84 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Introduction to JRuby and other such languages ==
__TOC__
== Background ==
== Background ==


Over the last 10-15 years , the [[Java virtual machine]](JVM) has been a popular platform to host languages other than Java. This can be attributed to the performance and “write-once-run-anywhere” portability of the JVM , as well as the other advanced features, providing runtime environments to the other languages.
<ref>http://www.drdobbs.com/jvm/a-long-look-at-jvm-languages/240007765</ref>Over the last 10-15 years , the [http://en.wikipedia.org/wiki/Java_virtual_machine Java Virtual Machine](JVM) has been a popular platform to host languages other than Java. This can be attributed to the performance and “write-once-run-anywhere” portability of the JVM , as well as other advanced features, providing runtime environments to the other languages.


Why have so many languages , including Ruby, Groovy,and Python, been ported to Java ?
Why have so many languages, including Ruby, Groovy,and Python, been ported to Java ?


The main reason is because its easier to target one platform and rely on the multi platform JVM to host it than it is to write interpreters for each of the operating system.
The main reason is because its easier to target one platform and rely on the multi platform JVM to host it than it is to write interpreters for each of the operating system.


Additionally , with the JVM’s advanced [[Just-in-time]] (JIT) compilation ,the resulting compiled and optimized Java bytecode will typically run with equal or better performance than naive interpreters. Further , the Java JIT compiler continues to optimize code well after it’s first complied ,depending upon changes in code execution and branching. The cost and effort associated with building this into each independent interpreter makes this kind of performance prohibitive; so , it makes sense to leverage the JVM’s existing multi platform implementation of this performance optimization feature .
Additionally , with JVM’s advanced [http://en.wikipedia.org/wiki/Just_in_Time Just In Time] (JIT) compilation ,the resulting compiled and optimized Java bytecode will typically run with equal or better performance than naive interpreters. Further , the Java JIT compiler continues to optimize code well after it’s first complied ,depending upon changes in code execution and branching. The cost and effort associated with building this into each independent interpreter makes this kind of performance prohibitive; so , it makes sense to leverage the JVM’s existing multi platform implementation of this performance optimization feature .


A list of other features that JVM brings along are a huge set of well tested libraries , garbage collection , excellent built-in tools and debugging interfaces that a language developer can easily plug into.
A list of other features that JVM brings along are a huge set of well tested libraries , garbage collection , excellent built-in tools and debugging interfaces that a language developer can easily plug into.
The biggest advantage that JVM brings to the table is interoperability that it provides.
The biggest advantage that JVM brings to the table is interoperability that it provides.


Prior to Java Se 7 2011 , there was a small penalty hit when crossing the barrier to and from Java code . This was because JVM was not initially built to support dynamically typed languages. To fix this Java Specification Request 292 was developed with the goal of creating a new bytecode instruction to resolve this issue. The result is the invoked dynamic bytecode, which is an enhancement to the JVM that allows dynamic and direct linkage between the calling code and receiving code at run time.
Prior to Java Se 7 2011 , there was a small penalty hit when crossing the barrier to and from Java code . This was because JVM was not initially built to support dynamically typed languages. To fix this Java Specification Request 292 was developed with the goal of creating a new bytecode instruction to resolve this issue. The result is invoked dynamic bytecode, which is an enhancement to the JVM that allows dynamic and direct linkage between the calling code and receiving code at run time.
 
==Languages Built on JVM==
*JRuby
 
*Jython
*Clojure
 
*TCL/Java
 
*Groovy


==Different Fusion Languages==
==JRuby==
==JRuby==


JRuby is an implementation of the Ruby programming language atop the Java Virtual Machine, written largely in Java. JRuby is tightly integrated with Java to allow the embedding of the interpreter into any Java application with full two-way access between the Java and the Ruby code.
JRuby<ref>http://www.jruby.org</ref> is an implementation of the Ruby programming language built on Java Virtual Machine, written in Java. JRuby is tightly integrated with Java so as to provide full two-way access between the Java and the Ruby code.
====History of JRuby====  
====History of JRuby====  
=====Developers=====  
=====Developers=====  
Line 25: Line 38:
It was originally created by Jan Arne Petersen, in 2001.
It was originally created by Jan Arne Petersen, in 2001.


JRuby 1.1 added Just-in-time compilation and Ahead-of-time compilation modes to JRuby and was already faster in most cases than the then-current Ruby 1.8.7 reference implementation.
JRuby 1.1 added Just-in-time (JIT) compilation and Ahead-of-time (AOT) compilation modes to JRuby and was already faster in most cases than the then-current Ruby 1.8.7 reference implementation.


JRuby packages are available for most platforms; Fedora 9 was among the first to include it as a standard package at JRuby 1.1.1
JRuby packages are available for most platforms; Fedora 9 was among the first to include it as a standard package at JRuby 1.1.1
Recently , JRuby has been gaining more and more attention in the Java and Ruby communities.
Recently , JRuby has been gaining increased presence in the Java and Ruby communities.


:'''Commercial Support for JRuby''' : Engine Yard Inc.
:'''Commercial Support for JRuby''' : Engine Yard Inc.


Compilation of JRuby code is mixed mode ie code can be interpreted ,JIT (Just in time ) compiled or AOT compiled.
Compilation of JRuby code is mixed mode which means that the code can be interpreted ,JIT (Just in time ) compiled or AOT (Ahead of time) compiled.
 
JRuby was the driving force behind adding the invoke dynamic bytecode to the Java SE 7 release. This facilitates Java-to-Ruby and reverse calls to be treated the same as Java-to-Java calls. Additionally, JRuby inspired Sun's Multi-VM JVM research effort, where one JVM can act as a separate sandbox to each of multiple applications, allowing different versions of the JRuby runtime to be loaded and active at the same time.
 
====Framework Support====
JRuby has built-in support for Rails, RSpec, Rake, and RubyGems. It allows the use of bundled C libraries known as gems. It also provides the feature of launching the Interactive Ruby Shell (irb). The [https://netbeans.org/ Netbeans] Ruby Pack, available since NetBeans 6.0, allows IDE development with Ruby and JRuby, as well as Ruby on Rails for the two implementations of Ruby.
 
<b>Code Snippet:</b> <br>
JRuby Calling Java
 
  require 'java'
  frame = javax.swing.JFrame.new
  frame.getContentPane.add javax.swing.JLabel.new('Hello, World!')
  frame.setDefaultCloseOperation javax.swing.JFrame::EXIT_ON_CLOSE
  frame.pack
  frame.set_visible true}}


JRuby was a big reason the invoke dynamic bytecode was added to Java with the Java SE 7 release. This allows all Java-to-Ruby and reverse calls to be treated the same as Java-to-Java calls. Additionally, JRuby inspired Sun's Multi-VM JVM research effort, where one JVM can act as a separate sandbox to each of multiple applications, allowing different versions of the JRuby runtime to be loaded and active at the same time.
====Frameworks Support====
JRuby has built-in support for Rails, RSpec, Rake, and RubyGems. It embeds an FFI subsystem to allow to use C libraries bundled as gems. It also allows launching the Interactive Ruby Shell (irb) as Ruby MRI does. The Netbeans Ruby Pack, available since NetBeans 6.0, allows IDE development with Ruby and JRuby, as well as Ruby on Rails for the two implementations of Ruby.
====Advantages of JRuby over Java====
====Advantages of JRuby over Java====
• Ruby has features missing from Java  
• Ruby has features missing from Java  
* Closure (blocks)
 
* Blocks also known as Closures


* Open classes  
* Open classes  
Line 45: Line 72:
* Meta programming  
* Meta programming  


* Duck-typing  
* [http://en.wikipedia.org/wiki/Duck_typing Duck-typing]


• Domain Specific Language (DSL)  
• Domain Specific Language (DSL)  


* Through (J)Ruby's capability of allowing expressive method names and cushy semantics
====Advantages of JRuby over Ruby====
====Advantages of JRuby over Ruby====
With JRuby you get the best of both worlds: Ruby applications and libraries, plus Java libraries. And you can access those libraries with Ruby syntax (or Java syntax, if you want).  
JRuby provides you with the best of both the Java and Ruby world : Ruby applications and libraries, plus Java libraries. And you can access those libraries with Ruby syntax (or Java syntax, if you want).  
 
*On average JRuby, runs 2 and a half times faster than Ruby, except at startup


*In addition to native threads, JRuby supports Unicode natively
*On average JRuby, runs 2 and a half times faster than Ruby, except at startup.
 
*Code can be fully compiled ahead of time or just in time


*In addition to native threads, JRuby supports Unicode natively.


==Jython==
==Jython==


Jython is the successor to JPython. The Jython project was created in accordance with the CNRI JPython 1.1.x license, in order to ensure the continued existence and development of this important piece of Python software. The intent is to manage this project with the same open policies that are serving CPython so well.
<ref>http://www.jython.org</ref>[http://www.jython.org/ Jython] is the successor to JPython. The Jython project is in accordance with the JPython 1.1.x license. The intent is to manage this project with the same open policies that are serving CPython so well.


====What is Jython?====
====What is Jython?====


JPython 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.
JPython is an implementation of the Python programming language designed to run on the JVM. It consists of a compiler to compile Python source code 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 for the usage of Java packages from within JPython. JPython has been renamed as Jython.


:'''Project inception''': Created by Jim Hugunin in 1997
:'''Project inception''': Created by Jim Hugunin in 1997


:'''Licensing''': Permissive free, GPL-like, Python Software Foundation license
:'''Licensing''': Python Software Foundation license


:'''Commercial support''': Community based
Jython is a fully dynamic language system.


:'''Language type system''': Fully dynamic
Compilation of Jython is mixed mode which means that the code can be interpreted , JIT compiled or AOT compiled.


Compilation of Jython is mixed mode ie code can be interpreted , JIT compiled or AOT compiled.
Jython, is one of the very first languages to be ported on to the JVM, which is a Java implementation of the Python interpreter to facilitate high-performance Python application execution. Written on the JVM, Jython supports calls into Java code and libraries, and all code is JIT compiled at runtime.
 
The startup time and performance of Jython code is largely determined by the JVM. Jython is almost as fast as CPython.
Jython, one of the very first languages ported to the JVM, is a Java implementation of the Python interpreter to enable high-performance, compiled, Python application execution. Written on the JVM, Jython fully supports calls into Java code and libraries, and all code is JIT compiled at runtime.
The startup time and runtime performance for Jython are largely determined by the JVM. Startup time can be mitigated by using a tool like Nailgun. Jython is approximately as fast as CPython--sometimes faster, sometimes slower .


====Purpose====  
====Purpose====  
There are numerous alternative languages implemented for the Java VM. The following features help to separate Jython from the rest:
<ref>https://wiki.python.org/jython/JythonFaq/GeneralInfo</ref>There are numerous alternative languages implemented for the Java VM. The following features help to separate Jython from the rest:


Dynamic compilation to Java bytecodes - leads to highest possible performance without sacrificing interactivity.
*Dynamic compilation to Java bytecodes - provides highest possible performance.  


Ability to extend existing Java classes in Jython - allows effective use of abstract classes.
*One can extend existing Java classes in Jython - providing effective use of abstract classes.


Optional static compilation - allows creation of applets, servlets and beans.
*Jython allows creation of applets, servlets and beans.


Bean Properties - make use of Java packages much easier.
*Python Language - combines remarkable power with clear syntax.  


Python Language - combines remarkable power with very clear syntax.  
*It also supports a full object-oriented programming model .


It also supports a full object-oriented programming model which makes it a natural fit for Java's OO design.
<b>Code Snippet:</b><br/>
A class declaration in Jython :
 
class Hello:
    def __init__(self, name="John Doe"):
        self.name = name
    def greeting(self):
        print "Hello, %s" % self.name


Creation of objects :
    jane = Hello("Jane Doe")
    joe = Hello("Joe")
    default = Hello()


==Clojure==
==Clojure==


Clojure is a dialect of the Lisp programming language created by Rich Hickey. It is a functional general-purpose language. Its focus on programming with immutable values and explicit progression-of-time constructs are intended to facilitate the development of more robust programs, particularly multithreaded ones. Clojure runs on the Java Virtual Machine, Common Language Runtime, and JavaScript engines. Like other Lisps, Clojure treats code as data and has a sophisticated macro system.
<ref>http://en.wikipedia.org/wiki/Clojure</ref>[http://clojure.org/ Clojure] is a dialect of the Lisp programming language. It was created by Rich Hickey. It is a functional general-purpose language. Its focus on programming with immutable values and explicit progression-of-time constructs .With the help of these constructs it provides support for multi-threaded programs. Clojure runs on Java Virtual Machine, Common Language Runtime, and JavaScript engines.  


'''Licensing''': Eclipse Public License.
'''Licensing''': Eclipse Public License.
Line 109: Line 142:
'''Compilation''': Bytecode, and JIT compiled
'''Compilation''': Bytecode, and JIT compiled


Clojure is a modern-day Lisp for functional programming, interoperable with object-oriented code, and built for concurrency. It's built on and tightly integrated with the JVM, treats all code as data, views functions as objects, and emphasizes recursion over looping. The main feature of Clojure is its immutable state system that provides for much easier, less error-prone, parallel code execution.
Clojure is a modern-day functional programming language, inter-operable with object-oriented code, and built for concurrency. It's built on and tightly integrated with the JVM, treats all code as data, views functions as objects, and emphasizes on recursion . The main feature of Clojure is its immutable state system that provides much easier, less error-prone, parallel code execution.


====Advantages====
====Advantages====


*All the benefits of functional programming, without the purity straitjacket.
<ref>http://stackoverflow.com/questions/3046769/advantages-of-clojure</ref>*It provides all the benefits of functional programming languages.


*It allows dynamic, compact code with late binding, macros, multimethods
*It allows dynamic, compact code with late binding, macros, multimethods.


*Java interoperability
*Java [http://en.wikipedia.org/wiki/Interoperability interoperability]


*Can code functions to sequence abstraction instead of to specific data structures
*Can code functions to sequence abstraction instead of to specific data structures


*In-built concurrency : functional data structures, software transactional memory
*In-built concurrency.
 
<b>Code Snippets: </b><br/>
 
Hello World in Clojure
  (println "Hello world!")


Defining a square function
  defn square [x]
  (* x x))


==TCL/Java==
==TCL/Java==
Tcl/Java is a project to bridge Tcl and Java. It consists of two distinct packages, Tcl Blend and Jacl.
<ref>http://en.wikipedia.org/wiki/Tcl/Java</ref>[http://tcljava.sourceforge.net/docs/website/index.html Tcl/Java] , a project to bridge Tcl and Java, consists of two distinct packages:
 
* Tcl Blend
 
*Jacl


====TCL Blend====
====TCL Blend====
Tcl Blend is a Tcl extension that makes use of JNI to facilitate communication between a Java interpreter and a Tcl interpreter. Tcl Blend is typically used to load a Java interpreter into an existing Tcl process, so that functionality implemented in Java can be accessed in a Tcl script. For example, one could allocate a Java object in a Tcl script and interactively invoke Java methods on the object.
Tcl Blend is a Tcl extension that makes use of [http://en.wikipedia.org/wiki/Java_Native_Interface JNI] to facilitate communication between a Java interpreter and a Tcl interpreter. Tcl Blend loads a Java interpreter into an existing Tcl process. Here, the behavior that has been implemented in Java is accessed in a Tcl script. For example, A Java object allocated in a Tcl script can interactively invoke Java methods on this object.


One can also load Tcl Blend and Tcl into a Java process, which adds scripting functionality to an existing Java application. Because Tcl Blend is a normal Tcl extension, one can use it with other popular Tcl extensions like Tk, Expect, and Itcl.
Loading Tcl Blend and Tcl into a Java process enables one to add scripting functionality to an existing Java application. TCL Blend can be used with other popular Tcl extensions like Tk.


====JACL====
====JACL====
Jacl is a self-contained implementation of a Tcl interpreter, written entirely in Java. Jacl also includes features that facilitate communication between a Java interpreter and a Tcl interpreter. Jacl is typically used to incorporate Tcl scripting functionality into an existing Java application, without dealing with the complexities of native code that come with loading Tcl Blend into a Java process.
JACL is an implementation of a Tcl interpreter. It is written entirely in Java. Jacl facilitates communication between a Java interpreter and a Tcl interpreter. Jacl helps in incorporating Tcl scripting into an existing Java application, without dealing with the complexities that come with loading Tcl Blend into a Java process.
 
JTcl, a fork of Jacl, aims to continue the modernization of Jacl that began with the Jacl Modernization Project in the Google Summer of Code.
 
==Groovy==


JTcl, a fork of Jacl, was released on November 17, 2010. One of the main goals of JTcl is to continue the modernization of Jacl that began with the Jacl Modernization Project in the Google Summer of Code.
<ref>http://en.wikipedia.org/wiki/Groovy_(programming_language)</ref>[http://groovy.codehaus.org/ Groovy], an object-oriented programming language for the Java platform, is a dynamic language with features similar to those of Python, Ruby and Perl. Most Java code is also syntactically valid Groovy.


*Groovy can be used as a scripting language for the Java Platform.


==Groovy==
*Groovy is dynamically compiled to Java Virtual Machine (JVM) bytecode


Groovy is an object-oriented programming language for the Java platform. It is a dynamic language with features similar to those of Python, Ruby, Perl, and Smalltalk. It can be used as a scripting language for the Java Platform, is dynamically compiled to Java Virtual Machine (JVM) bytecode, and interoperates with other Java code and libraries. Groovy uses a Java-like curly-bracket syntax. Most Java code is also syntactically valid Groovy.
*Groovy interoperates with other Java code and libraries.


====History====  
====History====  


James Strachan first talked about the development of Groovy in his blog in August 2003 Several versions were released between 2004 and 2006. After the JCP standardization process began, the version numbering was changed and a version called "1.0" was released on January 2, 2007. After various betas and release candidates numbered 1.1, on December 7, 2007, Groovy 1.1 Final was released and immediately rebranded as Groovy 1.5 as a reflection of the many changes that were made.
[http://en.wikipedia.org/wiki/James_Strachan_(programmer) James Strachan] first talked about the development of Groovy in his blog in August 2003. Several versions were released between 2004 and 2006. After various betas, Groovy 1.1 Final was released and immediately rebranded as Groovy 1.5 as a reflection of the many changes that were made.


====Features====  
====Features====  
 
<ref>http://stackoverflow.com/questions/764416/why-would-one-use-groovy-over-java</ref>
Most valid Java files are also valid Groovy files. Although the two languages are similar, Groovy code can be more compact, because it does not require all the elements that Java requires. This makes it possible for Java programmers to gradually learn Groovy by starting with familiar Java syntax before acquiring more Groovy idioms.
Most valid Java files are also valid Groovy files. This facilitates Java programmers to easily switch to Groovy. Groovy code is more compact when compared to Java. This is because it does not require all the elements that Java requires.


Groovy features not available in Java include:
Groovy features not available in Java include:


*both static and dynamic typing (with the def keyword)
*both static and dynamic typing  


*closures
*closures
Line 158: Line 208:
*operator overloading
*operator overloading


*native syntax for lists and associative arrays (maps)
*native syntax for lists and associative arrays  


*native support for regular expressions
*support for regular expressions
 
*polymorphic iteration


*expressions embedded inside strings(String interpolation)  
*expressions embedded inside strings(String interpolation)  


*additional helper methods
*additional helper methods
*safe navigation operator "?." to automatically check for nulls


*Mixins/Categories
*Mixins/Categories
Line 174: Line 220:
*Collection literals
*Collection literals


*GPath expressions
*metaprogramming.
 
<b>Code Snippet:</b><br/>
Example for Metaprogramming in Groovy:


*metaprogramming.
  Number.metaClass {
  sqrt = { Math.sqrt(delegate) }
  }
  assert 9.sqrt() == 3
  assert 4.sqrt() == 2


====IDE Support====
====IDE Support====


Many integrated development environments and text editors support Groovy:
Many integrated development environments and text editors support Groovy:
Eclipse, through Groovy-Eclipse , Emacs, using Groovy-Mode , IntelliJ IDEA, Community Edition, Grails/Griffon in the Ultimate Edition only , NetBeans, since version 6.5 , etc
[http://www.eclipse.org/ Eclipse], through Groovy-Eclipse, Emacs, using Groovy-Model, Grails/Griffon in the Ultimate Edition only, NetBeans, since version 6.5 , etc
 
==Tutorial Links==
 
* JRuby - http://www.codeschool.com/code_tv/intro-to-jruby
* Jython - https://wiki.python.org/jython/LearningJython
* Clojure - http://learn-clojure.com/clojure_tutorials.html
* Tcl/Java - http://ptolemy.eecs.berkeley.edu/~johnr/tutorials/tcljava98/notes/index.html
* Groovy - http://www.vogella.com/articles/Groovy/article.html
 
==References==
<references/>

Latest revision as of 20:24, 24 September 2013

Introduction to JRuby and other such languages

Background

<ref>http://www.drdobbs.com/jvm/a-long-look-at-jvm-languages/240007765</ref>Over the last 10-15 years , the Java Virtual Machine(JVM) has been a popular platform to host languages other than Java. This can be attributed to the performance and “write-once-run-anywhere” portability of the JVM , as well as other advanced features, providing runtime environments to the other languages.

Why have so many languages, including Ruby, Groovy,and Python, been ported to Java ?

The main reason is because its easier to target one platform and rely on the multi platform JVM to host it than it is to write interpreters for each of the operating system.

Additionally , with JVM’s advanced Just In Time (JIT) compilation ,the resulting compiled and optimized Java bytecode will typically run with equal or better performance than naive interpreters. Further , the Java JIT compiler continues to optimize code well after it’s first complied ,depending upon changes in code execution and branching. The cost and effort associated with building this into each independent interpreter makes this kind of performance prohibitive; so , it makes sense to leverage the JVM’s existing multi platform implementation of this performance optimization feature .

A list of other features that JVM brings along are a huge set of well tested libraries , garbage collection , excellent built-in tools and debugging interfaces that a language developer can easily plug into. The biggest advantage that JVM brings to the table is interoperability that it provides.

Prior to Java Se 7 2011 , there was a small penalty hit when crossing the barrier to and from Java code . This was because JVM was not initially built to support dynamically typed languages. To fix this Java Specification Request 292 was developed with the goal of creating a new bytecode instruction to resolve this issue. The result is invoked dynamic bytecode, which is an enhancement to the JVM that allows dynamic and direct linkage between the calling code and receiving code at run time.

Languages Built on JVM

  • JRuby
  • Jython
  • Clojure
  • TCL/Java
  • Groovy

JRuby

JRuby<ref>http://www.jruby.org</ref> is an implementation of the Ruby programming language built on Java Virtual Machine, written in Java. JRuby is tightly integrated with Java so as to provide full two-way access between the Java and the Ruby code.

History of JRuby

Developers
  • Charles Oliver Nutter
  • Thomas Enebo

It was originally created by Jan Arne Petersen, in 2001.

JRuby 1.1 added Just-in-time (JIT) compilation and Ahead-of-time (AOT) compilation modes to JRuby and was already faster in most cases than the then-current Ruby 1.8.7 reference implementation.

JRuby packages are available for most platforms; Fedora 9 was among the first to include it as a standard package at JRuby 1.1.1 Recently , JRuby has been gaining increased presence in the Java and Ruby communities.

Commercial Support for JRuby : Engine Yard Inc.

Compilation of JRuby code is mixed mode which means that the code can be interpreted ,JIT (Just in time ) compiled or AOT (Ahead of time) compiled.

JRuby was the driving force behind adding the invoke dynamic bytecode to the Java SE 7 release. This facilitates Java-to-Ruby and reverse calls to be treated the same as Java-to-Java calls. Additionally, JRuby inspired Sun's Multi-VM JVM research effort, where one JVM can act as a separate sandbox to each of multiple applications, allowing different versions of the JRuby runtime to be loaded and active at the same time.

Framework Support

JRuby has built-in support for Rails, RSpec, Rake, and RubyGems. It allows the use of bundled C libraries known as gems. It also provides the feature of launching the Interactive Ruby Shell (irb). The Netbeans Ruby Pack, available since NetBeans 6.0, allows IDE development with Ruby and JRuby, as well as Ruby on Rails for the two implementations of Ruby.

Code Snippet:
JRuby Calling Java

 require 'java'

 frame = javax.swing.JFrame.new
 frame.getContentPane.add javax.swing.JLabel.new('Hello, World!')
 frame.setDefaultCloseOperation javax.swing.JFrame::EXIT_ON_CLOSE
 frame.pack
 frame.set_visible true}}

Advantages of JRuby over Java

• Ruby has features missing from Java

  • Blocks also known as Closures
  • Open classes
  • Meta programming

• Domain Specific Language (DSL)

Advantages of JRuby over Ruby

JRuby provides you with the best of both the Java and Ruby world : Ruby applications and libraries, plus Java libraries. And you can access those libraries with Ruby syntax (or Java syntax, if you want).

  • On average JRuby, runs 2 and a half times faster than Ruby, except at startup.
  • In addition to native threads, JRuby supports Unicode natively.

Jython

<ref>http://www.jython.org</ref>Jython is the successor to JPython. The Jython project is in accordance with the JPython 1.1.x license. The intent is to manage this project with the same open policies that are serving CPython so well.

What is Jython?

JPython is an implementation of the Python programming language designed to run on the JVM. It consists of a compiler to compile Python source code 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 for the usage of Java packages from within JPython. JPython has been renamed as Jython.

Project inception: Created by Jim Hugunin in 1997
Licensing: Python Software Foundation license

Jython is a fully dynamic language system.

Compilation of Jython is mixed mode which means that the code can be interpreted , JIT compiled or AOT compiled.

Jython, is one of the very first languages to be ported on to the JVM, which is a Java implementation of the Python interpreter to facilitate high-performance Python application execution. Written on the JVM, Jython supports calls into Java code and libraries, and all code is JIT compiled at runtime. The startup time and performance of Jython code is largely determined by the JVM. Jython is almost as fast as CPython.

Purpose

<ref>https://wiki.python.org/jython/JythonFaq/GeneralInfo</ref>There are numerous alternative languages implemented for the Java VM. The following features help to separate Jython from the rest:

  • Dynamic compilation to Java bytecodes - provides highest possible performance.
  • One can extend existing Java classes in Jython - providing effective use of abstract classes.
  • Jython allows creation of applets, servlets and beans.
  • Python Language - combines remarkable power with clear syntax.
  • It also supports a full object-oriented programming model .

Code Snippet:
A class declaration in Jython :

class Hello:

    def __init__(self, name="John Doe"):
       self.name = name
    def greeting(self):
       print "Hello, %s" % self.name

Creation of objects :

   jane = Hello("Jane Doe")
   joe = Hello("Joe")
   default = Hello()

Clojure

<ref>http://en.wikipedia.org/wiki/Clojure</ref>Clojure is a dialect of the Lisp programming language. It was created by Rich Hickey. It is a functional general-purpose language. Its focus on programming with immutable values and explicit progression-of-time constructs .With the help of these constructs it provides support for multi-threaded programs. Clojure runs on Java Virtual Machine, Common Language Runtime, and JavaScript engines.

Licensing: Eclipse Public License.

Commercial support: Community-based

Language type system: Strong, dynamic

Compilation: Bytecode, and JIT compiled

Clojure is a modern-day functional programming language, inter-operable with object-oriented code, and built for concurrency. It's built on and tightly integrated with the JVM, treats all code as data, views functions as objects, and emphasizes on recursion . The main feature of Clojure is its immutable state system that provides much easier, less error-prone, parallel code execution.

Advantages

<ref>http://stackoverflow.com/questions/3046769/advantages-of-clojure</ref>*It provides all the benefits of functional programming languages.

  • It allows dynamic, compact code with late binding, macros, multimethods.
  • Can code functions to sequence abstraction instead of to specific data structures
  • In-built concurrency.

Code Snippets:

Hello World in Clojure

 (println "Hello world!")

Defining a square function

 defn square [x]
 (* x x))

TCL/Java

<ref>http://en.wikipedia.org/wiki/Tcl/Java</ref>Tcl/Java , a project to bridge Tcl and Java, consists of two distinct packages:

  • Tcl Blend
  • Jacl

TCL Blend

Tcl Blend is a Tcl extension that makes use of JNI to facilitate communication between a Java interpreter and a Tcl interpreter. Tcl Blend loads a Java interpreter into an existing Tcl process. Here, the behavior that has been implemented in Java is accessed in a Tcl script. For example, A Java object allocated in a Tcl script can interactively invoke Java methods on this object.

Loading Tcl Blend and Tcl into a Java process enables one to add scripting functionality to an existing Java application. TCL Blend can be used with other popular Tcl extensions like Tk.

JACL

JACL is an implementation of a Tcl interpreter. It is written entirely in Java. Jacl facilitates communication between a Java interpreter and a Tcl interpreter. Jacl helps in incorporating Tcl scripting into an existing Java application, without dealing with the complexities that come with loading Tcl Blend into a Java process.

JTcl, a fork of Jacl, aims to continue the modernization of Jacl that began with the Jacl Modernization Project in the Google Summer of Code.

Groovy

<ref>http://en.wikipedia.org/wiki/Groovy_(programming_language)</ref>Groovy, an object-oriented programming language for the Java platform, is a dynamic language with features similar to those of Python, Ruby and Perl. Most Java code is also syntactically valid Groovy.

  • Groovy can be used as a scripting language for the Java Platform.
  • Groovy is dynamically compiled to Java Virtual Machine (JVM) bytecode
  • Groovy interoperates with other Java code and libraries.

History

James Strachan first talked about the development of Groovy in his blog in August 2003. Several versions were released between 2004 and 2006. After various betas, Groovy 1.1 Final was released and immediately rebranded as Groovy 1.5 as a reflection of the many changes that were made.

Features

<ref>http://stackoverflow.com/questions/764416/why-would-one-use-groovy-over-java</ref> Most valid Java files are also valid Groovy files. This facilitates Java programmers to easily switch to Groovy. Groovy code is more compact when compared to Java. This is because it does not require all the elements that Java requires.

Groovy features not available in Java include:

  • both static and dynamic typing
  • closures
  • operator overloading
  • native syntax for lists and associative arrays
  • support for regular expressions
  • expressions embedded inside strings(String interpolation)
  • additional helper methods
  • Mixins/Categories
  • Collection literals
  • metaprogramming.

Code Snippet:
Example for Metaprogramming in Groovy:

 Number.metaClass {
 sqrt = { Math.sqrt(delegate) }
 }
 assert 9.sqrt() == 3
 assert 4.sqrt() == 2

IDE Support

Many integrated development environments and text editors support Groovy: Eclipse, through Groovy-Eclipse, Emacs, using Groovy-Model, Grails/Griffon in the Ultimate Edition only, NetBeans, since version 6.5 , etc

Tutorial Links

References

<references/>