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

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
== 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.
Over the last 10-15 years , the [[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 the 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 ?

Revision as of 17:31, 17 September 2013

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.

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 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 .

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 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.

Different Fusion Languages

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.

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 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 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.

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.

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

• Ruby has features missing from Java

  • Closure (blocks)
  • Open classes
  • Meta programming
  • Duck-typing

• Domain Specific Language (DSL)

  • Through (J)Ruby's capability of allowing expressive method names and cushy semantics

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).

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


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.

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.

Project inception: Created by Jim Hugunin in 1997
Licensing: Permissive free, GPL-like, Python Software Foundation license
Commercial support: Community based
Language type system: Fully dynamic

Compilation of Jython is mixed mode ie code can be interpreted , JIT compiled or AOT compiled.

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

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.

Ability to extend existing Java classes in Jython - allows effective use of abstract classes.

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

Bean Properties - make use of Java packages much easier.

Python Language - combines remarkable power with very clear syntax.

It also supports a full object-oriented programming model which makes it a natural fit for Java's OO design.


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.

Licensing: Eclipse Public License.

Commercial support: Community-based

Language type system: Strong, dynamic

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.

Advantages

  • All the benefits of functional programming, without the purity straitjacket.
  • It allows dynamic, compact code with late binding, macros, multimethods
  • Java interoperability
  • Can code functions to sequence abstraction instead of to specific data structures
  • In-built concurrency : functional data structures, software transactional memory


TCL/Java

Tcl/Java is a project to bridge Tcl and Java. It consists of two distinct packages, Tcl Blend and 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 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.

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.

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.

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.


Groovy

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.

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.

Features

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.

Groovy features not available in Java include:

  • both static and dynamic typing (with the def keyword)
  • closures
  • operator overloading
  • native syntax for lists and associative arrays (maps)
  • native support for regular expressions
  • polymorphic iteration
  • expressions embedded inside strings(String interpolation)
  • additional helper methods
  • safe navigation operator "?." to automatically check for nulls
  • Mixins/Categories
  • Collection literals
  • GPath expressions
  • metaprogramming.

IDE Support

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