Saturday, July 3, 2010

OO Hello World - JRuby



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

The code is identical to the previous post of IronRuby. This is because at the end, both are written in the Ruby programming language. Nevertheless, I decided to create separate posts for those developers looking for their preferred platform and also because of the “Ruby Info” section, which of course differs between the two implementations. In the future, if I post about IronRuby or JRuby 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  
 @name = ""  
 def initialize(name)  
  @name = name.capitalize  
 end  
 def salute  
  puts "Hello #@name!"  
 end  
end  
  
# Greet the world!  
g = Greet.new("world")  
g.salute
Version 2 (Verbose):
Explicitly adding instructions and keywords that are optional to the compiler.
require "java"

module GreetProgram   
 class Greet  
  @name = ""  
  def initialize(name)  
   @name = name.capitalize  
  end  
  def salute  
   puts "Hello #@name!"  
  end  
 end  
   
 # Greet the world!  
 g = Greet.new("world")  
 g.salute    
end
The Program Output:









JRuby Info:
“JRuby is a 100% Java implementation of the Ruby programming language. It is Ruby for the JVM.” Taken from: (http://kenai.com/projects/jruby/pages/AboutJRuby)

“JRuby (or Juby) is a Java implementation of the Ruby programming language, being developed by the JRuby team. It is free software released under a three-way CPL/GPL/LGPL license. 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 (similar to Jython for the Python language).” Taken from: (http://en.wikipedia.org/wiki/JRuby)

Appeared:
2001
Current Version:
Developed by:
Charles Nutter, Thomas Enebo, Nick Sieger, Ola Bini, Marcin Mielzynski, Bill Dortch, Wayne Meissner, MenTaLguY
Creator:
Jan Arne Petersen
Influenced by:
Ruby (Yukihiro Matsumoto)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
JVM
Latest Framework Target:
JDK 6
Mono Target:
No
Allows Unmanaged Code:
Yes (using native libraries)
Source Code Extension:
“.rb”
Keywords:
38
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:


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:


Friday, July 2, 2010

OO Hello World - Cobra



Hello world in Cobra is here! Another Python – Like language which has lots of built in cool features such as Unit Tests and Contracts.


NOTE: The indentation appears to be 1 space when it should be 4. Cobra won't accept anything other than 4 (or one tab per indent). Take it in consideration if you want to test the code :)


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
 var name
 
 cue init(name as String)
   base.init
   #.name = name[0].toString.toUpper + name[1:]
   .name = name.capitalized
  
  def salute
   print "Hello [.name]!"

# Greet the world!
class GreetProgram
  def main
   g = Greet("world")
   g.salute

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

use System
namespace _GreetProgram

 class Greet
  var name as String
  
  cue init(name as String)
   base.init
   #.name = name[0].toString.toUpper + name[1:]
   .name = name.capitalized
  
  def salute
   print "Hello [.name]!"


use _GreetProgram
 
# Greet the world!
 class GreetProgram
  def main is shared
   g = Greet("world")
   g.salute

The Program Output:









Cobra Info:
“Cobra is a general purpose programming language with: a clean, high-level syntax, static and dynamic binding, first class support for unit tests and contracts, compiled performance with scripting conveniences, lambdas and closures, extensions and mixins... and more” Taken from: (http://cobra-language.com/)

Appeared:
2006
Current Version:
Developed by:
Chuck Esterbrook
Creator:
Chuck Esterbrook
Influenced by:
Python (Guido van Rossum), C# (Anders Hejlsberg), Eiffel (Bertrand Meyer), Objective-C (Tom Love, Brad Cox)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
CLR
Latest Framework Target:
2.0
Mono Target:
Yes
Allows Unmanaged Code:
No
Source Code Extension:
“.cobra”
Keywords:
139 (including types)
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
No
Latest IDE Support:
SharpDevelop
MonoDevelop
VisualStudio
Language Reference:
Extra Info:


Thursday, July 1, 2010

OO Hello World - Java



The Hello World version of the program in Java!

I was thinking in why I excluded Java from this blog if it is the de facto language for the JVM! Just like C# is for the CLR, so from now on its included :) in the “Most Active .NET and JVM Languages” post and here below the OO Hello World program… enjoy!


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.

package greetprogram;

class Greet {
    private String name;
    Greet(String name) {
        this.name = name.substring(0,1).toUpperCase() + name.substring(1, name.length());
    }
    void Salute() {
        System.out.println("Hello " + name + "!") ;
    }
}

package greetprogram;
// Greet the world!
class Main {
    public static void main(String[] args) {
        Greet g = new Greet("world");
        g.Salute();
    }
}

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

package greetprogram;
import java.lang.*;

public class Greet {
    private String name;
    public Greet(String name) {
        this.name = name.substring(0,1).toUpperCase() + name.substring(1, name.length());
    }
    public void Salute() {
        System.out.println("Hello " + this.name + "!") ;
    }
}

package greetprogram;
// Greet the world!
public class Main {  
    public static void main(String[] args) {
        Greet g = new Greet("world");
        g.Salute();
    }
}

The Program Output:









Java Info:
“The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is general-purpose, concurrent, class-based, and object-oriented, and is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications.” Taken from: (http://en.wikipedia.org/wiki/Java_(programming_language))

Appeared:
1995
Current Version:
Developed by:
James Gosling & Sun Microsystems
Creator:
James Gosling
Influenced by:
C (Dennis Ritchie) and C++ (Bjarne Stroustrup)
Predecessor Language
Predecessor Appeared
Predecessor Creator
Runtime Target:
JVM
Latest Framework Target:
JDK 6
Mono Target:
No
Allows Unmanaged Code:
No
Source Code Extension:
“.java”
Keywords:
50
Case Sensitive:
Yes
Free Version Available:
Yes
Open Source:
Yes
Standard:
JSR 316?
Latest IDE Support:
NetBeans 6.9
Eclipse
IntelliJ IDEA
Language Reference:
Extra Info: