Wednesday, 16 July 2014

The 8 Alternative Languages For The JVM

    The Java Virtual Machine (JVM) isn't just for java anymore. Several hundred JVM programming languages are available for your projects. These languages ultimately compile to bytecode in class files, which the JVM can then execute. As a result these programming languages benefit from all the optimizations available on the JVM out of the box.

    The JVM languages fall into three categories: 
  1. They have features that Java doesn't have.
  2. They are ports of existing languages to the JVM.
  3. They are research languages. 
    The first category describes languages that include more features than Java and aim to let developers write code in a more concise way. Java SE 8 introduced lambda expressions, the Stream API, and default methods to tackle this issue of conciseness. However, developers love many other features - such as collection literals, pattern matching, and a more sophisticated type interface - that they can't find in Java yet. The languages we'll look at in this first category are Scala, Groovy, Xtend, Ceylon, Kotlin, and Fantom.

    The second category is existing languages that were ported to the JVM. Many languages, such as Python and Ruby, can interact with Java APIs and are popular for scripting and quick prototyping. Both the standard implementation of Python (CPython) and Ruby( Ruby MRI) feature a global interpreter lock, which prevents a multicore system. However, Jython and JRuby - the Python and Ruby implementations on the JVM - get rid of this restriction by making use of Java threads instead.

     Another popular language ported to JVM is Clojure, a dialect of Lisp. In addition, Oracle recently released Nashorn, a project that lets you run JavaScript on the JVM.

     The third category is languages that implement new research ideas, are suited only for a specific domain, or are just experimental, such as X10, is designed for efficient programming for high - performance parallel computing. Another language in this category is Fortress from Oracle Labs, now discontinued.

let's see the brief introduction to these languages.

1. SCALA : 

    Scala is a statically typed programming language that fuses the object - oriented model and functional programming ideas. That mean, in practice, that you can declare classes, create objects, and call methods just like you would typically do in java. However, Scala also brings popular features from functional languages such as pattern matching on data structures, local type inference, persistent collections, and tuple literals. 

    The fusion of object - oriented and functional features lets you use the best tools from both worlds to solve particular problem. As a result, Scala often lets programmers express algorithms more concisely than in Java.

2. GROOVY :

    Groovy is a dynamically typed object-oriented language. Groovy's dynamic nature lets you manipulate your code in powerful ways. For example, you can expand objects at runtime (for example, by adding fields or methods).

    However, Groovy also provides optional static checking, which means that you can catch errors at compile time (for example, calling an undefined method will be reported as an error before the program runs, just as in Java). As a result, programmers who feel that they are more productive without types getting in their way can embrace Groovy's dynamic nature. Nonetheless, they can also opt to gradually use static checking later if they wish. In addition, Groovy is friendly to Java programmers because almost all Java code is also valid Groovy code, so the learning curve is small.

3. CLOJURE : 

    Clojure is a dynamically typed programming language that can be seen as a modern take on Lisp. It is radically different from what object-oriented programmers might be used to. In fact, Clojure is a fully functional programming language, and as a result, it is centered on immutable data structures, recursion, and functions.

4. KOTLIN : 

     Kotlin is a statically typed object oriented language. Its main design goals are to be compatible with Java's API, have a type system that catches more errors at compile time, and be less verbose than Java. Kotlin's designers say that Scala is a close choice to match its design goals, but they dislike Scala's complexity and long compilation time compared to Java. Kotlin aims to tackle these issues. 

5. CEYLON : 

     Red Hat developed Ceylon, a statically typed object - oriented language, to give Java programmers a language that's easy to learn and understand (because of syntax that's similar to Java) but less verbose. Ceylon includes more type system features than Java. For example, Ceylon supports a constuct for defining type aliases ( similar to C's typedef; for example, you could define Strings to be an alias for List<String>), flow typing ( for example, no need to cast the type of an expression in a block if you've already done an instance of check on it), union of types, and local type inference In addition, in Ceylon you can ask certain variables or blocks of code to use dynamic typing - type checking is performed at runtime instead of compile time.

6. XTEND : 

    Xtend is a statically typed object - oriented language. One way it differs from other languages is that it compiles to pretty - printed Java code rather that bytecode. As a result, you can also work with the generated code.

Xtend supports two forms of method invocation: default Java dispatching and multiple dispatching. With multiple dispatching, an overloaded method is selected based on the runtime type of its arguments (instead of the traditional static types of the arguments as in Java). Xtend provides many other popular features available in other languages such as operator overloading and type inference.

One unique feature is template expressions, which are a convenient way to generate string concatenation ( similar to what template engines provide). For example, template expressions support control - flow constructs such as IF and FOR. In addition, special processing of white space allows templates to be readable and their output to be nicely formatted.

7. FANTOM :

    Fantom is an object - oriented language featuring a type system that takes an alternative view compared to most other established, statically typed languages. First, it differentiates itself by not supporting user - defined generics. However, three built-in classes can be parameterized: List, Map, and Func. This design decision was made to let programmers benefit from the use of generics ( such as working with collections) without complicating the overall type system. In addition, Fantom provides two kinds of method invocations : one that goes through type checking at compile time (using a dot notation : . ) and one that defers checking to runtime (using an arrow notation: ->) .

8. X10 : 

    X10 is an experimental object - oriented language that IBM developed. It supports features such as first - class functions and is designed to facilitate efficient programming for high performance parallel computing.

    To this end, the language is based on a programming model called the partitioned global address space. In this model, each process shares a global address space, and slices of this space are allocated as private memory for local data and access. To work with this model, X10 offers specialized built-in language constructs to work with concurrency and distributed execution.

    Compared to popular object - oriented languages, a novel feature in its type system is support for constraint types. You can think of constraint types as a form of contracts attached to types. What makes this useful is that errors are checked statically, eliminating the need for more - expensive runtime checks. For example, one possible application of constraint types is to report out-of-bound array accesses at compile time. 



0 comments:

Post a Comment