Sunday, April 22, 2012

OO Hello World - Xtend



The OO Hello World in Xtend, the "the CoffeScript for the JVM", is here!

Xtend is a statically-typed programming language which is tightly integrated with and
runs on the Java Virtual Machine.


You can see the OO Hello World series 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 {
 String name
 new(String name) {
  this.name = name.toFirstUpper
 }
 def salute() {
  println("Hello " + name + "!")
 }
}
// Greet Program
class Program {
 def static void main(String[] args) {
  val g = new Greet("world")  
  g.salute
 } 
}

Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
package com.series

public class Greet {
 private String name
 public new(String name) {
  this.name = name.toFirstUpper()
 }
 def public void salute() {
  println("Hello " + this.name + "!")
 }
}
package com.series

// Greet Program
public class Program { 
 def public static void main(String[] args) {
  val g = new Greet("world")  
  g.salute()
 } 
}

The Program Output:








Xtend Info:

"Xtend is a statically-typed programming language developed at Eclipse.org. It
has a strong focus on leveraging all the good parts of Java, including seamless
integration with the huge amount of Java frameworks and libraries out there.” Taken from: ( Pragmatic Magazine - Issue 30, December 2011 )

Appeared:
2011
Current Version:
Developed by:
Eclipse
Creator:
Sven Efftinge, Sebastian Zarnekow
Influenced by:
Java (James Gosling)
Predecessor Language
N/A
Predecessor Appeared
N/A
Predecessor Creator
N/A
Runtime Target:
JVM
Latest Framework Target:
JDK 6,7
Mono Target:
No
Allows Unmanaged Code:
No
Source Code Extension:
“.xtend”
Keywords:
41
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
N/A
Latest IDE Support:
Eclipse
Language Reference:
Extra Info:


2 comments:

  1. You could use
    this.name = name.toFirstUpper
    in snippet 1 line 04.

    ReplyDelete
    Replies
    1. Hi Jan,

      Thanks for your suggestion. Code updated.
      That's much better.

      Delete