<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;C0cCR3gzeyp7ImA9WhBWE0g.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520</id><updated>2013-04-07T09:11:06.683-07:00</updated><category term="POC" /><category term="Python" /><category term="C++/CLI" /><category term="Cobra" /><category term="CLR" /><category term="JVM" /><category term="Gosu" /><category term="Keywords" /><category term="Kotlin" /><category term="Xtend" /><category term="VB.NET" /><category term="JScript.NET" /><category term="Oxygene" /><category term="F#" /><category term="Java" /><category term="Groovy" /><category term="C#" /><category term="PHP" /><category term="Fantom" /><category term="Scala" /><category term="Zonnon" /><category term="Boo" /><category term="JRuby" /><category term="DelphiPrism" /><category term="Jython" /><category term="Nemerle" /><category term="IronRuby" /><category term="Phalanger" /><category term="Series" /><category term="Ceylon" /><category term="IronPython" /><title>Carlos Quintanilla's blog</title><subtitle type="html">On (CLR, JVM) Programming Languagues</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://carlosqt.blogspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>87</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/CarlosQuintanillasBlog" /><feedburner:info uri="carlosquintanillasblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>CarlosQuintanillasBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><entry gd:etag="W/&quot;CUIGSXk9fSp7ImA9WhBWEkg.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1014331208375736535</id><published>2012-07-11T14:09:00.001-07:00</published><updated>2013-04-06T06:05:28.765-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-06T06:05:28.765-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ceylon" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Ceylon</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update 1:&lt;/b&gt; Porting code examples to Ceylon M5 - syntax changes on assignent operator, module definition and support for String Interpolation.
&lt;br /&gt;
&lt;b&gt;Update 2:&lt;/b&gt; Interoperability with java code via .jar containing the Stopwatch class imported as a ceylon module using ceylon import-jar.
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Ceylon that implements 2 modules (+ an extra utility Stopwatch java class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the module called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the execution of the program done by the running function "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your Eclipse IDE and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;
module com.series.staticfiborial '1.0.0' {
    shared import java.base '7';
    import blog.series.lib '1.0.0';
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Factorial and Fibonacci in Ceylon  
  
// Module "Static Class" using top level members  
import java.math { BigInteger { bigone=\iONE, bigzero=\iZERO,  
                                big=\IvalueOf } }  
import blog.series.lib { Stopwatch }  
  
// '(private) Static Field' + Initialization  
variable String _className = "'Static' Constructor";  
  
// Static Initializer Method instead, but need to be explicitly called.  
shared void constructor() {  
    print(_className);  
}  
  
// 'Static' Method - Factorial Recursive    
 shared BigInteger factorialR(Integer n) {    
    if (n == 1) {  
        return bigone;  
    }  
    else {  
        return big(n).multiply(factorialR(n - 1));  
    }    
}    
  
// 'Static' Method - Factorial Imperative    
shared BigInteger factorialI(Integer n) {  
    variable Integer c = n;  
    variable BigInteger res = bigone;  
    while (c &gt; 1) {    
        res = res.multiply(big(c));  
        c--;  
    }  
    return res;  
}    
  
// 'Static' Method - Fibonacci Recursive    
shared Integer fibonacciR(Integer n) {    
    if (n &lt; 2) {   
        return 1;  
    }    
    else {  
        return fibonacciR(n - 1) + fibonacciR(n - 2);  
    }    
}    
  
// 'Static' Method - Fibonacci Imperative    
shared Integer fibonacciI(Integer n) {    
    variable Integer pre = 1;  
    variable Integer cur = 1;  
    variable Integer tmp = 0;  
    for (i in 2..n) {    
        tmp = cur + pre;    
        pre = cur;    
        cur = tmp;    
    }    
    return cur;    
}  
  
// 'Static' Method - Benchmarking Algorithms    
shared void benchmarkAlgorithm(Integer algorithm, Integer[] values) {    
    Stopwatch timer = Stopwatch();  
    variable BigInteger facTimeResult = bigzero;  
    variable Integer fibTimeResult = 0;  
      
    if (algorithm == 1) {  
        print("\nFactorial Imperative:");  
        // "For" Loop Statement    
        for (j in 0..values.size - 1) {  
            if (exists testValue = values[j]) {  
                // Taking Time    
                timer.start();   
                facTimeResult = factorialI(testValue);  
                timer.stop();    
                // Getting Time    
                print(" (``testValue.string``) = ``timer.elapsed``");    
            }              
        }    
    }  
    else if(algorithm == 2) {  
        print("\nFactorial Recursive:");    
        // "While" Loop Statement    
        variable Integer i = 0;  
        while (i &lt; values.size) {  
            if (exists testValue = values[i]) {       
                // Taking Time    
                timer.start();    
                facTimeResult = factorialR(testValue);    
                timer.stop();    
                // Getting Time    
                print(" (``testValue.string``) = ``timer.elapsed``");               
            }  
            i++;  
        }          
    }  
    else if (algorithm == 3) {  
        print("\nFibonacci Imperative:");    
        // "For Each" Loop Statement    
        for (testValue in values) {              
            // Taking Time    
            timer.start();   
            fibTimeResult = fibonacciI(testValue);    
            timer.stop();    
            // Getting Time    
            print(" (``testValue.string``) = ``timer.elapsed``");                        
        }    
    }  
    else if (algorithm == 4) {  
        print("\nFibonacci Recursive:");    
        // "For Each" Loop Statement    
        for (testValue in values) {              
            // Taking Time    
            timer.start();    
            fibTimeResult = fibonacciR(testValue);    
            timer.stop();    
            // Getting Time    
            print(" (``testValue.string``) = ``timer.elapsed``");  
        }          
    }  
    else {  
        print("DONG!");  
    }  
}  

doc "Run the module `com.series.staticfiborial`."  
void run() {  
    // pass    
}  
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;
module com.series.fiborial '1.0.0' {
    import java.base '7';
    shared import com.series.staticfiborial '1.0.0';
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;import java.math { BigInteger }  
import java.util { Scanner }  
import java.lang { System { sin=\Iin } }   
// Import 'Static' Module's 'methods'  
import com.series.staticfiborial { staticFiborial=constructor, benchmarkAlgorithm,  
                                    facI=factorialI, facR=factorialR,  
                                    fibI=fibonacciI, fibR=fibonacciR }  
  
// Instance Class    
class InstanceFiborial(className="Instance Constructor") {    
    // Instance Field and Constructor/Initializer  
    variable String className;  
    print(className);  
    // Instance Method - Factorial Recursive    
    shared BigInteger factorialR(Integer n) {    
        // Calling Static Method    
        return facR(n);    
    }    
    // Instance Method - Factorial Imperative    
    shared BigInteger factorialI(Integer n) {    
        // Calling Static Method    
        return facI(n);    
    }    
    // Instance Method - Fibonacci Recursive    
    shared Integer fibonacciR(Integer n) {    
        // Calling Static Method    
        return fibR(n);    
    }    
    // Instance Method - Fibonacci Imperative    
    shared Integer fibonacciI(Integer n) {    
        // Calling Static Method    
        return fibI(n);    
    }    
}    

doc "Run the module `com.series.fiborial`."  
void main() {  
    print("\n'Static' Class");    
    // Calling 'Static' Class and Methods    
    // No instantiation needed. Calling method directly from the class    
    staticFiborial();    
    print("FacImp(5) = ``facI(5).string``");    
    print("FacRec(5) = ``facR(5).string``");    
    print("FibImp(11)= ``fibI(11).string``");    
    print("FibRec(11)= ``fibR(11).string``");   
    
    print("\nInstance Class");  
    // Calling Instance Class and Methods    
    // Need to instantiate before using. Call method from instantiated object    
    value ff = InstanceFiborial();    
    print("FacImp(5) = ``ff.factorialI(5).string``");  
    print("FacRec(5) = ``ff.factorialR(5).string``");    
    print("FibImp(11)= ``ff.fibonacciI(11).string``");  
    print("FibRec(11)= ``ff.fibonacciR(11).string``");  
    
    // Create a (generic) list of integer values to test    
    // From 5 to 50 by 5        
    Integer[] values = [
        for (i in 5..50)    
            if (i%5==0) i
    ];    

    // Benchmarking Fibonacci    
    // 1 = Factorial Imperative    
    benchmarkAlgorithm(1, values);    
    // 2 = Factorial Recursive    
    benchmarkAlgorithm(2, values);    
    
    // Benchmarking Factorial    
    // 3 = Fibonacci Imperative    
    benchmarkAlgorithm(3, values);    
    // 4 = Fibonacci Recursive    
    benchmarkAlgorithm(4, values);  
    
    // Stop and exit    
    print("Press any key to exit...");   
    value s = Scanner(sin);  
    //String line = s.nextLine();  
    s.nextLine();
    s.close();  
}  
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-X15NRYWavZU/T_7R2z8oalI/AAAAAAAAGlw/94ludOoUR5U/s1600/FiborialCeylon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-X15NRYWavZU/T_7R2z8oalI/AAAAAAAAGlw/94ludOoUR5U/s1600/FiborialCeylon.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;
module com.series.fiborialseries '1.0.0' {
    shared import java.base '7';
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;
import java.math { BigInteger { bigone=\iONE,     
                                big=\IvalueOf } }    
      
class Fiborial() {      
    // Using a StringBuilder as a list of string elements        
    shared String getFactorialSeries(Integer n) {        
        // Create the String that will hold the list        
        value series = StringBuilder();        
        // We begin by concatenating the number you want to calculate        
        // in the following format: "!# ="        
        series.append("!");        
        series.append(n.string);    
        series.append(" = ");        
        // We iterate backwards through the elements of the series        
        variable value i = n;        
        while (i &gt; 0) {        
            // and append it to the list        
            series.append(i.string);    
            if (i &gt; 1) {        
                series.append(" * ");    
            }        
            else {        
                series.append(" = ");    
            }    
            i--;        
        }        
        // Get the result from the Factorial Method        
        // and append it to the end of the list        
        series.append(factorial(n).string);        
        // return the list as a string        
        return series.string;     
    }    
        
    // Using a StringBuilder as a list of string elements        
    shared String getFibonnaciSeries(Integer n) {        
        // Create the String that will hold the list        
        value series = StringBuilder();        
        // We begin by concatenating the first 3 values which        
        // are always constant        
        series.append("0, 1, 1");  
        // Then we calculate the Fibonacci of each element        
        // and add append it to the list        
        for (i in 2..n) {        
            if (i &lt; n) {       
                series.append(", ");    
            }    
            else {        
                series.append(" = ");    
            }    
            series.append(fibonacci(i).string);        
        }        
        // return the list as a string        
        return series.string;      
    }        
        
    shared BigInteger factorial(Integer n) {      
        if (n == 1) {        
              return bigone;    
        }    
        else {    
            return big(n).multiply(factorial(n - 1));    
        }             
    }             
        
    shared Integer fibonacci(Integer n) {      
        if (n &lt; 2) {      
            return 1;    
        }    
        else {      
            return fibonacci(n - 1) + fibonacci(n - 2);    
        }    
    }          
}      
    
void run() {    
     // Printing Factorial Series      
    print("");      
    value fiborial = Fiborial();     
    print(fiborial.getFactorialSeries(5));      
    print(fiborial.getFactorialSeries(7));     
    print(fiborial.getFactorialSeries(9));      
    print(fiborial.getFactorialSeries(11));      
    print(fiborial.getFactorialSeries(40));      
    // Printing Fibonacci Series      
    print("");    
    print(fiborial.getFibonnaciSeries(5));      
    print(fiborial.getFibonnaciSeries(7));      
    print(fiborial.getFibonnaciSeries(9));      
    print(fiborial.getFibonnaciSeries(11));     
    print(fiborial.getFibonnaciSeries(40));      
}  
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-iRsvshew2zc/T_3dAruu9OI/AAAAAAAAGlI/--gXD6TglFU/s1600/FiborialSeriesCeylon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="285" src="http://4.bp.blogspot.com/-iRsvshew2zc/T_3dAruu9OI/AAAAAAAAGlI/--gXD6TglFU/s640/FiborialSeriesCeylon.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style="background-color: white;"&gt;In Ceylon it is not possible to define a class with static members. To emulate that you need to create a module with toplevel methods, attributes, and even other instance types/classes.&lt;/span&gt;&lt;br /&gt;
"There are no&amp;nbsp;&lt;tt class="literal" style="font-family: 'Courier New', Courier, monospace; font-size: 14px;"&gt;static&lt;/tt&gt;&amp;nbsp;members. Instead,&amp;nbsp;&lt;span class="emphasis"&gt;&lt;em&gt;toplevel&lt;/em&gt;&lt;/span&gt;&amp;nbsp;methods and attributes are declared as direct members of a package. This, along with certain other features, gives the language a more regular block structure." taken from Ceylon documentation.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;    
module com.series.staticfiborial '1.0.0' {}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;    
// Module "Static Class" using top level members  
  
// 'Static' Field'   
variable Integer _staticCount = 0;    
// 'Static' Read-Only Property/Getter  
shared Integer staticCount {  
    return _staticCount;  
}  
// 'Static' Initializer Method instead, but need to be explicitly called.  
shared void constructor() {  
    print("\nStatic Constructor ``_staticCount.string``");  
}  
// 'Static' Method  
shared void fibonacci(Integer n) {  
    _staticCount++;  
    print("\nFibonacci(``n.string``)");  
}  
  
void run() {  
    // pass  
}  
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;    
module com.series.fiborial '1.0.0' {
    import com.series.staticfiborial '1.0.0';
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;    
import com.series.staticfiborial { staticCount, fibonacci,  
                                    staticFiborial=constructor }  
  
// Instance Class  
shared class InstanceFiborial(_instanceCount=0) {    
    // Instance Field and Constructor/Initializer  
    variable Integer _instanceCount;      
    print("Instance Constructor ``this._instanceCount.string``");      
    // Instance Read-Only Property/Getter  
    shared Integer instanceCount {  
        return this._instanceCount;  
    }  
    // Instance Method    
    shared void factorial(Integer n) {    
        this._instanceCount++;    
        print("\nFactorial(``n.string``)");    
    }    
}  
  
void main() {  
    // Calling Static Constructor and Methods    
    // No need to instantiate    
    staticFiborial();    
    fibonacci(5);    
    
    // Calling Instance Constructor and Methods    
    // Instance required    
    value fib = InstanceFiborial();    
    fib.factorial(5);    
    
    fibonacci(15);    
    fib.factorial(5);    
    
    // Calling Instance Constructor and Methods    
    // for a second object    
    value fib2 = InstanceFiborial();    
    fib2.factorial(5);    
    
    print("");    
    // Calling Static Property    
    print("Static Count = " + staticCount.string);    
    // Calling Instance Property of object 1 and 2    
    print("Instance 1 Count = " + fib.instanceCount.string);    
    print("Instance 2 Count = " + fib2.instanceCount.string);    
}  
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-jBC1XakILUo/T_3mFGtlcoI/AAAAAAAAGlU/wjli3Y9d338/s1600/FiborialExtrasCeylon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-jBC1XakILUo/T_3mFGtlcoI/AAAAAAAAGlU/wjli3Y9d338/s1600/FiborialExtrasCeylon.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt; &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;module com.series.fiborial '1.0.0' {
    shared import java.base '7';
    import blog.series.lib '1.0.0'; 
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;
import java.math { BigInteger { bigone=\iONE, bigzero=\iZERO,  
                                big=\IvalueOf } }  
import blog.series.lib { Stopwatch }  
  
// Long/Integer Factorial      
Integer factorialInt64(Integer n) {    
    if (n == 1) {  
        return 1;  
    }  
    else {  
        return n * factorialInt64(n - 1);  
    }    
}    
  
// Double Factorial    
Float factorialDouble(Integer n) {    
    if (n == 1) {  
        return 1.0;  
    }  
    else {  
        return n * factorialDouble(n - 1);  
    }    
}    
  
// BigInteger Factorial      
BigInteger factorialBigInteger(Integer n) {    
    if (n == 1) {  
        return bigone;  
    }  
    else {  
        return big(n).multiply(factorialBigInteger(n - 1));  
    }    
}     

void main() {  
    value timer = Stopwatch();    
    variable Integer facIntResult = 0;    
    variable Float facDblResult = 0.0;    
    variable BigInteger facBigResult = bigzero;        
      
    print("\nFactorial using Int64");  
    // Benchmark Factorial using Int64    
    for (i in (5..50).by(5)) {  
        timer.start();  
        facIntResult = factorialInt64(i);   
        timer.stop();  
        print(" (``i.string``) = ``timer.elapsed.string`` : ``facIntResult.string``");    
    }  
  
    print("\nFactorial using Double");    
    // Benchmark Factorial using Double  
    for (i in (5..50).by(5)) {  
        timer.start();  
        facDblResult = factorialDouble(i);   
        timer.stop();  
        print(" (``i.string``) = ``timer.elapsed.string`` : ``facDblResult.string``");  
    }  
  
    print("\nFactorial using BigInteger");    
    // Benchmark Factorial using BigInteger  
    for (i in (5..50).by(5)) {  
        timer.start();  
        facBigResult = factorialBigInteger(i);   
        timer.stop();  
        print(" (``i.string``) = ``timer.elapsed.string`` : ``facBigResult.string``");  
    }    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-qRiYQ4n38rA/T_3rSye1GzI/AAAAAAAAGlk/4TWCQhwLTXo/s1600/FiborialTypesCeylon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="567" src="http://2.bp.blogspot.com/-qRiYQ4n38rA/T_3rSye1GzI/AAAAAAAAGlk/4TWCQhwLTXo/s640/FiborialTypesCeylon.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/MO2EqJBAcNg" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1014331208375736535/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/07/factorial-and-fibonacci-in-ceylon.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1014331208375736535?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1014331208375736535?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/MO2EqJBAcNg/factorial-and-fibonacci-in-ceylon.html" title="Factorial and Fibonacci in Ceylon" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-X15NRYWavZU/T_7R2z8oalI/AAAAAAAAGlw/94ludOoUR5U/s72-c/FiborialCeylon.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/07/factorial-and-fibonacci-in-ceylon.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUBQHw5fCp7ImA9WhBWEkg.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1526451520324377991</id><published>2012-07-09T09:36:00.001-07:00</published><updated>2013-04-06T06:50:51.224-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-06T06:50:51.224-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ceylon" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Ceylon - Basics by Example</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update 1:&lt;/b&gt; Porting code examples to Ceylon M5 - syntax changes on assignent operator, module definition and support for String Interpolation. 
&lt;br /&gt;
&lt;br /&gt;
Extending my Basics by Example series to a new language. today's version of the post written in &lt;b&gt;Ceylon&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
You can copy and paste the code below in Eclipse and start playing and learning with it. This little "working" program will teach you the basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Verbose&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;module com.series.basics '1.0.0' {
    import java.base '7';
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;
// Ceylon Basics  
import java.util { Calendar, GregorianCalendar, Scanner }  
import java.lang { System { sin = \Iin } }  
  
// (Main) Constructor/Initializer  
// Instead of method and constructor overloading,   
// Ceylon supports parameters with default values and sequenced ("varargs") parameters.  
shared class Greet(_name="", _message="", _loopMessage=0) {  
    // Fields or Attributes    
    variable String _name;  
    variable String _message;  
    variable Integer _loopMessage;  
    // Getters and Setters  
    shared String name {  
        return _name;  
    }  
    assign name {  
        _name = this.capitalize(name);  
    }  
    shared String message {  
        return _message;  
    }  
    assign message {  
        _message = this.capitalize(message);  
    }  
    shared Integer loopMessage {  
        return _loopMessage;  
    }  
    assign loopMessage {  
        _loopMessage = loopMessage;  
    }  
    // Overloaded/Secondary Constructor    
    // No overloaded constructors/initializers  
    // Method 1    
    String capitalize(String val) {    
          // "if-then-else" statement    
        if (val.size &gt; 0) {  
            return val[0..0].uppercased + val[1...];  
        }    
        else {  
            return "";  
        }  
     }  
    // Method 2    
    shared void salute() {    
        // "for" statement    
        for(i in 1..this._loopMessage) {    
            print("``this._message`` ``this._name``!");    
        }    
    }    
    // Overloaded Method    
    // No Overloaded Methods Support. New methods instead.    
    // Method 2.1    
    shared void salute21(String message, String name, Integer loopMessage) {    
        // "while" statement    
        variable Integer i = 1;    
        while (i &lt;= loopMessage) {    
            print("``this.capitalize(message)`` ``this.capitalize(name)``!");    
            i++;    
        }    
    }    
    // Overloaded Method    
    // No Overloaded Methods Support. New methods instead.    
    // Method 2.2    
    shared void salute22(String name) {  
        Calendar dtNow = GregorianCalendar();  
        variable Integer hh = dtNow.get(dtNow.\iHOUR_OF_DAY);  
        // Ceylon doc: The type of the switched expression must be an enumerated type.   
        // You can't switch on a String or Integer. (Use if instead.)  
        // if-else-if statement  
        if (hh in 6..11) { this._message = "good morning,"; }   
        else if (hh in 12..17) { this._message = "good afternoon,"; }   
        else if (hh in 18..22) { this._message = "good evening,"; }   
        else if (hh == 23 || hh in 0..5) { this._message = "good night,"; }   
        else { this._message = "huh?"; }  
        print("``this.capitalize(this._message)`` ``this.capitalize(name)``!");  
    }  
  
}  
  
doc "Run the module `com.series.basics`."
shared void run() {  
    // Define variable object of type Greet and Instantiate. Call Constructor      
    value g = Greet();  
    // Call Setter  
    g.message = "hello";    
    g.name = "world";    
    g.loopMessage = 5;    
    // Call Method 2    
    g.salute();  
    // Call Overloaded Method 2.1 and Getter    
    g.salute21(g.message, "Ceylon", g.loopMessage);    
    // Call Overloaded Method 2.2    
    g.salute22("carlos");    
  
    print("Press any key to exit...");  
    Scanner s = Scanner(sin);  
    String line = s.nextLine();  
    s.close();  
}  
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Minimal&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;module com.series.basics '1.0.0' {
    import java.base '7';
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;
// Ceylon Basics  
import java.util { Calendar, GregorianCalendar, Scanner }  
import java.lang { System { sin = \Iin } }  
  
// (Main) Constructor/Initializer  
// Instead of method and constructor overloading,   
// Ceylon supports parameters with default values and sequenced ("varargs") parameters.  
class Greet(_name="", _message="", _loopMessage=0) {  
    // Fields or Attributes    
    variable String _name;  
    variable String _message;  
    variable Integer _loopMessage;  
    // Getters and Setters  
    shared String name {  
        return _name;  
    }  
    assign name {  
        _name = capitalize(name);  
    }  
    shared String message {  
        return _message;  
    }  
    assign message {  
        _message = capitalize(message);  
    }  
    shared Integer loopMessage {  
        return _loopMessage;  
    }  
    assign loopMessage {  
        _loopMessage = loopMessage;  
    }  
    // Overloaded/Secondary Constructor    
    // No overloaded constructors/initializers  
    // Method 1    
    String capitalize(String val) {    
          // "if-then-else" statement    
        if (val.size &gt; 0) {  
            return val[0..0].uppercased + val[1...];  
        }    
        else {  
            return "";  
        }  
     }  
    // Method 2    
    shared void salute() {    
        // "for" statement    
        for(i in 1.._loopMessage) {    
            print("``_message`` ``_name``!");    
        }    
    }    
    // Overloaded Method    
    // No Overloaded Methods Support. New methods instead.    
    // Method 2.1    
    shared void salute21(String message, String name, Integer loopMessage) {    
        // "while" statement    
        variable Integer i = 1;    
        while (i &lt;= loopMessage) {    
            print("``capitalize(message)`` ``capitalize(name)``!");    
            i++;    
        }    
    }    
    // Overloaded Method    
    // No Overloaded Methods Support. New methods instead.    
    // Method 2.2    
    shared void salute22(String name) {  
        Calendar dtNow = GregorianCalendar();  
        variable Integer hh = dtNow.get(dtNow.\iHOUR_OF_DAY);  
        // Ceylon documentation: The type of the switched expression must be an enumerated type.   
        // You can't switch on a String or Integer. (Use if instead.)  
        // if-else-if statement  
        if (hh in 6..11) { _message = "good morning,"; }   
        else if (hh in 12..17) { _message = "good afternoon,"; }   
        else if (hh in 18..22) { _message = "good evening,"; }   
        else if (hh == 23 || hh in 0..5) { _message = "good night,"; }   
        else { _message = "huh?"; }  
        print("``capitalize(_message)`` ``capitalize(name)``!");  
    }  
  
}  
  
void run() {  
    // Define variable object of type Greet and Instantiate. Call Constructor      
    value g = Greet();  
    // Call Setter  
    g.message = "hello";    
    g.name = "world";    
    g.loopMessage = 5;    
    // Call Method 2    
    g.salute();  
    // Call Overloaded Method 2.1 and Getter    
    g.salute21(g.message, "Ceylon", g.loopMessage);    
    // Call Overloaded Method 2.2    
    g.salute22("carlos");    
  
    print("Press any key to exit...");  
    value s = Scanner(sin);  
    s.nextLine();  
    s.close();  
}  
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-9Df2wDNaC2w/T_sEnJVU1LI/AAAAAAAAGko/RnaYJkh-zHc/s1600/BasicsByExampleCeylon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="368" src="http://3.bp.blogspot.com/-9Df2wDNaC2w/T_sEnJVU1LI/AAAAAAAAGko/RnaYJkh-zHc/s640/BasicsByExampleCeylon.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
Note: the following is extracted from Ceylon documentation:&lt;br /&gt;
"you don't need to write getters and setters unless you're doing something special with the value you're getting or setting.&lt;br /&gt;
Don't ever write code like this in Ceylon:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;variable String _name;
shared String name { return _name; }
assign name { _name=name; }
&lt;/pre&gt;
&lt;br /&gt;
It's not necessary, and there's never any benefit to it."&lt;br /&gt;
&lt;br /&gt;
That is exactly what I'm doing with the setters and loopMessage's getter, but remember that the code is like that just because I'm showing the syntax constructs, more importantly, this helps to compare with other languages. The code above is not intended to teach "good practices" nor "idiomatic" code.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Auto-Implemented Properties in Ceylon&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In Ceylon there are no such auto-implemented properties that generate automatically a Java bean like getter/setter, instead you need to use class attributes directly using the shared annotation to make them public.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;class UsingAttributesToSetGet() {  
    // Attributes   
    shared variable String name = "";  
    shared variable String message = "";  
    shared variable Integer loopMessage = 0;  
    // Methods    
    shared void salute() {    
        print("``message`` ``name`` ``loopMessage.string``!");   
    }    
}

void run() {  
    value g = UsingAttributesToSetGet();  
    // Set the attribute    
    g.message = "hello";    
    g.name = "world";    
    g.loopMessage = 5;    
    // print them out    
    g.salute();    
    // and print them again using the attribute    
    print("``g.message`` ``g.name`` ``g.loopMessage.string``!");
}  
&lt;/pre&gt;
&lt;br /&gt;
And the output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-w4jANmd3aP0/T_r7on86iWI/AAAAAAAAGkc/FeXCTh-xukg/s1600/AutoImplPropCeylon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-w4jANmd3aP0/T_r7on86iWI/AAAAAAAAGkc/FeXCTh-xukg/s1600/AutoImplPropCeylon.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/o0J8nkY4wzI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1526451520324377991/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/07/ceylon-basics-by-example.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1526451520324377991?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1526451520324377991?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/o0J8nkY4wzI/ceylon-basics-by-example.html" title="Ceylon - Basics by Example" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-9Df2wDNaC2w/T_sEnJVU1LI/AAAAAAAAGko/RnaYJkh-zHc/s72-c/BasicsByExampleCeylon.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/07/ceylon-basics-by-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUMARXc-eip7ImA9WhJRGU0.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1462822315894633494</id><published>2012-07-08T16:31:00.000-07:00</published><updated>2012-07-21T14:50:44.952-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-07-21T14:50:44.952-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Xtend" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Xtend</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Xtend that implements 2 classes (in fact, they are 3 + an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your Eclipse IDE and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Factorial and Fibonacci in Xtend  
package com.series
import com.series.Stopwatch
import java.math.BigInteger
import java.util.List

// Instance Class
// static is not a class modifier in Xtend
class StaticFiborial {
    // Static Field
    private static String className = "'Static' Constructor"
    // Static Constructor/Initializer  
    // no available static constructor support  
    // Static Initializer Method instead, but need to be explicitly invoked  
    def static constructor() {  
        className = "'Static' Constructor"  
        println(className)  
    }  
    // Static Method - Factorial Recursive  
    def static BigInteger factorialR(int n) {
        if (n == 1)  
              return 1BI
        else
            return BigInteger::valueOf(n) * factorialR(n - 1)       
    }
    // Static Method - Factorial Imperative  
    def static BigInteger factorialI(int n) {
        var res = 1BI
        var m = n // method parameters are final
        while (m &amp;gt; 1) {
            res = res * BigInteger::valueOf(m)
            m = m - 1    
        }   
        return res     
    }
    // Static Method - Fibonacci Recursive   
    def static long fibonacciR(int n) {
        if (n &amp;lt; 2)
            return 1L
        else
            return fibonacciR(n - 1) + fibonacciR(n - 2)
    } 
    // Static Method - Fibonacci Imperative
    def static long fibonacciI(int n) {
        var pre = 1L
        var cur = 1L
        var tmp = 0L
        for (int i : 2..n) {
            tmp = cur + pre
            pre = cur
            cur = tmp
        }             
        return cur
    }    
    // Static Method - Benchmarking Algorithms  
      def static void benchmarkAlgorithm(int algorithm, List&amp;lt;Integer&amp;gt; values) {  
        val timer = new Stopwatch  
        var testValue = 0
        var facTimeResult = 0BI  
        var fibTimeResult = 0L 
        var i = 0 
        // "Switch" Flow Control Statement
        switch algorithm {
            case 1: {
                println("\nFactorial Imperative:")  
                // "For" Loop Statement  
                for (int j : 0..values.size - 1) {  
                    testValue = values.get(j).intValue
                    // Taking Time
                    timer.start
                    facTimeResult = factorialI(testValue)  
                    timer.stop 
                    // Getting Time  
                    println(''' («testValue») = «timer.getElapsed»''')
                    }
                }
            case 2: {
                println("\nFactorial Recursive:")    
                // "While" Loop Statement                
                while (i &amp;lt; values.size) {                            
                    testValue = values.get(i).intValue    
                    // Taking Time    
                    timer.start    
                    facTimeResult = factorialR(testValue)    
                    timer.stop    
                    // Getting Time    
                    println(''' («testValue») = «timer.getElapsed»''')
                    i = i + 1    
                }
            }
            case 3: {
                println("\nFibonacci Imperative:")   
                // "Do-While" Loop Statement
                do {    
                    testValue = values.get(i).intValue    
                    // Taking Time    
                    timer.start    
                    fibTimeResult = fibonacciI(testValue)    
                    timer.stop
                    // Getting Time    
                    println(''' («testValue») = «timer.getElapsed»''')
                    i = i + 1        
                } while (i &amp;lt; values.size)    
            }
            case 4: {
                println("\nFibonacci Recursive:")    
                // "For Each" Loop Statement    
                for (int item : values) {    
                    testValue = item;    
                    // Taking Time    
                    timer.start    
                    fibTimeResult = fibonacciR(testValue)    
                    timer.stop    
                    // Getting Time    
                    println(''' («testValue») = «timer.getElapsed»''')
                }    
            }
            default : println("DONG!")
        }
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import com.series.StaticFiborial
import java.math.BigInteger

// Instance Class    
class InstanceFiborial {
    // Instance Field    
    private String className    
    // Instance Constructor    
    new() {    
        this.className = "Instance Constructor"
        println(this.className)
    }    
    // Instance Method - Factorial Recursive    
    def BigInteger factorialR(int n) {    
        // Calling Static Method    
        return StaticFiborial::factorialR(n)    
    }    
    // Instance Method - Factorial Imperative    
    def BigInteger factorialI(int n) {    
        // Calling Static Method
        return StaticFiborial::factorialI(n)
    }    
    // Instance Method - Fibonacci Recursive
    def long fibonacciR(int n) {    
        // Calling Static Method    
        return StaticFiborial::fibonacciR(n)    
    }    
    // Instance Method - Factorial Imperative    
    def long fibonacciI(int n) {    
        // Calling Static Method    
        return StaticFiborial::fibonacciI(n);    
    }    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import com.series.StaticFiborial
import com.series.InstanceFiborial 
import java.util.List
import java.util.ArrayList
import java.util.Scanner

class FiborialProgram {
    def static main(String[] args) {
        println("\n'Static' Class")    
        // Calling Static Class and Methods    
        // No instantiation needed. Calling method directly from the class
        StaticFiborial::constructor        
        println('''FacImp(5) = «StaticFiborial::factorialI(5)»''')    
        println('''FacRec(5) = «StaticFiborial::factorialR(5)»''')    
        println('''FibImp(11)= «StaticFiborial::fibonacciI(11)»''')    
        println('''FibRec(11)= «StaticFiborial::fibonacciR(11)»''')    

        println("\nInstance Class");    
        // Calling Instance Class and Methods     
        // Need to instantiate before using. Calling method from instantiated object    
        val ff = new InstanceFiborial
        println('''FacImp(5) = «ff.factorialI(5)»''')
        println('''FacRec(5) = «ff.factorialR(5)»''')  
        println('''FibImp(11)= «ff.fibonacciI(11)»''')   
        println('''FibRec(11)= «ff.fibonacciR(11)»''')  
  
        // Create a (generic) list of integer values to test    
        // From 5 to 50 by 5    
        val List&amp;lt;Integer&amp;gt; values = new ArrayList&amp;lt;Integer&amp;gt;
        var i = 5
        while (i &amp;lt; 55) {  
            values.add(i)  
            i = i + 5  
        }
  
        // Benchmarking Fibonacci                         
        // 1 = Factorial Imperative                
        StaticFiborial::benchmarkAlgorithm(1, values)    
        // 2 = Factorial Recursive    
        StaticFiborial::benchmarkAlgorithm(2, values)     
  
        // Benchmarking Factorial                
        // 3 = Fibonacci Imperative    
        StaticFiborial::benchmarkAlgorithm(3, values)    
        // 4 = Fibonacci Recursive    
        StaticFiborial::benchmarkAlgorithm(4, values)     
  
        // Stop and exit    
        println("Press any key to exit...")          
        val in = new Scanner(System::in)    
        val line = in.nextLine    
        in.close         
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-REnBwOKPqN8/T_oArOTy0kI/AAAAAAAAGjs/ofWubyJmVy0/s1600/FiborialXtend.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-REnBwOKPqN8/T_oArOTy0kI/AAAAAAAAGjs/ofWubyJmVy0/s1600/FiborialXtend.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import java.math.BigInteger
import java.lang.StringBuffer

class Fiborial {
    // Using a StringBuffer as a list of string elements  
    def static String getFactorialSeries(int n) {  
        // Create the String that will hold the list  
        val series = new StringBuffer  
        // We begin by concatenating the number you want to calculate  
        // in the following format: "!# ="  
        series.append("!")  
        series.append(n) 
        series.append(" = ")  
        // We iterate backwards through the elements of the series  
        var i = n  
        while (i &amp;gt; 0) {  
            // and append it to the list  
            series.append(i)  
            if (i &amp;gt; 1)  
                series.append(" * ")  
            else  
                series.append(" = ")  
            i = i - 1  
        }  
        // Get the result from the Factorial Method  
        // and append it to the end of the list  
        series.append(factorial(n))  
        // return the list as a string  
        return series.toString
    }  
  
    // Using a StringBuffer as a list of string elements  
    def static String getFibonnaciSeries(int n)  
    {  
        // Create the String that will hold the list  
        val series = new StringBuffer  
        // We begin by concatenating the first 3 values which  
        // are always constant  
        series.append("0, 1, 1")
        // Then we calculate the Fibonacci of each element  
        // and add append it to the list  
        for (int i : 2..n) {  
            if (i &amp;lt; n)  
                series.append(", ")  
            else  
                series.append(" = ")  
            series.append(fibonacci(i))  
        }  
        // return the list as a string  
        return series.toString
    }  
  
    def static BigInteger factorial(int n) {
        if (n == 1)  
              return 1BI
        else
            return BigInteger::valueOf(n) * factorial(n - 1)       
    }       
  
    def static long fibonacci(int n) {
        if (n &amp;lt; 2)
            return 1L
        else
            return fibonacci(n - 1) + fibonacci(n - 2)
    }    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import com.series.Fiborial

class FiborialProgram {
    def static void main(String[] args) {
        // Printing Factorial Series  
        println 
        println(Fiborial::getFactorialSeries(5))
        println(Fiborial::getFactorialSeries(7))  
        println(Fiborial::getFactorialSeries(9))  
        println(Fiborial::getFactorialSeries(11))  
        println(Fiborial::getFactorialSeries(40))  
        // Printing Fibonacci Series  
        println 
        println(Fiborial::getFibonnaciSeries(5))  
        println(Fiborial::getFibonnaciSeries(7))  
        println(Fiborial::getFibonnaciSeries(9))  
        println(Fiborial::getFibonnaciSeries(11))  
        println(Fiborial::getFibonnaciSeries(40))  
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-1idsQp6p8yw/T_oKEeu_ZkI/AAAAAAAAGj4/nj4Lcg-8x4I/s1600/FiborialSeriesXtend.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-1idsQp6p8yw/T_oKEeu_ZkI/AAAAAAAAGj4/nj4Lcg-8x4I/s1600/FiborialSeriesXtend.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, getters/setters, constructors/initializers, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series

class Fiborial {
    // Instance Field    
    var int instanceCount
    // Static Field    
    static var int staticCount
    // Instance Read-Only Getter    
    // Within instance members, you can always use      
    // the "this" reference pointer to access your (instance) members.    
    def int getInstanceCount() {    
        return this.instanceCount     
    }    
    // Static Read-Only Getter        
    // As with Static Methods, you cannot reference your class members    
    // with the "this" reference pointer since static members are not    
    // instantiated.            
    def static int getStaticCount() {    
        return staticCount
    }    
    // Instance Constructor    
    public new() {    
        this.instanceCount = 0
        println    
        println('''Instance Constructor «this.instanceCount»''')   
    }    
    // Static Constructor 
    // not supported in Xtend. Constructor cannot be static.
    // using an explicit initializer method instead    
    def static constructor() { 
        staticCount = 0
        println 
        println('''Static Constructor «staticCount»''') 
    }    
    // Instance Method    
    def void factorial(int n) {    
        this.instanceCount =  this.instanceCount + 1
        println    
        println('''Factorial(«n»)''')    
    }    
  
    // Static Method    
    def static void fibonacci(int n) {    
        staticCount = staticCount + 1
        println    
        println('''Fibonacci(«n»)''');    
    }                    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import com.series.Fiborial

class FiborialProgram {
    def static void main(String[] args) {
        // Calling Static Initializer and Methods  
        // No need to instantiate  
        Fiborial::constructor  
        Fiborial::fibonacci(5)  
      
        // Calling Instance Constructor and Methods  
        // Instance required  
        val fib = new Fiborial  
        fib.factorial(5)  
      
        Fiborial::fibonacci(15)  
        fib.factorial(5)  
      
        // Calling Instance Constructor and Methods  
        // for a second object  
        val fib2 = new Fiborial  
        fib2.factorial(5)  
      
        println
        // Calling Static Property  
        println('''Static Count = «Fiborial::getStaticCount»''')  
        // Calling Instance Property of object 1 and 2  
        println('''Instance 1 Count = «fib.getInstanceCount»''')  
        println('''Instance 2 Count = «fib2.getInstanceCount»''')          
    } 
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-bpu2oHIqpM8/T_oSHBd66BI/AAAAAAAAGkE/x0qrzvsEjTE/s1600/FiborialExtrasXtend.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-bpu2oHIqpM8/T_oSHBd66BI/AAAAAAAAGkE/x0qrzvsEjTE/s1600/FiborialExtrasXtend.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt; &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import com.series.Stopwatch
import java.math.BigInteger

class Fiborial {
    def static void main(String[] args) {
        val timer = new Stopwatch  
        var facIntResult = 0L
        var facDblResult  = 0d  
        var facBigResult = 0BI 
        var i = 5
        
        println("\nFactorial using Int64")  
        // Benchmark Factorial using Int64  
        while (i &amp;lt; 55) {  
            timer.start
            facIntResult = factorialInt64(i)  
            timer.stop  
              println(''' (Â«iÂ») = «timer.getElapsed» : «facIntResult»''')  
              i = i + 5  
        }  
        println("\nFactorial using Double")  
        // Benchmark Factorial using Double  
        i = 5  
        while (i &amp;lt; 55) {  
            timer.start  
            facDblResult = factorialDouble(i)  
            timer.stop
            println(''' («i») = «timer.getElapsed» : «facDblResult»''')  
            i = i + 5  
        }  
        println("\nFactorial using BigInteger")  
        // Benchmark Factorial using BigInteger  
        i = 5  
        while (i &amp;lt; 55) {  
            timer.start  
            facBigResult = factorialBigInteger(i)  
            timer.stop  
              println(''' («i») = «timer.getElapsed» : «facBigResult»''')  
            i = i + 5    
        }  
    }
    
    // Long Factorial    
    def static long factorialInt64(int n) {    
        if (n == 1)    
            return 1L  
        else    
            return n * factorialInt64(n - 1)  
    }  
      
    // Double Factorial
    def static double factorialDouble(int n) {    
        if (n == 1)    
            return 1d
        else    
            return n * factorialDouble(n - 1)  
    }  
      
    // BigInteger Factorial   
    def static BigInteger factorialBigInteger(int n) {    
        if (n == 1)    
            return 1BI  
        else    
            return BigInteger::valueOf(n) * factorialBigInteger(n - 1)  
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-wKUETIPr3_E/T_oW5v-jtsI/AAAAAAAAGkQ/KW7Odl7kufE/s1600/FiborialTypesXtend.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="558" src="http://4.bp.blogspot.com/-wKUETIPr3_E/T_oW5v-jtsI/AAAAAAAAGkQ/KW7Odl7kufE/s640/FiborialTypesXtend.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/W84WkloIw0U" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1462822315894633494/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/07/factorial-and-fibonacci-in-xtend.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1462822315894633494?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1462822315894633494?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/W84WkloIw0U/factorial-and-fibonacci-in-xtend.html" title="Factorial and Fibonacci in Xtend" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-REnBwOKPqN8/T_oArOTy0kI/AAAAAAAAGjs/ofWubyJmVy0/s72-c/FiborialXtend.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/07/factorial-and-fibonacci-in-xtend.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QMQXo-eSp7ImA9WhVVF0s.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-6719850344830422981</id><published>2012-05-06T12:27:00.001-07:00</published><updated>2012-05-11T13:49:40.451-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-05-11T13:49:40.451-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Xtend" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Xtend - Basics by Example</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Extending my Basics by Example series to a new language. today's version of the post written in &lt;b&gt;Xtend&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
You can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you the basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Verbose&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Xtend Basics
package com.series
import java.util.Calendar
import java.util.GregorianCalendar

public class Greet {
    // Fields or Attributes
    private String message  
    private String name
    private int loopMessage 
    // Getters and Setters. 
    // M7 will introduce annotation @Property to auto generate them (if not present)
    def public String getMessage() {  
        return this.message
    }  
    def public void setMessage(String value) {  
        this.message = this.capitalize(value)  
    }  
    def public String getName() {  
        return this.name
    }  
    def public void setName(String value) {  
        this.name = this.capitalize(value)  
    }  
    def public int getLoopMessage() {  
        return this.loopMessage  
    }  
    def public void setLoopMessage(int value) {  
        this.loopMessage = value  
    }  
    // Constructor  
    public new() {
        this.message = ""  
        this.name = ""
        this.loopMessage = 0           
    }
    // Overloaded Constructor  
    public new(String message, String name, int loopMessage) {  
        this.message = this.capitalize(message)  
        this.name = this.capitalize(name)  
        this.loopMessage = loopMessage  
    }    
    // Method 1  
    def private String capitalize(String value) {  
        // "if-then-else" statement  
        if (value.length() &amp;gt;= 1) {  
            return value.toFirstUpper()  
        }  
        else  {  
            return ""  
        }  
    }  
    // Method 2  
    def public void Salute() {  
        // "for (each)" statement
        for (int i : 0..this.loopMessage) {  
            println(this.message + " " + this.name + "!")  
        }  
    }  
    // Overloaded Method 2.1  
    def public void Salute(String message, String name, int loopMessage) {  
        // "while" statement  
        var int i = 0  
        while(i &amp;lt; loopMessage) {  
            println(this.capitalize(message) + " " + this.capitalize(name) + "!")
            i = i + 1
        }  
    }      
    // Overloaded Method 2.2  
    def public void Salute(String name) {  
        // "switch/case" statement  
        // doesn't work with iterables (i.e: case 6..11: ...)
        // doesn't allow multiple expressions in one case (i.e: case i&amp;gt;=6 &amp;amp;&amp;amp; i&amp;lt;=11: ...)
        // doesn't allow fall through (i.e: case 6: case 7: case N: ...)
        // so better to use if-else-if expression instead
        var GregorianCalendar dtNow = new GregorianCalendar()        
        val int hh = dtNow.get(Calendar::HOUR_OF_DAY) 
        if (hh &amp;gt;= 6 &amp;amp;&amp;amp; hh &amp;lt;= 11) this.message = "good morning,"        
        else if (hh &amp;gt;= 12 &amp;amp;&amp;amp; hh &amp;lt;= 17) this.message = "good afternoon,"
        else if (hh &amp;gt;= 18 &amp;amp;&amp;amp; hh &amp;lt;= 22) this.message = "good evening,"            
        else if (hh == 23 || (hh &amp;gt;= 0 &amp;amp;&amp;amp; hh &amp;lt;= 5)) this.message = "good night,"
        else this.message = "huh?"        
        println(this.capitalize(this.message) + " " + this.capitalize(name) + "!")  
    }  
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
import java.util.Scanner  
import java.lang.System 
// Greet Program
public class Program { 
    def public static void main(String[] args) {
        // Define variable object of type Greet and Instantiate. Call Constructor  
        val Greet g = new Greet()           
        // Call Setters  
        g.setMessage("hello")  
        g.setName("world")  
        g.setLoopMessage(5)  
        // Call Method 2  
        g.Salute()
        // Overloaded Method 2.1 and Getters  
        g.Salute(g.getMessage(), "xtend", g.getLoopMessage())  
        // Overloaded Method 2.2  
        g.Salute("carlos")
        
        // Stop and exit  
        println("Press any key to exit...")        
        val Scanner in = new Scanner(System::in)  
        val String line = in.nextLine()  
        in.close()                 
    }    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Minimal&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Xtend Basics
import java.util.Calendar
import java.util.GregorianCalendar

class Greet {
    // Fields or Attributes
    private String message  
    private String name
    private int loopMessage    
    // Getters and Setters. 
    // M7 will introduce annotation @Property to auto generate them (if not present)    
    def getMessage() {  
        message
    }  
    def setMessage(String value) {  
        message = capitalize(value)  
    }  
    def getName() {  
        name
    }  
    def setName(String value) {  
        name = capitalize(value)  
    }  
    def getLoopMessage() {  
        loopMessage  
    }  
    def setLoopMessage(int value) {  
        loopMessage = value  
    }  
    // Constructor  
    new() {
        message = ""  
        name = ""
        loopMessage = 0           
    }
    // Overloaded Constructor  
    new(String message, String name, int loopMessage) {  
        this.message = capitalize(message)  
        this.name = capitalize(name)  
        this.loopMessage = loopMessage  
    }    
    // Method 1  
    def private String capitalize(String value) {  
        // "if-then-else" statement  
        if (value.length &amp;gt;= 1)  
            value.toFirstUpper  
        else    
            ""  
    }  
    // Method 2  
    def Salute() {  
        // "for (each)" statement
        for (i : 0..loopMessage) {  
            println(message + " " + name + "!")  
        }  
    }  
    // Overloaded Method 2.1  
    def Salute(String message, String name, int loopMessage) {  
        // "while" statement  
        var i = 0  
        while(i &amp;lt; loopMessage) {  
            println(capitalize(message) + " " + capitalize(name) + "!")
            i = i + 1
        }  
    }      
    // Overloaded Method 2.2  
    def Salute(String name) {  
        // "switch/case" statement  
        // doesn't work with iterables (i.e: case 6..11: ...)
        // doesn't allow multiple expressions in one case (i.e: case i&amp;gt;=6 &amp;amp;&amp;amp; i&amp;lt;=11: ...)
        // doesn't allow fall through (i.e: case 6: case 7: case N: ...)
        // so better to use if-else-if expression instead
        var dtNow = new GregorianCalendar        
        val hh = dtNow.get(Calendar::HOUR_OF_DAY) 
        if (hh &amp;gt;= 6 &amp;amp;&amp;amp; hh &amp;lt;= 11) message = "good morning,"        
        else if (hh &amp;gt;= 12 &amp;amp;&amp;amp; hh &amp;lt;= 17) message = "good afternoon,"
        else if (hh &amp;gt;= 18 &amp;amp;&amp;amp; hh &amp;lt;= 22) message = "good evening,"            
        else if (hh == 23 || (hh &amp;gt;= 0 &amp;amp;&amp;amp; hh &amp;lt;= 5)) message = "good night,"
        else message = "huh?"        
        println(capitalize(message) + " " + capitalize(name) + "!")  
    }  
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;import java.util.Scanner  
// Greet Program
class Program { 
    def static main(String[] args) {
        // Define variable object of type Greet and Instantiate. Call Constructor  
        val g = new Greet           
        // Call Setters  
        g.setMessage("hello")  
        g.setName("world")  
        g.setLoopMessage(5)  
        // Call Method 2  
        g.Salute
        // Overloaded Method 2.1 and Getters  
        g.Salute(g.getMessage, "xtend", g.getLoopMessage)  
        // Overloaded Method 2.2  
        g.Salute("carlos")
        
        // Stop and exit  
        println("Press any key to exit...")        
        val in = new Scanner(System::in)  
        val line = in.nextLine  
        in.close
    }    
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-3-oX7zWQ6Zw/T6arm-jRqWI/AAAAAAAAGfA/-LHBc7JmS_o/s1600/xtend_basics_greet_output.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-3-oX7zWQ6Zw/T6arm-jRqWI/AAAAAAAAGfA/-LHBc7JmS_o/s1600/xtend_basics_greet_output.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Auto-Implemented Properties in Xtend&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Auto-implemented properties enable you to quickly specify a property of a class without having to write code to Get and Set the field. In Xtend you will use the @Property annotation which will generate a Java-Bean-style getter and setter (if the field is not final) for an annotated field and only generated when not explicitly defined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Xtend Basics  
class AutoImplementedProperties {  
    // Fields + Auto-Implemented Properties  
    @Property String message  
    @Property String name  
    @Property int loopMessage  
    // Methods  
    def salute() {    
        println('''&amp;laquo;message.toFirstUpper&amp;raquo; &amp;laquo;name.toFirstUpper&amp;raquo; &amp;laquo;loopMessage&amp;raquo;!''')
    }  
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;
class Program { 
    def static void main(String[] args) {
        var g = new AutoImplementedProperties =&amp;gt; [ 
            // Call Set Property  
            message = &amp;quot;hello&amp;quot;         
            name = &amp;quot;world&amp;quot;
            loopMessage = 5        
        ]
        // print them out  
        g.salute
        // and print them again using Get Properties  
        println('''&amp;laquo;g.message&amp;raquo; &amp;laquo;g.name&amp;raquo; &amp;laquo;g.loopMessage&amp;raquo;!''')
    }    
}
&lt;/pre&gt;
&lt;br /&gt;
And the output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-pByrv6uzP6I/T614n-N3JXI/AAAAAAAAGgA/2xRKst6X7qc/s1600/xtend_autoimplemented_props_output.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-pByrv6uzP6I/T614n-N3JXI/AAAAAAAAGgA/2xRKst6X7qc/s1600/xtend_autoimplemented_props_output.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/zxTnVFfCSC0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/6719850344830422981/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/05/xtend-basics-by-example.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/6719850344830422981?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/6719850344830422981?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/zxTnVFfCSC0/xtend-basics-by-example.html" title="Xtend - Basics by Example" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-3-oX7zWQ6Zw/T6arm-jRqWI/AAAAAAAAGfA/-LHBc7JmS_o/s72-c/xtend_basics_greet_output.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/05/xtend-basics-by-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Dk8ER3gzeyp7ImA9WhJQGEQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-3455394179034889700</id><published>2012-04-22T14:41:00.000-07:00</published><updated>2012-08-02T01:06:46.683-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-08-02T01:06:46.683-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Xtend" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>OO Hello World - Xtend</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;The OO Hello World in Xtend, the "the CoffeScript for the JVM", is here! &lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;Xtend is a statically-typed programming language which is tightly integrated with and&lt;/span&gt;&lt;br /&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;runs on the Java Virtual Machine.&lt;/span&gt;&lt;br /&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;div style="line-height: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;You can see the OO Hello World series post here:&amp;nbsp;&lt;/span&gt;&lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world.html"&gt;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&lt;/a&gt;&amp;nbsp;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;where I give some details on why these "oo hello world series" samples.&lt;/span&gt;&lt;/div&gt;
&lt;div style="line-height: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Version 1 (Minimal):&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;The minimum you need to type to get your program compiled and running.&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;/div&gt;
&lt;pre class="javascript" name="code"&gt;class Greet {
 String name
 new(String name) {
  this.name = name.toFirstUpper
 }
 def salute() {
  println("Hello " + name + "!")
 }
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;// Greet Program
class Program {
 def static void main(String[] args) {
  val g = new Greet("world")  
  g.salute
 } 
}
&lt;/pre&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Version 2 (Verbose):&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Explicitly adding instructions and keywords that are optional to the compiler.&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;/div&gt;
&lt;pre class="javascript" name="code"&gt;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 + "!")
 }
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;package com.series

// Greet Program
public class Program { 
 def public static void main(String[] args) {
  val g = new Greet("world")  
  g.salute()
 } 
}
&lt;/pre&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;The Program Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-MOlV1Xp-39c/T5RvbuAGjSI/AAAAAAAAGcI/v0tmWGDpj_4/s1600/oohello_xtend.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="78" src="http://1.bp.blogspot.com/-MOlV1Xp-39c/T5RvbuAGjSI/AAAAAAAAGcI/v0tmWGDpj_4/s320/oohello_xtend.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Xtend Info:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b style="mso-bidi-font-weight: normal;"&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
"Xtend is a statically-typed programming language developed at Eclipse.org. It&lt;br /&gt;
has a strong focus on leveraging all the good parts of Java, including seamless&lt;br /&gt;
integration with the huge amount of Java frameworks and libraries out there.” Taken from: (
&lt;a href="http://pragprog.com/magazines"&gt;Pragmatic Magazine - Issue 30, December 2011&lt;/a&gt;&amp;nbsp;)&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;
&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Appeared:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;2011&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Current Version:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;2.3 &lt;/span&gt;&lt;span style="font-family: 'Times New Roman', serif; font-size: 12pt;"&gt;&amp;nbsp;(&lt;a href="http://carlosqt.blogspot.com/p/programming-languages.html"&gt;latest version in "Languages" page&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Developed by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 12pt;"&gt;Eclipse&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Creator:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;Sven Efftinge, Sebastian Zarnekow&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 4;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Influenced by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Java (James Gosling)&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 5;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Predecessor Language&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 6;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Predecessor Appeared&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 7;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Predecessor Creator&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 8;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Runtime Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;JVM&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 9;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Latest Framework Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;JDK 6,7&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 10;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Mono Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 11;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Allows Unmanaged Code:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 12;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Source Code Extension:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;“.xtend”&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 13;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Keywords:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;41&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 14;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Case Sensitive:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 15;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Free Version Available:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 16;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Open Source:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 17;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Standard:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;N/A&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 18;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Latest IDE Support:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
Eclipse&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://www.eclipse.org/xtend/download.html"&gt;http://www.eclipse.org/xtend/download.html&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://download.eclipse.org/modeling/tmf/xtext/updates/composite/milestones/"&gt;http://download.eclipse.org/modeling/tmf/xtext/updates/composite/milestones/&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 19;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Language Reference:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://www.eclipse.org/xtend/documentation/Xtend%20User%20Guide.pdf"&gt;http://www.eclipse.org/xtend/documentation/Xtend%20User%20Guide.pdf&lt;/a&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 20; mso-yfti-lastrow: yes;"&gt;&lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Extra Info:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://eclipse.org/projects/project.php?id=tools.xtend"&gt;http://eclipse.org/projects/project.php?id=tools.xtend&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://en.wikipedia.org/wiki/Xtend_(programming_language)"&gt;http://en.wikipedia.org/wiki/Xtend_(programming_language)&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="MsoNormal" style="line-height: 19.2pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/riGCIpj-tGw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/3455394179034889700/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/04/oo-hello-world-xtend.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/3455394179034889700?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/3455394179034889700?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/riGCIpj-tGw/oo-hello-world-xtend.html" title="OO Hello World - Xtend" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-MOlV1Xp-39c/T5RvbuAGjSI/AAAAAAAAGcI/v0tmWGDpj_4/s72-c/oohello_xtend.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/04/oo-hello-world-xtend.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUYMRH89eyp7ImA9WhJRFkQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1300670284525022713</id><published>2012-04-18T07:05:00.000-07:00</published><updated>2012-07-19T03:19:45.163-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-07-19T03:19:45.163-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Kotlin" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Kotlin</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Kotlin that implements 2 classes (+ an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one is the main function which has the execution entry point.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members (or 2 separate classes in the case of Kotlin since it does not supports staitc methods in a class), and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Factorial and Fibonacci in Kotlin
package com.series

import java.math.BigInteger
import com.series.Stopwatch

// Instance (Singleton) Class that works as a Module/Utils class
// static is not a class modifier in Kotlin
object StaticFiborial {
    // 'Static' Field
    private var className : String = "'Static' Constructor"
    // no available static __constructor support
    // Static Initializer Method instead, but need to be explicitly invoked
    fun constructor() {
        className = "'Static' Constructor";
        println(className)
    }
    // 'Static' Method - Factorial Recursive
    fun factorialR(n : Int) : BigInteger? {
        if (n == 1)
            return BigInteger.ONE
        else
            return BigInteger.valueOf(n.toLong())?.multiply(factorialR(n - 1))
    }
    // 'Static' Method - Factorial Imperative
    fun factorialI(var n : Int) : BigInteger? {
        var res: BigInteger? = BigInteger.ONE
        while (n &amp;gt; 1) {
            res = res?.multiply(BigInteger.valueOf(n.toLong()))
            n -= 1
        }
        return res
    }
    // 'Static' Method - Fibonacci Recursive
    fun fibonacciR(n : Int) : Long {
        if (n &amp;lt; 2)
            return 1
        else
            return fibonacciR(n - 1) + fibonacciR(n - 2)
    }
    // 'Static' Method - Fibonacci Imperative
    fun fibonacciI(n : Int) : Long {
        var pre : Long = 1
        var cur : Long = 1
        var tmp : Long
        for (i in 2..n) {
            tmp = cur + pre
            pre = cur
            cur = tmp
        }
        return cur
    }
    // 'Static' Method - Benchmarking Algorithms
    fun benchmarkAlgorithm(algorithm : Int, values : Array&amp;lt;Int&amp;gt;) {
        val timer : Stopwatch = Stopwatch()
        var testValue : Int
        var i : Int = 1
        var facTimeResult : BigInteger? = BigInteger.ZERO
        var fibTimeResult : Long

        when (algorithm) {
            1 -&amp;gt; {
                println("\nFactorial Imperative:");
                // "For" Loop Statement
                for (j in 1..values.size - 1) {
                    testValue = values[j]
                    // Taking Time
                    timer.start()
                    facTimeResult = factorialI(testValue)
                    timer.stop()
                    // Getting Time
                    println(" (${testValue}) = ${timer.getElapsed()}")
                }
            }
            2 -&amp;gt; {
                println("\nFactorial Recursive:")
                // "While" Loop Statement
                while (i &amp;lt; values.size) {
                    testValue = values[i]
                    // Taking Time
                    timer.start()
                    facTimeResult = factorialR(testValue)
                    timer.stop()
                    // Getting Time
                    println(" (${testValue}) = ${timer.getElapsed()}")
                    i += 1
                }
            }
            3 -&amp;gt; {
                println("\nFibonacci Imperative:")
                // "Do-While" Loop Statement
                do {
                    testValue = values[i]
                    // Taking Time
                    timer.start()
                    fibTimeResult = fibonacciI(testValue)
                    timer.stop()
                    // Getting Time
                    println(" (${testValue}) = ${timer.getElapsed()}")
                    i++
                } while (i &amp;lt; values.size)
            }
            4 -&amp;gt; {
                println("\nFibonacci Recursive:")
                // "For Each" Loop Statement
                for (j in values) {
                    testValue = j
                    // Taking Time
                    timer.start()
                    fibTimeResult = fibonacciR(testValue)
                    timer.stop()
                    // Getting Time
                    println(" (${testValue}) = ${timer.getElapsed()}")
                }
            }
            else -&amp;gt; println("DONG!")
        }
    }
}

// Instance Class
// Instance Field
class InstanceFiborial(private var className : String) {
    // Instance Constructor
    this() : this("Instance Constructor") {
        println(this.className)
    }
    // Instance Method - Factorial Recursive
    fun factorialR(n : Int) : BigInteger? {
        // Calling Static Method
        return StaticFiborial.factorialR(n)
    }
    // Instance Method - Factorial Imperative
    fun factorialI(n : Int) : BigInteger? {
        // Calling Static Method
        return StaticFiborial.factorialI(n)
    }
    // Instance Method - Fibonacci Recursive
    fun fibonacciR(n : Int) : Long {
        // Calling Static Method
        return StaticFiborial.fibonacciR(n)
    }
    // Instance Method - Fibonacci Imperative
    fun fibonacciI(n : Int) : Long {
        // Calling Static Method
        return StaticFiborial.fibonacciI(n)
    }
}

fun main(args: Array&amp;lt;String&amp;gt;) {
    println("\n'Static' Class");
    // Calling 'Static' Class and Methods
    // No instantiation needed. Calling method directly from the class
    StaticFiborial.constructor()
    println("FacImp(5) = ${StaticFiborial.factorialI(5)}")
    println("FacRec(5) = ${StaticFiborial.factorialR(5)}")
    println("FibImp(11)= ${StaticFiborial.fibonacciI(11)}")
    println("FibRec(11)= ${StaticFiborial.fibonacciR(11)}")

    println("\nInstance Class");
    // Calling Instance Class and Methods
    // Need to instantiate before using. Call method from instantiated object
    val ff = InstanceFiborial()
    println("FacImp(5) = ${ff.factorialI(5)}")
    println("FacRec(5) = ${ff.factorialR(5)}")
    println("FibImp(11)= ${ff.fibonacciI(11)}")
    println("FibRec(11)= ${ff.fibonacciR(11)}")

    // Create a (generic) list of integer values to test
    // From 5 to 50 by 5
    val values = Array&amp;lt;Int&amp;gt;(11, {i -&amp;gt; i * 5})

    // Benchmarking Fibonacci
    // 1 = Factorial Imperative
    StaticFiborial.benchmarkAlgorithm(1, values)
    // 2 = Factorial Recursive
    StaticFiborial.benchmarkAlgorithm(2, values)

    // Benchmarking Factorial
    // 3 = Fibonacci Imperative
    StaticFiborial.benchmarkAlgorithm(3, values)
    // 4 = Fibonacci Recursive
    StaticFiborial.benchmarkAlgorithm(4, values)

    // Stop and exit
    println("Press any key to exit...")
    //val ins: Scanner = Scanner(System.in)
    //var line: String? = ins.nextLine()
    //ins.close()
}&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-YSOg-xoMvgA/T46LuRCY8wI/AAAAAAAAGas/2ebIqs0d2ME/s1600/FiborialKt.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-YSOg-xoMvgA/T46LuRCY8wI/AAAAAAAAGas/2ebIqs0d2ME/s1600/FiborialKt.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series

import java.math.BigInteger
import java.lang.StringBuffer

object Fiborial {
    // Using a StringBuffer as a list of string elements
    fun getFactorialSeries(n : Int) : String? {
        val series = StringBuffer()
        // We begin by concatenating the number you want to calculate
        // in the following format: "!# ="
        series.append("!")
        series.append(n)
        series.append(" = ")
        // We iterate backwards through the elements of the series
        // Reversed ranges are not supported... using while instead
        //for (i in n..0) {
        var i : Int = n
        while (i &amp;gt; 0) {
            // and append it to the list
            series.append(i)
            if (i &amp;gt; 1)
                series.append(" * ")
            else
                series.append(" = ")
            i--
        }
        // Get the result from the Factorial Method
        // and append it to the end of the list
        series.append(factorial(n))
        return series.toString()
    }

    // Using a StringBuffer as a list of string elements
    fun getFibonnaciSeries(n : Int) : String? {
        // Create the String that will hold the list
        val series = StringBuffer()
        // We begin by concatenating the first 3 values which
        // are always constant
        series.append("0, 1, 1")
        // Then we calculate the Fibonacci of each element
        // and add append it to the list
        for (i in 2..n) {
            if (i &amp;lt; n)
                series.append(", ")
            else
                series.append(" = ")
            series.append(fibonacci(i))
        }
        // return the list as a string
        return series.toString()
    }

    fun factorial(n : Int) : BigInteger? {
        if (n == 1)
            return BigInteger.ONE
        else
            return BigInteger.valueOf(n.toLong())?.multiply(factorial(n - 1))
    }

    fun fibonacci(n : Int) : Long {
        if (n &amp;lt; 2)
            return 1
        else
            return fibonacci(n - 1) + fibonacci(n - 2)
    }
}

fun main(args : Array&amp;lt;String&amp;gt;) {
    // Printing Factorial Series
    println("")
    println(Fiborial.getFactorialSeries(5))
    println(Fiborial.getFactorialSeries(7))
    println(Fiborial.getFactorialSeries(9))
    println(Fiborial.getFactorialSeries(11))
    println(Fiborial.getFactorialSeries(40))
    // Printing Fibonacci Series
    println("")
    println(Fiborial.getFibonnaciSeries(5))
    println(Fiborial.getFibonnaciSeries(7))
    println(Fiborial.getFibonnaciSeries(9))
    println(Fiborial.getFibonnaciSeries(11))
    println(Fiborial.getFibonnaciSeries(40))
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:








&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-sB7qA3LvLio/T46WVe_D-PI/AAAAAAAAGa0/5OKbUg3zuYE/s1600/FiborialSeriesKt.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="372" src="http://2.bp.blogspot.com/-sB7qA3LvLio/T46WVe_D-PI/AAAAAAAAGa0/5OKbUg3zuYE/s640/FiborialSeriesKt.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Normally, instance classes can contain both, instance and static members such as: fields, getters, constructors/initializers, methods, etc. However, In Kotlin, unlike Java, classes do not have static methods, so it doesn't support mixing both of them on the same object or class.

In the following code I had to create one Object and one Class to build this example. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series

// 'Static' Class
object StaticFiborial {
    // 'Static' Field/Property
    private var _staticCount : Int = 0
    // 'Static' Read-Only Property
    public val StaticCount : Int
        get() {
            return _staticCount
        }
    // 'Static' Constructor
    //this() : this() {
    // No constructor support for Objects - failed to get descriptor for secondary constructor
    // using an explicit initializer method instead
    fun constructor() {
        println("\nStatic Constructor ${_staticCount}")
    }
    // 'Static' Method
    fun fibonacci(n : Int) {
        _staticCount += 1
        println("\nFibonacci(${n})")
    }
}

// Instance Class
// Instance Field/Property
class InstanceFiborial(private var _instanceCount : Int) {
    // Instance Read-Only Property
    public val InstanceCount : Int
        get() {
            return this._instanceCount
        }
    // Instance Constructor
    this() : this(0) {
        println("\nInstance Constructor ${this._instanceCount}")
    }
    // Instance Method
    fun factorial(n : Int) {
        this._instanceCount += 1
        println("\nFactorial(${n})")
    }
}

fun main(args : Array&amp;lt;String&amp;gt;) {
    // Calling Static Constructor and Methods
    // No need to instantiate
    StaticFiborial.constructor()
    StaticFiborial.fibonacci(5)

    // Calling Instance Constructor and Methods
    // Instance required
    val fib = InstanceFiborial()
    fib.factorial(5)

    StaticFiborial.fibonacci(15)
    fib.factorial(5)

    // Calling Instance Constructor and Methods
    // for a second object
    val fib2 = InstanceFiborial()
    fib2.factorial(5)

    println("")
    // Calling Static Property
    println("Static Count = ${StaticFiborial.StaticCount}")
    // Calling Instance Property of object 1 and 2
    println("Instance 1 Count = ${fib.InstanceCount}")
    println("Instance 2 Count = ${fib2.InstanceCount}")
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-7qus8UJgcgI/T463GTbzskI/AAAAAAAAGa8/wlw_il2W1VI/s1600/FiborialExtrasKt.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-7qus8UJgcgI/T463GTbzskI/AAAAAAAAGa8/wlw_il2W1VI/s1600/FiborialExtrasKt.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series

import java.math.BigInteger
import com.series.Stopwatch

// Long Factorial
fun factorialInt64(n : Int) : Long {
    if (n == 1)
        return 1
    else
        return n * factorialInt64(n - 1)
}

// Double Factorial
fun factorialDouble(n : Int) : Double {
    if (n == 1)
        return 1.0
    else
        return n * factorialDouble(n - 1)
}

// BigInteger Factorial
fun factorialBigInteger(n : Int) : BigInteger? {
    if (n == 1)
        return BigInteger.ONE
    else
        return BigInteger.valueOf(n.toLong())?.multiply(factorialBigInteger(n - 1))
}

fun main(args: Array&amp;lt;String&amp;gt;) {
    val timer = Stopwatch()
    var facIntResult : Long = 0
    var facDblResult : Double = 0.0
    var facBigResult = BigInteger.ZERO

    println("\nFactorial using Int64")
    // Benchmark Factorial using Int64
    var i = 5
    while (i &amp;lt; 55) {
        timer.start()
        facIntResult = factorialInt64(i)
        timer.stop()
        println(" (${i}) = ${timer.getElapsed()} : ${facIntResult}")
        i += 5
    }
    println("\nFactorial using Double")
    // Benchmark Factorial using Double
    i = 5
    while (i &amp;lt; 55) {
        timer.start()
        facDblResult = factorialDouble(i)
        timer.stop()
        println(" (${i}) = ${timer.getElapsed()} : ${facDblResult}")
        i += 5
    }
    println("\nFactorial using BigInteger")
    // Benchmark Factorial using BigInteger
    i = 5
    while (i &amp;lt; 55) {
        timer.start()
        facBigResult = factorialBigInteger(i)
        timer.stop()
        println(" (${i}) = ${timer.getElapsed()} : ${facBigResult}")
        i += 5
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-2bBXlvHaaNU/T465XVrqJZI/AAAAAAAAGbE/nv9y-ZDv0C4/s1600/FiborialTypesKt.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="581" src="http://2.bp.blogspot.com/-2bBXlvHaaNU/T465XVrqJZI/AAAAAAAAGbE/nv9y-ZDv0C4/s640/FiborialTypesKt.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/0KrM1_CWgFU" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1300670284525022713/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/04/factorial-and-fibonacci-in-kotlin.html#comment-form" title="3 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1300670284525022713?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1300670284525022713?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/0KrM1_CWgFU/factorial-and-fibonacci-in-kotlin.html" title="Factorial and Fibonacci in Kotlin" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-YSOg-xoMvgA/T46LuRCY8wI/AAAAAAAAGas/2ebIqs0d2ME/s72-c/FiborialKt.png" height="72" width="72" /><thr:total>3</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/04/factorial-and-fibonacci-in-kotlin.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4DSX0zfCp7ImA9WhVXFkQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2066642672004153699</id><published>2012-04-14T11:04:00.001-07:00</published><updated>2012-04-17T13:02:58.384-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-17T13:02:58.384-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Kotlin" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Kotlin - Basics by Example</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Extending my Basics by Example series to a new language :D. today's version of the post written in &lt;b&gt;Kotlin&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
You can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you the basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Verbose&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Kotlin Basics
package com.series.basics

import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Scanner
import java.lang.System

// (Main) Constructor
public class Greet() {
    // Fields or Attributes are Properties
    private var _message: String = &amp;quot;&amp;quot;
    private var _name: String = &amp;quot;&amp;quot;
    private var _loopMessage: Int = 0
    // Properties
    public var Message : String
        get() {
            return this._message
        }
        set(value) {
            this._message = this.Capitalize(value)
        }
    public var Name : String
        get() {
            return this._name
        }
        set(value) {
            this._name = this.Capitalize(value)
        }
    public var LoopMessage : Int
        get() {
            return this._loopMessage
        }
        set(value) {
            this._loopMessage = value
        }
    // Overloaded/Secondary Constructor
    public this(val message: String, val name: String, val loopMessage: Int) : this() {
        this._message = message
        this._name = name
        this._loopMessage = loopMessage
    }
    // Method 1
    private fun Capitalize(val value: String) : String {
        // &amp;quot;if-then-else&amp;quot; statement
        if (value.length &amp;gt; 0)
            return value[0].toString().toUpperCase() + value.substring(1,value.length)
        else
            return &amp;quot;&amp;quot;
    }
    // Method 2
    public fun Salute() {
        // &amp;quot;for&amp;quot; statement
        for(i in 1..this._loopMessage) {
            println(&amp;quot;${this._message} ${this._name}!&amp;quot;)
        }
    }
    // Overloaded Method
    // No Overloaded Methods Support. New methods instead.
    // Method 2.1
    public fun Salute21(val message: String, val name: String, val loopMessage: Int) {
        // &amp;quot;while&amp;quot; statement
        var i: Int = 1
        while (i &amp;lt;= loopMessage) {
            println(&amp;quot;${this.Capitalize(message)} ${this.Capitalize(name)}!&amp;quot;)
            i++
        }
    }
    // Overloaded Method
    // No Overloaded Methods Support. New methods instead.
    // Method 2.2
    public fun Salute22(val name: String) {
        // &amp;quot;switch/case&amp;quot; statement is not supported
        // using match statement instead
        val dtNow: Calendar? = Calendar.getInstance()
        val t: Int? = dtNow?.get(Calendar.HOUR_OF_DAY)
        when (t) {
            6,7,8,9,10,11 -&amp;gt; this._message = &amp;quot;good morning,&amp;quot;
            12,13,14,15,16,17 -&amp;gt; this._message = &amp;quot;good afternoon,&amp;quot;
            18,19,20,21,22 -&amp;gt; this._message = &amp;quot;good evening,&amp;quot;
            23,0,1,2,3,4,5 -&amp;gt; this._message = &amp;quot;good night,&amp;quot;
            else -&amp;gt; this._message = &amp;quot;huh?&amp;quot;
        }
        println(&amp;quot;${this.Capitalize(this._message)} ${this.Capitalize(name)}!&amp;quot;)
    }
}

// Console Program
public fun main(val args: Array&amp;lt;String&amp;gt;) {
    // Define object of type Greet and Instantiate Greet. Call Constructor
    val g:Greet = Greet()
    // Call Set Properties
    g.Message = &amp;quot;hello&amp;quot;
    g.Name = &amp;quot;world&amp;quot;
    g.LoopMessage = 5
    // Call Method 2
    g.Salute()
    // Call Overloaded Method 2.1 and Get Properties
    g.Salute21(g.Message, &amp;quot;kotlin&amp;quot;, g.LoopMessage)
    // Call Overloaded Method 2.2
    g.Salute22(&amp;quot;carlos&amp;quot;)
    // Stop and exit
    println(&amp;quot;Press any key to exit...&amp;quot;)
    // following code not working due to 'System.in' being considered as 'in' language keyword
    // Error message: Expecting an element
    //val ins: Scanner = Scanner(System.in)
    //var line: String? = ins.nextLine()
    //ins.close()
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Greetings Program - Minimal&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Kotlin Basics
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Scanner
import java.lang.System

// (Main) Constructor
class Greet() {
    // Fields or Attributes are Properties
    private var _message: String = ""
    private var _name: String = ""
    private var _loopMessage: Int = 0
    // Properties
    var Message : String
        get() {
            return _message
        }
        set(value) {
            _message = Capitalize(value)
        }
    var Name : String
        get() {
            return _name
        }
        set(value) {
            _name = Capitalize(value)
        }
    var LoopMessage : Int
        get() {
            return _loopMessage
        }
        set(value) {
            _loopMessage = value
        }
    // Overloaded/Secondary Constructor
    this(message: String, name: String, loopMessage: Int) : this() {
        _message = message
        _name = name
        _loopMessage = loopMessage
    }
    // Method 1
    private fun Capitalize(value: String) : String {
        // "if-then-else" statement
        if (value.length &amp;gt; 0)
            return value[0].toString().toUpperCase() + value.substring(1,value.length)
        else
            return ""
    }
    // Method 2
    fun Salute() {
        // "for" statement
        for(i in 1.._loopMessage) {
            println("${_message} ${_name}!")
        }
    }
    // Overloaded Method
    // No Overloaded Methods Support. New methods instead.
    // Method 2.1
    fun Salute21(message: String, name: String, loopMessage: Int) {
        // "while" statement
        var i = 1
        while (i &amp;lt;= loopMessage) {
            println("${Capitalize(message)} ${Capitalize(name)}!")
            i++
        }
    }
    // Overloaded Method
    // No Overloaded Methods Support. New methods instead.
    // Method 2.2
    fun Salute22(name: String) {
        // "switch/case" statement is not supported
        // using match statement instead
        val dtNow = Calendar.getInstance()
        val t = dtNow?.get(Calendar.HOUR_OF_DAY)
        when (t) {
            6,7,8,9,10,11 -&amp;gt; _message = "good morning,"
            12,13,14,15,16,17 -&amp;gt; _message = "good afternoon,"
            18,19,20,21,22 -&amp;gt; _message = "good evening,"
            23,0,1,2,3,4,5 -&amp;gt; _message = "good night,"
            else -&amp;gt; _message = "huh?"
        }
        println("${Capitalize(_message)} ${Capitalize(name)}!")
    }
}

// Console Program
fun main(args: Array&amp;lt;String&amp;gt;) {
    // Define object of type Greet and Instantiate Greet. Call Constructor
    val g = Greet()
    // Call Set Properties
    g.Message = "hello"
    g.Name = "world"
    g.LoopMessage = 5
    // Call Method 2
    g.Salute()
    // Call Overloaded Method 2.1 and Get Properties
    g.Salute21(g.Message, "kotlin", g.LoopMessage)
    // Call Overloaded Method 2.2
    g.Salute22("carlos")
    // Stop and exit
    println("Press any key to exit...")
    // following code not working due to 'System.in' being considered as 'in' keyword
    // Error message: Expecting an element
    //val ins: Scanner = Scanner(System.in)
    //var line: String? = ins.nextLine()
    //ins.close()
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-m3BFkYheiSk/T4m2PXXw1zI/AAAAAAAAGZo/GpLU5LXS9BM/s1600/kotlin_basics_greet_output.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="366" src="http://2.bp.blogspot.com/-m3BFkYheiSk/T4m2PXXw1zI/AAAAAAAAGZo/GpLU5LXS9BM/s640/kotlin_basics_greet_output.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Auto-Implemented Properties in Kotlin&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Auto-implemented properties enable you to quickly specify a property of a class without having to write code to Get and Set the property. In Kotlin, there's no way to declare a field. All you have is properties. Read/write properties are declared with the var keyword, and read-only ones – with val keyword.
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Kotlin Basics
class AutoImplementedProperties() {
    // Fields or Attributes are Properties
    var Message: String = ""
    var Name: String = ""
    var LoopMessage: Int = 0
    // Methods
    fun Salute() {
        println("${Message} ${Name} ${LoopMessage}!")
    }
}

// parameters of main constructor become properties of the class
class MainConstructorProperties(var Message: String, var Name: String, var LoopMessage: Int) {
    // Methods
    fun Salute() {
        println("${Message} ${Name} ${LoopMessage}!")
    }
}
// if you want private properties for the ones sent to the main constructor
// use the private modifier before each var/val declaration
/*class PropertiesFromConstructorParams(private var Message: String
                                      , private var Name: String
                                      , private var LoopMessage: Int) {
    // pass
}
*/

fun main(args: Array&amp;lt;String&amp;gt;) {
    val g = AutoImplementedProperties()
    // Call Set Properties
    g.Message = "hello"
    g.Name = "world"
    g.LoopMessage = 5
    // print them out
    g.Salute()
    // and print them again using Get Properties
    println("${g.Message} ${g.Name} ${g.LoopMessage}!")

    println()

    val p = MainConstructorProperties("bye","carlos",1)
    p.Salute()
    // Call Set Properties
    p.Message = "hello"
    p.Name = "world"
    p.LoopMessage = 5
    // print them out
    p.Salute()
    // and print them again using Get Properties
    println("${p.Message} ${p.Name} ${p.LoopMessage}!")

}&lt;/pre&gt;
&lt;br /&gt;
And the output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-iXfQASLBQyg/T4m7pG0BR2I/AAAAAAAAGZw/_wu9I1_69VM/s1600/kotlin_basics_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="208" src="http://2.bp.blogspot.com/-iXfQASLBQyg/T4m7pG0BR2I/AAAAAAAAGZw/_wu9I1_69VM/s400/kotlin_basics_properties.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/mQxv06mN23w" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2066642672004153699/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/04/kotlin-basics-by-example.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2066642672004153699?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2066642672004153699?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/mQxv06mN23w/kotlin-basics-by-example.html" title="Kotlin - Basics by Example" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-m3BFkYheiSk/T4m2PXXw1zI/AAAAAAAAGZo/GpLU5LXS9BM/s72-c/kotlin_basics_greet_output.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/04/kotlin-basics-by-example.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE4GRnk8eCp7ImA9WhVSGEQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-8794187794036166539</id><published>2012-02-25T15:09:00.001-08:00</published><updated>2012-03-16T03:15:27.770-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-16T03:15:27.770-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Kotlin" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>OO Hello World - Kotlin</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;The OO Hello World in Kotlin, the "the new language from JetBrains for the JVM", is here! &lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Project Kotlin is a codename for a statically typed programming language compiled to JVM byte code and JavaScript.&lt;/span&gt;&lt;br /&gt;
&lt;div style="line-height: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;You can see the OO Hello World series post here:&amp;nbsp;&lt;/span&gt;&lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world.html"&gt;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&lt;/a&gt;&amp;nbsp;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;where I give some details on why these "oo hello world series" samples.&lt;/span&gt;&lt;/div&gt;
&lt;div style="line-height: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Version 1 (Minimal):&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;The minimum you need to type to get your program compiled and running.&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;/div&gt;
&lt;pre class="scala" name="code"&gt;class Greet(name : String) {
  val name : String = name[0].toString().toUpperCase() + name.substring(1, name.length);
  fun salute() {
    println("Hello, ${name}!");
  }
}

// Greet the world!
fun main(args : Array&amp;lt;string&amp;gt;) {
  val g = Greet("carlos");
  g.salute();
}
&lt;/pre&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Version 2 (Verbose):&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Explicitly adding instructions and keywords that are optional to the compiler.&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;/div&gt;
&lt;pre class="scala" name="code"&gt;package greetprogram;

public class Greet(name : String) {
  private val name : String = name[0].toString().toUpperCase() + name.substring(1, name.length);
  public fun salute() {
    println("Hello, ${this.name}!");
  }
}

public fun main(args : Array&amp;lt;string&amp;gt;) {
  val g = Greet("carlos");
  g.salute();
}
&lt;/pre&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;The Program Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-CKYMOweu6ek/T0lmlXVhLuI/AAAAAAAAGPw/9SFsYiRoAtk/s1600/kotlin_oohello_output.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-CKYMOweu6ek/T0lmlXVhLuI/AAAAAAAAGPw/9SFsYiRoAtk/s1600/kotlin_oohello_output.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;b&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Kotlin Info:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b style="mso-bidi-font-weight: normal;"&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
""Project Kotlin" is the codename of a statically-typed JVM-targeted programming language developed by JetBrains intended for industrial use. This is an object-oriented language” Taken from: (
&lt;a href="http://confluence.jetbrains.net/display/Kotlin/Welcome"&gt;http://confluence.jetbrains.net/display/Kotlin/Welcome&lt;/a&gt;&amp;nbsp;)&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;
&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Appeared:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;2011&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Current Version:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;0.1&lt;/span&gt;&lt;span style="font-family: &amp;quot;Times New Roman&amp;quot;, serif; font-size: 12pt;"&gt;&amp;nbsp;(&lt;a href="http://carlosqt.blogspot.com/p/programming-languages.html"&gt;latest version in "Languages" page&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Developed by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;JetBrains&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Creator:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;Andrey Breslav&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 4;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Influenced by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Groovy (&lt;/span&gt;&lt;span style="background-color: white; color: #333333; font-family: serif, serif; font-size: 16px; text-align: left;"&gt;Guillaume Laforge&lt;/span&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;), C# (&lt;/span&gt;&lt;span style="background-color: white; color: #333333; font-family: &amp;quot;Times New Roman&amp;quot;, serif; font-size: 16px; text-align: left;"&gt;Anders Hejlsberg&lt;/span&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;)&lt;/span&gt;
&lt;br /&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Java (James Gosling), Scala (&lt;/span&gt;&lt;span style="background-color: white; color: #333333; font-family: serif, serif; font-size: 16px; text-align: left;"&gt;Martin Odersky&lt;/span&gt;&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 5;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Predecessor Language&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 6;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Predecessor Appeared&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 7;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Predecessor Creator&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 8;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Runtime Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;JVM&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 9;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Latest Framework Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;JDK 6&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 10;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Mono Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 11;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Allows Unmanaged Code:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 12;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Source Code Extension:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;“.kt”&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 13;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Keywords:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;31&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 14;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Case Sensitive:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 15;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Free Version Available:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 16;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Open Source:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 17;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Standard:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;N/A&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 18;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Latest IDE Support:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
Intellij IDEA&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;a href="https://github.com/JetBrains/kotlin/downloads"&gt;https://github.com/JetBrains/kotlin/downloads&lt;/a&gt;
&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 19;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Language Reference:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://confluence.jetbrains.net/display/Kotlin/Docs+Home"&gt;http://confluence.jetbrains.net/display/Kotlin/Docs+Home&lt;/a&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 20; mso-yfti-lastrow: yes;"&gt;&lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: &amp;quot;&amp;quot;, serif, &amp;quot;&amp;quot;, serif; font-size: 12pt;"&gt;Extra Info:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://blog.jetbrains.com/kotlin/"&gt;http://blog.jetbrains.com/kotlin/&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://kotlin-demo.jetbrains.com/"&gt;http://kotlin-demo.jetbrains.com/&lt;/a&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="MsoNormal" style="line-height: 19.2pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/WLTbeFk0BWw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/8794187794036166539/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/02/oo-hello-world-kotlin.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/8794187794036166539?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/8794187794036166539?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/WLTbeFk0BWw/oo-hello-world-kotlin.html" title="OO Hello World - Kotlin" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-CKYMOweu6ek/T0lmlXVhLuI/AAAAAAAAGPw/9SFsYiRoAtk/s72-c/kotlin_oohello_output.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/02/oo-hello-world-kotlin.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEUHR3k-fip7ImA9WhBWEkg.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7741628346336890401</id><published>2012-02-25T13:42:00.000-08:00</published><updated>2013-04-06T06:50:36.756-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-06T06:50:36.756-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Ceylon" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>OO Hello World - Ceylon</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update 1:&lt;/b&gt; Porting code examples to Ceylon M5 - syntax changes on assignent operator, module definition and support for String Interpolation. 
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;The OO Hello World in Ceylon, the "the new language from Red Hat for the JVM", is here! &lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Ceylon is a general-purpose, imperative, statically-typed, block-structured, object-oriented, higher-order language featuring a syntax similar to Java and C#, and a type system based on the notion of principal types.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;You can see the OO Hello World series post here:&amp;nbsp;&lt;/span&gt;&lt;a href="http://carlosqt.blogspot.com/2010/06/oo-hello-world.html"&gt;http://carlosqt.blogspot.com/2010/06/oo-hello-world.html&lt;/a&gt;&amp;nbsp;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;where I give some details on why these "oo hello world series" samples.&lt;/span&gt;&lt;/div&gt;
&lt;div style="line-height: normal;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Version 1 (Minimal):&lt;/span&gt;&lt;/b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;The minimum you need to type to get your program compiled and running.&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;/div&gt;
&lt;pre class="csharp" name="code"&gt;
class Greet(String name) {   
    String _name = name[0..0].uppercased + name[1...];  
    shared void salute() {  
        print("Hello, ``_name``!");  
    }
} 
  
// Greet the world!  
void run() {  
    value g = Greet("carlos");  
    g.salute();  
}  
&lt;/pre&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Version 2 (Verbose):&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Explicitly adding instructions and keywords that are optional to the compiler.&lt;/span&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;/div&gt;
&lt;pre class="csharp" name="code"&gt;
shared class Greet(String name) {   
    variable String _name = name[0..0].uppercased + name[1...];  
    shared void salute() {  
        print("Hello, ``this._name``!");  
    }  
}  
  
// Greet the world!  
shared void run() {  
    value g = Greet("carlos");  
    g.salute();  
} 
&lt;/pre&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;The Program Output:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-hrK_zQzJOpk/T0lTmHeb6BI/AAAAAAAAGPo/9UV22_PQgdk/s1600/ceylon_oohello_output.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-hrK_zQzJOpk/T0lTmHeb6BI/AAAAAAAAGPo/9UV22_PQgdk/s1600/ceylon_oohello_output.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;b style="mso-bidi-font-weight: normal;"&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Ceylon Info:&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style="mso-bidi-font-weight: normal;"&gt;&lt;u&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/u&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
“Ceylon is a programming language for writing large programs in a team environment. The language is elegant, highly readable, extremely typesafe, and makes it easy to get things done. And it's easy to learn for programmers who are familiar with mainstream languages used in business computing. Ceylon has a full-featured Eclipse-based development environment, allowing developers to take best advantage of the powerful static type system. Programs written in Ceylon execute on any JVM.” Taken from: (&lt;a href="http://www.ceylon-lang.org/"&gt;http://www.ceylon-lang.org/&lt;/a&gt;&amp;nbsp;)&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; border: none; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;"&gt;&lt;tbody&gt;
&lt;tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;"&gt;   &lt;td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Appeared:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;2011&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 1;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Current Version:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;0.1 M1&lt;/span&gt;&lt;span style="font-family: 'Times New Roman', serif; font-size: 12pt;"&gt;&amp;nbsp;(&lt;a href="http://carlosqt.blogspot.com/p/programming-languages.html"&gt;latest version in "Languages" page&lt;/a&gt;)&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 2;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Developed by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Red Hat&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 3;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Creator:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Gavin King&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 4;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Influenced by:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Java (James Gosling), C# (&lt;/span&gt;&lt;span style="background-color: white; color: #333333; font-family: 'Times New Roman', serif; font-size: 16px; text-align: left;"&gt;Anders Hejlsberg&lt;/span&gt;&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 5;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Predecessor Language&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 6;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Predecessor Appeared&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 7;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Predecessor Creator&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif;"&gt;N/A&lt;/span&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 8;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Runtime Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;JVM&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 9;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Latest Framework Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;JDK 6&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 10;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Mono Target:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 11;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Allows Unmanaged Code:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;No&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 12;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Source Code Extension:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;“.ceylon”&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 13;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Keywords:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: serif, serif; font-size: 16px;"&gt;35&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 14;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Case Sensitive:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 15;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Free Version Available:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 16;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Open Source:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Yes&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 17;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Standard:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;N/A&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 18;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Latest IDE Support:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
Eclipse&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://www.eclipse.org/downloads/"&gt;http://www.eclipse.org/downloads/&lt;/a&gt;&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 19;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Language Reference:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://www.ceylon-lang.org/documentation/reference/#tools"&gt;http://www.ceylon-lang.org/documentation/reference/&lt;/a&gt;&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;tr style="mso-yfti-irow: 20; mso-yfti-lastrow: yes;"&gt;   &lt;td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 170.6pt;" valign="top" width="227"&gt;&lt;div class="MsoNormal" style="line-height: normal; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;span style="color: #333333; font-family: '', serif, '', serif; font-size: 12pt;"&gt;Extra Info:&lt;/span&gt;&lt;/div&gt;
&lt;/td&gt;   &lt;td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt 0in 5.4pt; width: 351.0pt;" valign="top" width="468"&gt;&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://en.wikipedia.org/wiki/Ceylon_Project"&gt;http://en.wikipedia.org/wiki/Ceylon_Project&lt;/a&gt;
&lt;/div&gt;
&lt;div class="MsoNoSpacing"&gt;
&lt;a href="http://www.ceylon-lang.org/documentation/"&gt;http://www.ceylon-lang.org/documentation/&lt;/a&gt;
&lt;/div&gt;
&lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;div class="MsoNormal" style="line-height: 19.2pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class="MsoNormal"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/0JU0e9RAMMQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7741628346336890401/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/02/oo-hello-world-ceylon.html#comment-form" title="5 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7741628346336890401?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7741628346336890401?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/0JU0e9RAMMQ/oo-hello-world-ceylon.html" title="OO Hello World - Ceylon" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-hrK_zQzJOpk/T0lTmHeb6BI/AAAAAAAAGPo/9UV22_PQgdk/s72-c/ceylon_oohello_output.png" height="72" width="72" /><thr:total>5</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/02/oo-hello-world-ceylon.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUUHQHw_eip7ImA9WhVSGEQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1066899038299255232</id><published>2012-02-22T15:23:00.001-08:00</published><updated>2012-03-16T03:20:31.242-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-16T03:20:31.242-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Zonnon" /><category scheme="http://www.blogger.com/atom/ns#" term="POC" /><title>Proof of Concept - Zonnon and WPF</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Proof of Concept (POC)&lt;/b&gt; or a proof of principle is a realization of a certain method or idea(s) to demonstrate its feasibility, or a demonstration in principle, whose purpose is to verify that some concept or theory has the potential of being used. A proof-of-concept is usually small and may or may not be complete. (&lt;a href="http://en.wikipedia.org/wiki/Proof_of_concept"&gt;Wikipedia: Proof of Concept&lt;/a&gt;)
&lt;br /&gt;
&lt;b&gt;Concept&lt;/b&gt; is an idea formed from inference.
&lt;br /&gt;
&lt;b&gt;Inference&lt;/b&gt; is the act or process of deriving logical conclusions from premises known or assumed to be true.
&lt;br /&gt;
&lt;br /&gt;
Eh voilà! I'm going to proof that you can use WPF and the .NET Framework 4.0 with the latest release of the ETH Zonnon compiler (2010-08-07: Zonnon Compiler 1.2.8) which officially runs on and targets .NET Framework 2.0, and to do that, I will show you some basic .NET hacking that I learned from the &lt;a href="http://cobra-language.com/"&gt;Cobra Programming Language&lt;/a&gt;&amp;nbsp;guys&amp;nbsp;:)&lt;br /&gt;
&lt;br /&gt;
Let's start with the software you will need (in case you want to try it yourself) to follow this tutorial, then which files you will be using to reference, compile, decompile, edit and recompile, and finally, I will show step by step and with screenshots how to build a basic WPF program using Zonnon.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Software Requirements&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Microsoft Windows XP/Vista/7/Server&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.microsoft.com/download/en/details.aspx?id=17851"&gt;Microsoft .NET Framework 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.microsoft.com/visualstudio/en-us/try"&gt;Microsoft Visual Studio 2010&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/f7dy01k1(v=vs.100).aspx"&gt;MSIL Disassembler for .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/496e4ekx(v=vs.100).aspx"&gt;MSIL Assembler for .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.zonnon.ethz.ch/compiler/download.html"&gt;ETH Zonnon compiler 1.2.8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://notepad-plus-plus.org/"&gt;Notepad++&lt;/a&gt; (or any other Text Editor)&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Specific Assemblies&lt;/b&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/f7dy01k1(v=vs.100).aspx"&gt;MSIL Disassembler for .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Ildasm.exe&amp;nbsp;-&amp;nbsp;version 4.0.30319.1&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/496e4ekx(v=vs.100).aspx"&gt;MSIL Assembler for .NET 4.0&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;Ilasm.exe -&amp;nbsp;version 4.0.30319.1&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;fusion.dll - version 4.0.30319.1&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;WPF 4.0 Assemblies&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;PresentationCore.dll
-&amp;nbsp;version&amp;nbsp;4.0.30319.1&lt;/li&gt;
&lt;li&gt;PresentationFramework.dll&amp;nbsp;-&amp;nbsp;version&amp;nbsp;4.0.30319.1&lt;/li&gt;
&lt;li&gt;WindowsBase.dll&amp;nbsp;-&amp;nbsp;version&amp;nbsp;4.0.30319.1&lt;/li&gt;
&lt;li&gt;System.Xaml.dll
-&amp;nbsp;version&amp;nbsp;4.0.30319.1&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;a href="http://www.zonnon.ethz.ch/compiler/download.html"&gt;ETH Zonnon compiler 1.2.8&lt;/a&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;zc.exe - Compiler Launcher Program&lt;/li&gt;
&lt;li&gt;ETH.Zonnon.dll - Zonnon Compiler&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;b&gt;Step #1: Installing ETH Zonnon Compiler 1.2.8&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
You can download from the link above. I installed in "C:\Zonnon" for ease of use (less typing).&lt;br /&gt;
After installation you should have the following files installed:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-izxyUBiawBE/T0arb4VxwuI/AAAAAAAAGN4/uuj4ZSNO3Jk/s1600/s1_zonnon_files_after_installation.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="386" src="http://4.bp.blogspot.com/-izxyUBiawBE/T0arb4VxwuI/AAAAAAAAGN4/uuj4ZSNO3Jk/s400/s1_zonnon_files_after_installation.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #2: Project Directory&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Create a new folder that will hold our source code and needed assemblies. Again, for ease of use, I created it within the Zonnon installation directoy "C:\Zonnon\wpfznn\" and copy all the assemblies listed in section "Specific Assemblies"&lt;b&gt;&amp;nbsp;&lt;/b&gt;except for the Zonnon Compiler assemblies (zc.exe and ETH.Zonnon.dll) which are located in the Zonnon folder.&lt;br /&gt;
&lt;br /&gt;
At the end you should have something like the following:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-7wC-jSGmvBA/T0avKqu1uBI/AAAAAAAAGOA/JaRLfxCHRI4/s1600/s2_zonnon_working_folder_and_files.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="112" src="http://2.bp.blogspot.com/-7wC-jSGmvBA/T0avKqu1uBI/AAAAAAAAGOA/JaRLfxCHRI4/s400/s2_zonnon_working_folder_and_files.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Step #3: Writing Code&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Using your favorite Text Editor, create a new Zonnon source code file for our program "wpfpoc.znn" and save it in our working directory we just created. Now type (or copy/paste) the following Zonnon source code on the file and save again.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;module Main;
import 
    System.Byte as Byte,
    System.IO.Path as Path,
    System.Reflection.Assembly as Assembly,
    System.Reflection.AssemblyName as AssemblyName,
    (* WPF imports *)
    System.Xaml,
    System.Windows.Application as Application,
    System.Windows.Window as Window,
    System.Windows.Media.Color as Color,
    System.Windows.Media.SolidColorBrush as SolidColorBrush,    
    System.Windows.Controls.Button as Button,
    System.Windows.Controls.Label as Label,    
    System.Windows.Controls.StackPanel as StackPanel,
    System.Windows.SizeToContent as SizeToContent,
    System.Windows.Thickness as Thickness,
    System.Windows.Media.Brushes as Brushes,
    System.Windows.Media.Effects.DropShadowEffect as DropShadowEffect;
var        
    win: Window;    
    app: Application;
    c: Color;
    scb: SolidColorBrush;
    btn: Button;
    stk: StackPanel;
    asm : Assembly;
    asmn: AssemblyName;
    
procedure {public} onClick(sender: object; args: System.EventArgs);
var lbl: Label;
    msg: string;
begin
    msg := "Welcome to Zonnon!";
    lbl := new Label();
    lbl.FontSize := real(36);
    lbl.Foreground := Brushes.White;
    lbl.Content := msg;    
    stk.Children.Add(lbl);
    win.Height := lbl.Height;
    writeln(msg);
end onClick;
    
begin
    asm := Assembly.GetExecutingAssembly();
    asmn := asm.GetName();

    writeln;    
    writeln("Running Assembly: ", asm.Location:2);
    writeln("Assembly Name: ", asmn.Name:2);
    writeln;    

    win := new Window();
    win.Width := real(400);
    win.Height := real(150);
    win.SizeToContent := SizeToContent.Height;
    win.Title := "Hello Zonnon";        
    
    c.A := Byte(255); c.R := Byte(100); c.G := Byte(150); c.B := Byte(200);
    scb := new SolidColorBrush(c);
    win.Background := scb;
    
    stk := new StackPanel();
    stk.Margin := new Thickness(real(15));
    win.Content := stk;    
    
    btn := new Button();
    btn.Content := "Push Me";
    btn.FontSize := real(24);
    btn.Effect := new DropShadowEffect();
    
    btn.add_Click(onClick);
    stk.Children.Add(btn);
    
    app := new Application();
    app.Run(win);    
    
    (* Stop and exit *)  
    writeln;
    writeln("Press any key to exit...");  
    readln();    
end Main.    
&lt;/pre&gt;
&lt;br /&gt;
The code is very straightforward and even if it is not commented you can easily understand it... ok ok let's do a quick summary: The program is an executable Zonnon Module program unit. We then import several namespaces and classes from the WPF assemblies and we declare some variables to be used in our main body. The program creates a Window and set its properties. Next, a StackPanel container control is added to the Window's content. We add a Button into the StackPanel we just created and add a Click Event to it. This event calls the&amp;nbsp;onClick procedure that what it does is create a new Label and push it into the Stack (and printing it to the Console) for every click you do to the Button. Finally we create an instance of the Application and call its Run method toshow up our WPF window! Once you close the Window control will be return to the Console Application and wait for any key to be pressed to exit.&lt;br /&gt;
&lt;br /&gt;
For those who read programming books... Alright, yes, this program is a mix of a C# WPF example I found in one of my WPF books and another one from IronPython in Action plus some other stuff of my own :) &amp;nbsp;CODE REUSE FTW ;)&lt;br /&gt;
&lt;br /&gt;
Ok, let the fun begin!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #4: Compilation Completed Successfully - First Problem&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We are ready to compile our program for the first time.&lt;br /&gt;
Assuming you copied/pasted the code above, let's see what we get by compiling our code into an EXE file.&lt;br /&gt;
&lt;br /&gt;
Open a Windows Cmd window and navigate to our working folder. Then let's use the Zonnon Compiler with the following command line arguments to get our executable assembly.&lt;br /&gt;
&lt;br /&gt;
Assuming you are using the same path structure than me you can copy/pase the following line:&lt;br /&gt;
&lt;br /&gt;
C:\zonnon\zc.exe wpfpoc.znn /entry:Main /ref:PresentationCore.dll /ref:PresentationFramework.dll /ref:System.Xaml.dll /ref:WindowsBase.dll&lt;br /&gt;
&lt;br /&gt;
If you have no syntax error in your code you should see the following result:
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-4HJZyIReQv8/T0a4oEW3OnI/AAAAAAAAGOQ/UMMLqB62snc/s1600/s3_zonnon_compile_using_original_zc.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="455" src="http://4.bp.blogspot.com/-4HJZyIReQv8/T0a4oEW3OnI/AAAAAAAAGOQ/UMMLqB62snc/s640/s3_zonnon_compile_using_original_zc.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
SUCCESS! We did not get any compilation error. Lets run it...&lt;br /&gt;
&lt;br /&gt;
BEEP!&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-WKQGFUdNiO4/T0a5cuaXG2I/AAAAAAAAGOY/cOrZkBXcAiY/s1600/s4_zonnon_badimageformatexception.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-WKQGFUdNiO4/T0a5cuaXG2I/AAAAAAAAGOY/cOrZkBXcAiY/s1600/s4_zonnon_badimageformatexception.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OK... that makes sense... when the program runs and it arrives to line 53 (&amp;nbsp;win := new Window();&amp;nbsp;) it throws a BadImageFormatException. This is because the PresentationCore.dll and PresentationFramework.dll (where the Window class resides) target a newer .NET Framework than the one our program was compiled against. To fix that, we will change it by manually doing it on the zc.exe file.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #5:&amp;nbsp;Let the Hacking Begin -&amp;nbsp;Disassemble&amp;nbsp;the zc.exe Assembly&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We are going to make use of the Microsoft IL Dissasembler to change the target .NET Framework of the Zonnon Compiler launcher program from .NET 2.0 to 4.0.&lt;br /&gt;
&lt;br /&gt;
Copy/pase the following command line into your console:&lt;br /&gt;
&lt;br /&gt;
ildasm.exe C:\Zonnon\zc.exe /out=C:\Zonnon\zc.il&lt;br /&gt;
&lt;br /&gt;
The ildasm program will decompile and extract the zc.exe assembly and give us a file containing all its Intermediate Language in a file ".il"&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #6:&amp;nbsp;&lt;/b&gt;&lt;b&gt;Let the Hacking Begin - Change the Target .NET Framework&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Open the zc.il file with any Text Editor. and locate the following 2 sections&lt;br /&gt;
&lt;br /&gt;
.assembly extern mscorlib&lt;br /&gt;
.assembly extern System&lt;br /&gt;
&lt;br /&gt;
Each of those 2 assemblies have a .ver&amp;nbsp;2:0:0:0&lt;br /&gt;
Change it to:&amp;nbsp;.ver 4:0:0:0 and save.&lt;br /&gt;
&lt;br /&gt;
If you compare the original zc.il and the one after the edit you should get:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-D0PN9otRbdQ/T0bHBLmT6ZI/AAAAAAAAGOg/cw5-w4165b4/s1600/s6_zonnon_edit_il_change_target_framework.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="390" src="http://2.bp.blogspot.com/-D0PN9otRbdQ/T0bHBLmT6ZI/AAAAAAAAGOg/cw5-w4165b4/s640/s6_zonnon_edit_il_change_target_framework.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #7:&amp;nbsp;Let the Hacking Begin - Assemble&amp;nbsp;the zc.exe Assembly&lt;/b&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that the target Framework is changed, lets use the&amp;nbsp;Microsoft IL Asembler&amp;nbsp;to regenerate the zc.exe from the edited zc.il file.&lt;br /&gt;
&lt;br /&gt;
Copy/pase the following command line into your console:&amp;nbsp;
&lt;br /&gt;
&lt;br /&gt;
ilasm.exe C:\Zonnon\zc.il /EXE /out=C:\Zonnon\zc.exe&lt;br /&gt;
&lt;br /&gt;
You should get an Operation completed successfully:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-K-jaz1zfe2I/T0bIz0ZlWEI/AAAAAAAAGOo/vM_bMCqHHc4/s1600/s7_zonnon_ilasm_zc_il_to_exe.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-K-jaz1zfe2I/T0bIz0ZlWEI/AAAAAAAAGOo/vM_bMCqHHc4/s1600/s7_zonnon_ilasm_zc_il_to_exe.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #8:&amp;nbsp;&lt;/b&gt;&lt;b&gt;Compilation Completed Successfully - Second Problem&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Run the compiler command line that we used in Step #4&lt;br /&gt;
&lt;br /&gt;
C:\zonnon\zc.exe wpfpoc.znn /entry:Main /ref:PresentationCore.dll /ref:PresentationFramework.dll /ref:System.Xaml.dll /ref:WindowsBase.dll&lt;br /&gt;
&lt;br /&gt;
You should get the same&amp;nbsp;Compilation completed successfully message.&lt;br /&gt;
&lt;br /&gt;
Run your program again.&lt;br /&gt;
&lt;br /&gt;
BEEP!&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-flRUDF3f0-s/T0bKOcqWbjI/AAAAAAAAGOw/fi9yE3wg79I/s1600/s8_zonnon_invalidoperationexception.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-flRUDF3f0-s/T0bKOcqWbjI/AAAAAAAAGOw/fi9yE3wg79I/s1600/s8_zonnon_invalidoperationexception.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The problem now is that the UI application needs to run in a single Thread.&lt;br /&gt;
In C# apps you can solve this using the [STAThread] attribute to the program main method (the entry point) which indicates that the COM threading model for an application is single-threaded apartment (STA). However, it looks like there is no .NET Attributes support on Zonnon (or at least not documented).&lt;br /&gt;
&lt;br /&gt;
I then tried using the Thread object and set the &amp;nbsp;SetApartmentState property to&amp;nbsp;ApartmentState.STA, but I failed because I was not able to convert an activity to a System.Threading.ThreadStart delegate object so I can&amp;nbsp;succesfully&amp;nbsp;instantiate a Thread.&lt;br /&gt;
&lt;br /&gt;
For more details on the those 2 last paragraphs please have a look at this link:&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/jfoscoding/archive/2005/04/07/406341.aspx"&gt;Why is STAThread required?&lt;/a&gt;&lt;br /&gt;
"&lt;span style="background-color: #ced5db; color: #333333; font-family: &amp;quot;Tahoma&amp;quot;; font-size: 12px; line-height: 18px; text-align: left;"&gt;When the&amp;nbsp;&lt;/span&gt;&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemstathreadattributeclasstopic.asp" style="background-color: #ced5db; color: #0066dd; cursor: pointer; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px; outline-color: initial; outline-style: none; outline-width: initial; text-align: left; text-decoration: none;"&gt;&lt;span style="font-family: &amp;quot;Tahoma&amp;quot;;"&gt;STAThreadAttribute&lt;/span&gt;&lt;/a&gt;&lt;span style="background-color: #ced5db; color: #333333; font-family: &amp;quot;Tahoma&amp;quot;; font-size: 12px; line-height: 18px; text-align: left;"&gt;&amp;nbsp;is applied, it changes the apartment state of the current thread to be single threaded. "&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #9: The&amp;nbsp;System.STAThreadAttribute&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
At the end, I decided to fix it with a dirty hack (IL) again.
&lt;br /&gt;
To fix this we will be using exaclty the same method we used before, but this time we will change the Main method of our program, but first, let's see how I knew what to change.&lt;br /&gt;
&lt;br /&gt;
I created a C# program that used the [STAThread] attribute.&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;class Program
{
    // Methods
    [STAThread]
    private static void Main(string[] args)
    {
        //pass
    }
}
&lt;/pre&gt;
&lt;br /&gt;
I decompiled it using Reflector to see the generated IL code:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-5slq4OJ-9fY/T0gkyl-0bpI/AAAAAAAAGO4/DlsNXCi7kfM/s1600/s9_decompiled_csharp_code_STAThreadAttribute.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="312" src="http://1.bp.blogspot.com/-5slq4OJ-9fY/T0gkyl-0bpI/AAAAAAAAGO4/DlsNXCi7kfM/s640/s9_decompiled_csharp_code_STAThreadAttribute.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
OK, what we see here is that within the Main method, which is the entrypoint method of our assembly, an instance of System.STAThreadAttribute is created. That's all we need to know to fix the problem with our WPF program we need to create that instance ourselves. Don't we?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #10: Fixing our WPF Program &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Copy/pase the following command line into your console:&lt;br /&gt;
&lt;br /&gt;
ildasm.exe wpfpoc.exe /out=wpfpoc.il&lt;br /&gt;
&lt;br /&gt;
The ildasm program will decompile and extract the wpfpoc.exe assembly and give us a file containing all its Intermediate Language in a file ".il"&lt;br /&gt;
&lt;br /&gt;
Open it in any text editor and go to the main method.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-1MBwSa1zDAE/T0grNGYyHcI/AAAAAAAAGPA/viF2sfFeM4c/s1600/s10_fixing_our_program_main_method.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="446" src="http://2.bp.blogspot.com/-1MBwSa1zDAE/T0grNGYyHcI/AAAAAAAAGPA/viF2sfFeM4c/s640/s10_fixing_our_program_main_method.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Wait a second... it already has the&amp;nbsp;System.STAThreadAttribute on it! What's wrong then?&lt;br /&gt;
&lt;br /&gt;
The answer is the .param [0] line just above it. To make it work we need to either move the .custom instance line over the .param [0] or just comment/remove the .param [0] line and save.&lt;br /&gt;
&lt;br /&gt;
I was intrigued by this .param [0] and search about it on the&amp;nbsp;&lt;a href="http://www.apress.com/9781590596463"&gt;Expert .NET 2.0 IL Assembler&lt;/a&gt;&amp;nbsp;Apress book and found the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;param_const_def&amp;gt; ::= &amp;lt;b&amp;gt;.param&amp;lt;/b&amp;gt; [&amp;lt;sequence&amp;gt;] = &amp;lt;const_type&amp;gt; [ (&amp;lt;value&amp;gt;) ]
&lt;br /&gt;
&lt;br /&gt;
&lt;sequence&gt; is the parameter’s sequence number. This number should not be 0, because&lt;/sequence&gt;&lt;br /&gt;
a 0 sequence number corresponds to the return type, and a “default return value” does not&lt;br /&gt;
make sense.&lt;br /&gt;
&lt;br /&gt;
So needed or not needed to avoid any risk I opted to move the&amp;nbsp;System.STAThreadAttribute line on top of .param [0] &amp;nbsp;(maybe an IL expert can explain why this behaviour?)&lt;br /&gt;
&lt;br /&gt;
The code ends up like the following:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-8yRCu79xCaM/T0guX6dxikI/AAAAAAAAGPI/6gxFTCRuEps/s1600/s10_fixing_our_program_main_method_after_change.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="446" src="http://3.bp.blogspot.com/-8yRCu79xCaM/T0guX6dxikI/AAAAAAAAGPI/6gxFTCRuEps/s640/s10_fixing_our_program_main_method_after_change.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We are ready to re-build our program.&lt;br /&gt;
&lt;br /&gt;
Copy/pase the following command line into your console:&lt;br /&gt;
&lt;br /&gt;
ilasm.exe wpfpoc.il /EXE /out=wpfpoc.exe&lt;br /&gt;
&lt;br /&gt;
You should see a "Operation completed successfully" message.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step #11: Running the WPF Program&lt;/b&gt;
&lt;br /&gt;
&lt;br /&gt;
Execute the wpfpoc.exe program from the command line.&lt;br /&gt;
&lt;br /&gt;
Our WPF window will pop up.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-zkwuWdt61es/T0gvZ9CQxnI/AAAAAAAAGPQ/ctvCBXBLojQ/s1600/s11_running_our_program_1_console.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="316" src="http://3.bp.blogspot.com/-zkwuWdt61es/T0gvZ9CQxnI/AAAAAAAAGPQ/ctvCBXBLojQ/s640/s11_running_our_program_1_console.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Every time you click on the Push Me button it will push a new Label to the StackPanel and resize the Window. At the same time, it prints the same text to the Console.&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-jeJJGXWiXGA/T0gwHRvHEOI/AAAAAAAAGPY/bgP0-uLj8vg/s1600/s11_running_our_program_2_wpf.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="289" src="http://2.bp.blogspot.com/-jeJJGXWiXGA/T0gwHRvHEOI/AAAAAAAAGPY/bgP0-uLj8vg/s320/s11_running_our_program_2_wpf.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-PCfpomRTZ5U/T0gwnOnjMVI/AAAAAAAAGPg/Enhx-Efn41s/s1600/s11_running_our_program_3_console.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img border="0" height="316" src="http://4.bp.blogspot.com/-PCfpomRTZ5U/T0gwnOnjMVI/AAAAAAAAGPg/Enhx-Efn41s/s640/s11_running_our_program_3_console.png" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
There you go. We finally have a .NET Framework 4.0 WPF program developed using the Zonnon Programming Language. This was just a proof of concept experiment just for fun. I think Zonnon is a very interesting programming language and hope that the people behind it (
&lt;b style="background-color: white; font-family: verdana, arial, helvetica, sans-serif; font-size: 13px; line-height: 16px; outline-color: initial; outline-style: none; outline-width: 0px;"&gt;ETH Zurich&lt;/b&gt;&amp;nbsp;)&amp;nbsp; keep the good work and bring us a ETH Zonnon Compiler 1.2.9 soon with built in support for WPF and targets the .NET Framework 4.0.&lt;br /&gt;
&lt;br /&gt;
And by the way, this little trick is the same I used in my previous post &lt;a href="http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-zonnon.html"&gt;Factorial and Fibonacci in Zonnon&lt;/a&gt; to make use of System.Numerics.dll which is .NET 4.0 compatible only.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/02fEjnXquDw" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1066899038299255232/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/02/proof-of-concept-zonnon-and-wpf.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1066899038299255232?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1066899038299255232?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/02fEjnXquDw/proof-of-concept-zonnon-and-wpf.html" title="Proof of Concept - Zonnon and WPF" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-izxyUBiawBE/T0arb4VxwuI/AAAAAAAAGN4/uuj4ZSNO3Jk/s72-c/s1_zonnon_files_after_installation.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/02/proof-of-concept-zonnon-and-wpf.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkIFQ30yeip7ImA9WhVSGEQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7099430410646236775</id><published>2012-02-10T10:42:00.000-08:00</published><updated>2012-03-16T03:41:52.392-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-16T03:41:52.392-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Zonnon" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Zonnon</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Zonnon that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;(* Factorial and Fibonacci in Zonnon *)

(* Module (Static Class) *)
module StaticFiborial;
import 
  System.Numerics.BigInteger as BigInteger, 
  System.Diagnostics.Stopwatch as Stopwatch;
(* Static Field *)
var {private} className: string;

  (* Static Method - Factorial Recursive *)
  procedure {public} factorialR(n: integer): BigInteger;
  begin
  if n &amp;lt; 1 then
    return BigInteger.One;
  else
    return BigInteger(n) * BigInteger(factorialR(n - 1));
  end;   
  end factorialR;

  (* Static Method - Factorial Imperative *)
  procedure {public} factorialI(n: integer): BigInteger;
  var i: integer;
    res: BigInteger;
  begin 
    res := BigInteger.One;
    for i := n to 1 by -1 do 
      res := res * BigInteger(i);
    end;    
    return res;
  end factorialI;

  (* Static Method - Fibonacci Recursive *)
  procedure {public} fibonacciR(n: integer): integer{64};
  begin
    if n &amp;lt; 2 then
      return 1;
    else
      return fibonacciR(n - 1) + fibonacciR(n - 2);
    end;
  end fibonacciR;

  (* Static Method - Fibonacci Imperative *)
  procedure {public} fibonacciI(n: integer): integer{64};
  var i, pre, cur, tmp: integer{64};
  begin
    pre := 1;
    cur := 1;
    tmp := 0;
    for i := 2 to n do
      tmp := cur + pre;    
      pre := cur;    
      cur := tmp; 
    end; 
    return cur;
  end fibonacciI;  

  (* Static Method - Benchmarking Algorithms *)
  procedure {public} benchmarkAlgorithm(algorithm: integer; var values: array * of integer);
  var timer: Stopwatch;
    testValue: integer;
    facTimeResult: BigInteger;
    i, fibTimeResult: integer{64};
  begin
    timer := new Stopwatch(); 
    i := 0;   
    testValue := 0;   
    facTimeResult := BigInteger.Zero;
    fibTimeResult := 0;  
    (* "Switch" Flow Control Statement *)  
    case algorithm of    
    1:         
      writeln("Factorial Imperative:");
      (* "For" Loop Statement *)
      for i := 0 to len(values)-1 do
        testValue := values[i];
        (* Taking Time *)
        timer.Start;
        facTimeResult := factorialI(testValue);
        timer.Stop;
        (* Getting Time *)
        writeln(" (" + string(testValue) + ") = {" + string(timer.Elapsed) + "}");
      end;      
    | 2:
      writeln("Factorial Recursive:");
      (* "While" Loop Statement *)      
      while i &amp;lt; len(values) do
        testValue := values[i];
        (* Taking Time *)
        timer.Start;
        facTimeResult := factorialR(testValue);
        timer.Stop;
        (* Getting Time *)
        writeln(" (" + string(testValue) + ") = {" + string(timer.Elapsed) + "}");
        i := i + 1;
      end;
    | 3:  
      writeln("Fibonacci Imperative:");
      (* "Repeat" Loop Statement *)
      repeat
        testValue := values[i];
        (* Taking Time *)
        timer.Start;
        fibTimeResult := fibonacciI(testValue);
        timer.Stop;
        (* Getting Time *)
        writeln(" (" + string(testValue) + ") = {" + string(timer.Elapsed) + "}");
        i := i + 1;
        until i = len(values);
    | 4:  
      writeln("Fibonacci Recursive:");
      (* "Loop" Loop Statement *)
      loop
        testValue := values[i];
        (* Taking Time *)
        timer.Start;
        fibTimeResult := fibonacciR(testValue);
        timer.Stop;
        (* Getting Time *)
        writeln(" (" + string(testValue) + ") = {" + string(timer.Elapsed) + "}");
        i := i + 1;
        if i = len(values) then exit end;
        end;
    else
      (* This code will never be reached. 
      So, I'm "using" fibTimeResult &amp;amp; facTimeResult to avoid compile error:
      Zonnon Compiler, Version 1.2.8.0    
      The variable 'fibTimeResult' is assigned but its value is never used.
      The variable 'facTimeResult' is assigned but its value is never used.*)
      writeln(fibTimeResult);      
      writeln(string(facTimeResult)); (* BigInteger not implicitly converted*)
      writeln("DONG!");  
    end;
  end benchmarkAlgorithm;

  (* funny work around for static init code *)
  procedure {public} init;
  begin  
    (* pass *)
  end init;

(* Contructor | Initializer *)  
begin
  className := "Static Constructor";
  writeln(className);
end StaticFiborial.

(* Instance Class *)
object {ref, public} InstanceFiborial;
import System.Numerics.BigInteger as BigInteger,
  StaticFiborial;
(* Instance Field *)
var {private} className: string;

  (* Instance Method - Factorial Recursive *)
  procedure {public} factorialR(n: integer): BigInteger;
  begin
    (* Calling Static Method *)
    return StaticFiborial.factorialR(n);
  end factorialR;

  (* Instance Method - Factorial Imperative *)
  procedure {public} factorialI(n: integer): BigInteger;
  begin 
    (* Calling Static Method *)
    return StaticFiborial.factorialI(n);
  end factorialI;

  (* Instance Method - Fibonacci Recursive *)
  procedure {public} fibonacciR(n: integer): integer{64};
  begin
    (* Calling Static Method *)
    return StaticFiborial.fibonacciR(n);
  end fibonacciR;

  (* Instance Method - Fibonacci Imperative *)
  procedure {public} fibonacciI(n: integer): integer{64};
  begin
    return StaticFiborial.fibonacciI(n);
  end fibonacciI;
  
(* Instance Contructor | Initializer *)  
begin
  self.className := "Instance Constructor";
  writeln(self.className);
end InstanceFiborial.

(* Console Program *)
module Main;
import StaticFiborial, InstanceFiborial;
const N = 10;
type TestArray = array N of integer;
var i,j: integer;
  ff: InstanceFiborial; 
  values: TestArray;
begin
  writeln;
  writeln("Static Class");  
  (* Calling Static Class and Methods 
  No instantiation needed. Calling method directly from the class *)
  (* calling StaticFiborial.init to execute the static constructor code 
  otherwise the string that is being printed there will appear the first
  time a static method is called. In this case will appear like: 
  FacImp(5) =Static Constructor\n120 *)
  StaticFiborial.init;
  writeln("FacImp(5) =", string(StaticFiborial.factorialI(5)));
  writeln("FacRec(5) =", string(StaticFiborial.factorialR(5)));  
  writeln("FibImp(11)=", string(StaticFiborial.fibonacciI(11)));
  writeln("FibRec(11)=", string(StaticFiborial.fibonacciR(11)));  

  writeln;  
  writeln("Instance Class");
  (* Calling Instance Class and Methods         
  Need to instantiate before using. Calling method from instantiated object *)
  ff := new InstanceFiborial();
  writeln("FacImp(5) =", string(ff.factorialI(5)));
  writeln("FacRec(5) =", string(ff.factorialR(5)));  
  writeln("FibImp(11)=", string(ff.fibonacciI(11)));
  writeln("FibRec(11)=", string(ff.fibonacciR(11)));  
  writeln;

  (* Create a list of integer values to test    
  From 5 to 50 by 5 *)
  j := 0;
  (*for i := 5 to 50 by 5 do *)
  for i := 5 to 50 by 5 do
    values[j] := i;
    j := j + 1;
  end; 

  (* Benchmarking Fibonacci *)
  (* 1 = Factorial Imperative *)
  StaticFiborial.benchmarkAlgorithm(1, values);
  writeln;
  (* 2 = Factorial Recursive *)
  StaticFiborial.benchmarkAlgorithm(2, values);
  writeln;
        
  (* Benchmarking Factorial *)
  (* 3 = Fibonacci Imperative *)
  StaticFiborial.benchmarkAlgorithm(3, values);
  writeln;
  (* 4 = Fibonacci Recursive *)
  StaticFiborial.benchmarkAlgorithm(4, values);
  writeln;

  (* Stop and exit *)
  writeln("Press any key to exit...");
  readln();  
end Main.
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-cA560p4UQp0/TzUvITJcPSI/AAAAAAAAGNU/l7wKN7XFodY/s1600/fiborial_zonnon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-cA560p4UQp0/TzUvITJcPSI/AAAAAAAAGNU/l7wKN7XFodY/s640/fiborial_zonnon.png" width="396" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;  
module Main;
import
  System.Numerics.BigInteger as BigInteger, 
  System.Text.StringBuilder as StringBuilder;

  (* Using a StringBuilder as a list of string elements *)
  procedure {public} GetFactorialSeries(n: integer): string;
  var i: integer;
    series: StringBuilder;
  begin
    (* Create the String that will hold the list *)
    series := new StringBuilder();
    (* We begin by concatenating the number you want to calculate *)
    (* in the following format: "!# =" *)
    series.Append("!");  
    series.Append(n);  
    series.Append(" = ");  
    (* We iterate backwards through the elements of the series *)
    for i := n to 1 by -1 do
      (* and append it to the list *)
      series.Append(i);  
      if i &amp;gt; 1 then
        series.Append(" * ");  
      else   
        series.Append(" = ");   
    end;
    end;  
    (* Get the result from the Factorial Method *)
    (* and append it to the end of the list *)
    series.Append(string(Factorial(n)));
    (* return the list as a string *)
    return string(series);
  end GetFactorialSeries;

  (* Using a StringBuilder as a list of string elements *)
  procedure {public} GetFibonnaciSeries(n: integer): string;
  var i: integer;
    series: StringBuilder;
  begin
    (* Create the String that will hold the list *)  
    series := new StringBuilder();
    (* We begin by concatenating the first 3 values which 
    are always constant *)   
    series.Append("0, 1, 1"); 
    (* Then we calculate the Fibonacci of each element  
    and add append it to the list *)
    for i := 2 to n do 
      if i &amp;lt; n then
        series.Append(", ");  
      else  
        series.Append(" = ");  
      end;
      series.Append(string(Fibonacci(i)));  
    end;
    (* return the list as a string *)
    return string(series);
  end GetFibonnaciSeries;
  
  procedure {private} Factorial(n: integer): BigInteger;
  begin
    if n &amp;lt; 1 then
      return BigInteger.One;
    else
      return BigInteger(n) * BigInteger(Factorial(n - 1));
    end;   
  end Factorial;
  
  procedure {private} Fibonacci(n: integer): integer{64};
  begin
    if n &amp;lt; 2 then
      return 1;
    else
      return Fibonacci(n - 1) + Fibonacci(n - 2);
    end;
  end Fibonacci;
    
begin
  writeln;
  (* Printing Factorial Series *)
  writeln();  
  writeln(GetFactorialSeries(5));  
  writeln(GetFactorialSeries(7));  
  writeln(GetFactorialSeries(9));  
  writeln(GetFactorialSeries(11));  
  writeln(GetFactorialSeries(40));  
  (* Printing Fibonacci Series *)
  writeln();  
  writeln(GetFibonnaciSeries(5));  
  writeln(GetFibonnaciSeries(7));  
  writeln(GetFibonnaciSeries(9));  
  writeln(GetFibonnaciSeries(11));  
  writeln(GetFibonnaciSeries(40));  
  
end Main.
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-cStHLd494LI/TzU55A7_ZaI/AAAAAAAAGNc/acjqYq0H4PU/s1600/FiborialSeriesZonnon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="348" src="http://2.bp.blogspot.com/-cStHLd494LI/TzU55A7_ZaI/AAAAAAAAGNc/acjqYq0H4PU/s640/FiborialSeriesZonnon.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Normally, instance classes can contain both, instance and static members such as: fields, getters, constructors/initializers, methods, etc. However, Zonnon doesn't support mixing both of them 
on the Module or Object unit types.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;In the following code I had to create one Module and one Object to workaround this limitation.
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt; 
(* Module (Static Class) 
  You cannot declare a variable of type ModuleName 
  If you try to do that you get a: 
  "'ModuleName' does not denote a type as expected."
*) 
module StaticFiborial;
(* Static Field *)
var {private} staticCount: integer;
  
  (* Static Read-Only Getter 
  You cannot reference your class members with the "self" 
  reference pointer since static members are not instantiated. *)
  procedure {public} StaticCount(): integer;
  begin
    return staticCount;
  end StaticCount;  
  
  (* Static Method *)
  procedure {public} Fibonacci(n: integer);
  begin
    staticCount := staticCount + 1;
    writeln;
    writeln("Fibonacci(" + string(n) + ")");
  end Fibonacci;
  
(* Static Constructor | Initializer *)  
begin
  staticCount := 0; 
  writeln("Static Constructor", staticCount:2);
end StaticFiborial.

(* Object (Instance Class) 
  You cannot try to call a method of ObjectName without an instance.
  If you try to do that you get a:
  "Cannot access to a member of 'ObjectName' 
  because it is object but not an instance of object" *)
object {ref, public} InstanceFiborial;
(* Instance Field *)
var {private} instanceCount: integer;

  (* Instance Read-Only Getter
  Within instance members, you can always use    
  the "self" reference pointer to access your (instance) members. *) 
  procedure {public} InstanceCount(): integer;
  begin
    return self.instanceCount;
  end InstanceCount;

  (* Instance Method *)
  procedure {public} Factorial(n: integer);
  begin
    self.instanceCount := self.instanceCount + 1;
    writeln;
    writeln("Factorial(" + string(n) + ")");
  end Factorial;
  
(* Instance Contructor | Initializer *)  
begin
  self.instanceCount := 0; 
  writeln("Instance Constructor", self.instanceCount:2);
end InstanceFiborial.

module Main;
import StaticFiborial, InstanceFiborial;
var fib, fib2: InstanceFiborial;  
begin  
  writeln;
  (* Calling Static Constructor and Methods 
  No need to instantiate *)  
  StaticFiborial.Fibonacci(5);

  (* Calling Instance Constructor and Methods  
  instance required *)
  fib := new InstanceFiborial();
  fib.Factorial(5);

  StaticFiborial.Fibonacci(15);
  fib.Factorial(5);  

  (* Calling Instance Constructor and Methods  
  for a second object *)
  fib2 := new InstanceFiborial();  
  fib2.Factorial(5);  

  writeln;
  (* Calling Static Getter *)
  writeln("Static Count =", StaticFiborial.StaticCount:2);  
  (* Calling Instance Getter of object 1 and 2 *)
  writeln("Instance 1 Count =", fib.InstanceCount:2);  
  writeln("Instance 2 Count =", fib2.InstanceCount:2);  

end Main.
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-Nxz4D6MIbK8/TzVL10wCWmI/AAAAAAAAGNk/GSXXhIf7IIk/s1600/FiborialExtrasZonnon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="348" src="http://2.bp.blogspot.com/-Nxz4D6MIbK8/TzVL10wCWmI/AAAAAAAAGNk/GSXXhIf7IIk/s400/FiborialExtrasZonnon.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64/integer{64}, System.Double/real{64}, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was on my previous post in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET execution thrown an Overflow Exception when using the "Long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System::Numerics::BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just tried to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;  
module Main;
import System.Numerics.BigInteger as BigInteger, 
  System.Diagnostics.Stopwatch as Stopwatch;
var 
  timer: Stopwatch;
  facIntResult: integer{64};
  facDblResult: real{64};
  facBigResult: BigInteger;
  i: integer;  
  
  (* Long Factorial *)
  procedure FactorialInt64(n: integer): integer{64}; 
  begin
    if n = 1 then
      return 1{64};
    else  
      return n * FactorialInt64(n - 1);  
    end;
  end FactorialInt64;

  (* Double Factorial *)
  procedure FactorialDouble(n: integer): real{64};
  begin
    if n = 1 then
      return 1.0{64};  
    else  
      return real(n) * FactorialDouble(n - 1);
    end;
  end FactorialDouble;
  
  (* BigInteger Factorial *)
  procedure FactorialBigInteger(n: integer): BigInteger;
  begin
    if n = 1 then
      return BigInteger.One;  
    else  
      return BigInteger(n) * BigInteger(FactorialBigInteger(n - 1));  
    end;
  end FactorialBigInteger;
  
begin
  timer := new Stopwatch();  
  facIntResult := 0{64};
  facDblResult := 0.0{64};  
  facBigResult := BigInteger.Zero;  
  
  writeln;
  writeln("Factorial using Int64");  
  (* Benchmark Factorial using Int64 *)
  (* Overflow Exception!!! *)
  do
    for i:= 5 to 50 by 5 do    
      timer.Start;
      facIntResult := FactorialInt64(i);
      timer.Stop;
      writeln(" (" + string(i) + ") = " + string(timer.Elapsed) + " : " 
     + string(facIntResult));
    end;  
  on exception do
    (* built-in function reason doesn't work:
 Compile Error: Entity 'reason' is not declared*)
    writeln("Oops!","OverflowException");
  on termination do
    writeln("Oops!","Exception Termination");
  end;

  writeln;
  writeln("Factorial using Double");  
  (* Benchmark Factorial using Double *)
  for i:= 5 to 50 by 5 do    
    timer.Start;
    facDblResult := FactorialDouble(i);
    timer.Stop;
    writeln(" (" + string(i) + ") = " + string(timer.Elapsed) + " : " 
   + string(facDblResult));
  end;
  
  writeln;
  writeln("Factorial using BigInteger");  
  (* Benchmark Factorial using BigInteger *)
  for i:= 5 to 50 by 5 do    
    timer.Start;
    facBigResult := FactorialBigInteger(i);
    timer.Stop;
    writeln(" (" + string(i) + ") = " + string(timer.Elapsed) + " : " 
   + string(facBigResult));
  end;
end Main.
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-t7cGFeWNLu8/TzVcR_KLbXI/AAAAAAAAGNs/Hjc0wF2qGuE/s1600/FiborialTypesZonnon.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="534" src="http://1.bp.blogspot.com/-t7cGFeWNLu8/TzVcR_KLbXI/AAAAAAAAGNs/Hjc0wF2qGuE/s640/FiborialTypesZonnon.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;

NOTE: you need to manually add a reference to the System.Numerics assembly to your project so you can add it to your code.

&lt;!--
&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code. Notice that System.Numerics.dll comes only with the .NET Framework 4.0; Zonnon Compiler 1.2.8 targets .NET Framework 2.0, hence you cannot use it. If you do that, it will compile, but you will get the following runtime error when you code tries to use the BigInteger class. To fix that you need to wait a future official release that targets the .NET Framework 4.0, or, as I did, do a little hack on the compiler to make it work.
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="delphi" name="code"&gt;
Could not load file or assembly 'System.Numerics, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified.
   at Zonnon.Main._body()
   at Zonnon.Main.Main()
   at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile)
   at System.AppDomain.ExecuteAssembly(String assemblyFile)
   at uml4net.executer.Executer.execute(IPanelsMediator mediator, String executableFileName, String executableModule)
&lt;/pre&gt;
--&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Qt75d6OLVgY" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7099430410646236775/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-zonnon.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7099430410646236775?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7099430410646236775?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Qt75d6OLVgY/factorial-and-fibonacci-in-zonnon.html" title="Factorial and Fibonacci in Zonnon" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-cA560p4UQp0/TzUvITJcPSI/AAAAAAAAGNU/l7wKN7XFodY/s72-c/fiborial_zonnon.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-zonnon.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkMMRnY8cCp7ImA9WhVSGEQ.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7944302213515455918</id><published>2012-02-08T14:22:00.000-08:00</published><updated>2012-03-16T03:41:27.878-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-16T03:41:27.878-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Fantom" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Fantom</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Fantom that implements 2 classes (in fact, they are 3 + an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in Fantom

using [java] com.carlosqt.util::Stopwatch
using [java] java.math::BigInteger

// static is not a valid class modifier
// Instanced Class
class StaticFiborial 
{
  // (Constant) Static Field  - Static fields must be const - this ensures thread safety  
  private const static Str className
  // Class/Static Constructor/Initializer
  // It is permissible to have multiple static initializers; they run in order of declaration
  static 
  {      
    className = "Static Constructor"  
    echo(className)  
  }
  // Static Method - Factorial Recursive
  static BigInteger factorialR(Int n)      
  {      
    if (n == 1)      
      return BigInteger.ONE  
    else      
      return BigInteger.valueOf(n).multiply(factorialR(n - 1))  
  }
  // Static Method - Factorial Imperative      
  static BigInteger factorialI(Int n)      
  {      
    BigInteger res := BigInteger.ONE  
    for (i := n; i &amp;gt;= 1; i--)      
    {                      
      res = res.multiply(BigInteger.valueOf(i))  
    }      
    return res  
  }
  // Static Method - Fibonacci Recursive      
  static Int fibonacciR(Int n)      
  {      
    if (n &amp;lt; 2)      
      return 1  
    else      
      return fibonacciR(n - 1) + fibonacciR(n - 2)  
  }      
  // Static Method - Fibonacci Imperative      
  static Int fibonacciI(Int n)      
  {                  
    Int pre := 1  
    Int cur := 1  
    Int tmp := 0   
    for (i := 2; i &amp;lt;= n; i++)  
    {      
      tmp = cur + pre  
      pre = cur  
      cur = tmp  
    }      
    return cur    
  }          
  // Class/Static Method - Benchmarking Algorithms      
  static Void benchmarkAlgorithm(Int algorithm, List values)      
  {                  
    Stopwatch timer := Stopwatch()  
    Int testValue := 0 
    BigInteger facTimeResult := BigInteger.ZERO  
    Int fibTimeResult := 0
    // "Switch" Flow Control Statement
    switch (algorithm)    
    {    
      case 1:    
        echo("\nFactorial Imperative:")    
        // "For" Loop Statement    
        for (i := 0; i &amp;lt; values.size; i++)    
        {                            
          testValue = values.get(i)    
          // Taking Time    
          timer.start()    
          facTimeResult = factorialI(testValue)    
          timer.stop()
          // Getting Time    
          echo(" ($testValue) = ${timer.getElapsed()}")    
        }
      case 2:    
        echo("\nFactorial Recursive:")    
        // "While" Loop Statement
        Int i := 0
        while (i &amp;lt; values.size)    
        {                            
          testValue = values.get(i)   
          // Taking Time    
          timer.start()    
          facTimeResult = factorialR(testValue)
          timer.stop()
          // Getting Time    
          echo(" ($testValue) = ${timer.getElapsed()}")    
          i++
        }    
      case 3:    
        echo("\nFibonacci Imperative:")    
        // "While" Loop Statement
        Int i := 0
        while (i &amp;lt; values.size)    
        {
          testValue = values.get(i)    
          // Taking Time    
          timer.start()    
          fibTimeResult = fibonacciI(testValue)    
          timer.stop()    
          // Getting Time    
          echo(" ($testValue) = ${timer.getElapsed()}")    
          i++    
        }    
      case 4:    
        echo("\nFibonacci Recursive:")      
        // "For" Loop Statement    
        for (i := 0; i &amp;lt; values.size; i++)    
        {    
          testValue = values.get(i)
          // Taking Time    
          timer.start()    
          fibTimeResult = fibonacciR(testValue)   
          timer.stop()   
          // Getting Time    
          echo(" ($testValue) = ${timer.getElapsed()}")    
        }    
        default:    
          echo("DONG!")    
    }                    
  }
}


// Instance Class      
class InstanceFiborial      
{      
  // Instance Field      
  private Str className  
  // Instance Constructor      
  new make()      
  {      
      this.className = "Instance Constructor"  
      echo(this.className)  
  }      
  // Instance Method - Factorial Recursive      
  BigInteger factorialR(Int n)      
  {      
      // Calling Static Method      
      return StaticFiborial.factorialR(n)  
  }      
  // Instance Method - Factorial Imperative      
  BigInteger factorialI(Int n)
  {      
      // Calling Static Method      
      return StaticFiborial.factorialI(n)      
  }      
  // Instance Method - Fibonacci Recursive  
  Int fibonacciR(Int n)  
  {      
      // Calling Static Method      
      return StaticFiborial.fibonacciR(n)  
  }      
  // Instance Method - Factorial Imperative      
  Int fibonacciI(Int n)  
  {      
      // Calling Static Method      
      return StaticFiborial.fibonacciI(n)  
  }      
}    

// Console Program  
public class FiborialApp    
{    
  public static Void main()    
  {
    echo("\nStatic Class")      
    // Calling Static Class and Methods  
    // No instantiation needed. Calling method directly from the class      
    echo("FacImp(5) = ${StaticFiborial.factorialI(5)}")  
    echo("FacRec(5) = ${StaticFiborial.factorialR(5)}")     
    echo("FibImp(11)= ${StaticFiborial.fibonacciI(11)}")      
    echo("FibRec(11)= ${StaticFiborial.fibonacciR(11)}")  
      
    echo("\nInstance Class")      
    // Calling Instance Class and Methods       
    // Need to instantiate before using. Calling method from instantiated object      
    InstanceFiborial ff := InstanceFiborial.make()  
    echo("FacImp(5) = ${ff.factorialI(5)}")  
    echo("FacRec(5) = ${ff.factorialR(5)}")  
    echo("FibImp(11)= ${ff.fibonacciI(11)}")  
    echo("FibRec(11)= ${ff.fibonacciR(11)}")  
      
    // Create a list of integer values to test  
    // From 5 to 50 by 5      
    Int[] values := Int[,]  
    for(i := 5; i &amp;lt;= 50; i += 5)
        values.add(i)
            
    // Benchmarking Fibonacci                           
    // 1 = Factorial Imperative                  
    StaticFiborial.benchmarkAlgorithm(1, values)  
    // 2 = Factorial Recursive      
    StaticFiborial.benchmarkAlgorithm(2, values)  
      
    // Benchmarking Factorial                  
    // 3 = Fibonacci Imperative      
    StaticFiborial.benchmarkAlgorithm(3, values)  
    // 4 = Fibonacci Recursive      
    StaticFiborial.benchmarkAlgorithm(4, values) 
    
    // Stop and exit      
    echo("Press any key to exit...")  
    console := Env.cur  
    userInput := console.in.readLine  
  }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-rXPtVanxqVU/TzLWep1p1aI/AAAAAAAAGM0/z08dJNRaqmg/s1600/fiborial_fantom.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-rXPtVanxqVU/TzLWep1p1aI/AAAAAAAAGM0/z08dJNRaqmg/s1600/fiborial_fantom.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using [java] java.math::BigInteger    
using [java] java.lang::StringBuffer  
    
class Fiborial
{    
  // Using a StringBuffer as a list of string elements
  // because of the following compile error: 
  // Ambiguous call append(sys::Str) FiborialSeries.fan ... Fantom Problem
  // I had to use StringBuffer.apend(s, 0, s.length) instead of just StringBuffer.apend(CharSequence s) 
  static Str getFactorialSeries(Int n)    
  {    
    // Create the String that will hold the list    
    StringBuffer series := StringBuffer()  
    // We begin by concatenating the number you want to calculate    
    // in the following format: "!# ="    
    series.append("!", 0, "!".size)  
    series.append(n.toStr, 0, n.toStr.size)  
    series.append(" = ", 0, 3)
    // We iterate backwards through the elements of the series    
    for (i := n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--)   
    {
      // and append it to the list    
      series.append(i.toStr, 0, i.toStr.size)
      if (i &amp;gt; 1)  
        series.append(" * ", 0, 3)  
      else     
        series.append(" = ", 0, 3)
    }  
    // Get the result from the Factorial Method    
    // and append it to the end of the list
    Str fac := factorial(n).toStr
    series.append(fac, 0, fac.size)    
    // return the list as a string    
    return series.toStr  
  }    
  
  // Using a StringBuffer as a list of string elements    
  static Str getFibonnaciSeries(Int n)    
  {    
    // Create the String that will hold the list    
    StringBuffer series := StringBuffer()    
    // We begin by concatenating the first 3 values which    
    // are always constant    
    series.append("0, 1, 1", 0, 7)  
    // Then we calculate the Fibonacci of each element    
    // and add append it to the list
    Str fib := ""
    for (i := 2; i &amp;lt;= n; i++)
    {    
      if (i &amp;lt; n)    
        series.append(", ", 0, 2)
      else    
        series.append(" = ", 0, 3)
      
      fib = fibonacci(i).toStr
      series.append(fib, 0, fib.size)  
    }    
    // return the list as a string    
    return series.toStr
  }    
  
  static BigInteger factorial(Int n)    
  {    
    if (n == 1)      
      return BigInteger.ONE
    else      
      return BigInteger.valueOf(n).multiply(factorial(n - 1))  
  }            
  
  static Int fibonacci(Int n)    
  {    
    if (n &amp;lt; 2)
      return 1  
    else      
      return fibonacci(n - 1) + fibonacci(n - 2)  
  }       
}    
  
// Console Program  
public class FiborialSeriesApp    
{    
  public static Void main()    
  {  
    // Printing Factorial Series    
    echo("")  
    echo(Fiborial.getFactorialSeries(5))   
    echo(Fiborial.getFactorialSeries(7)) 
    echo(Fiborial.getFactorialSeries(9)) 
    echo(Fiborial.getFactorialSeries(11)) 
    echo(Fiborial.getFactorialSeries(40))  
    // Printing Fibonacci Series    
    echo("")  
    echo(Fiborial.getFibonnaciSeries(5)) 
    echo(Fiborial.getFibonnaciSeries(7)) 
    echo(Fiborial.getFibonnaciSeries(9)) 
    echo(Fiborial.getFibonnaciSeries(11))  
    echo(Fiborial.getFibonnaciSeries(40)) 
  }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:









&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-awTTdPtMwtQ/TzLfyQPrhyI/AAAAAAAAGM8/Og8fMC2ZKQI/s1600/FiborialSeriesFantom.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="271" src="http://3.bp.blogspot.com/-awTTdPtMwtQ/TzLfyQPrhyI/AAAAAAAAGM8/Og8fMC2ZKQI/s640/FiborialSeriesFantom.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, getters, constructors/initializers, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Instance Class  
class Fiborial
{  
  // Instance Field  
  private Int instanceCount  
  // Static Field
  // Static field 'staticCount' must be const
  private const static Int staticCount
  // Instance Read-Only Property   
  Int InstanceCount
  {
    get { return &amp;amp;instanceCount }  
  }  
  // Static Fields need to be const. A static const cannot have getter
  // using Static Read-Only Getter instead  
  // As with Static Methods, you cannot reference your class members  
  // with the "this" reference pointer since static members are not  
  // instantiated.  
  /*static Int StaticCount
  {    
    get { return &amp;amp;staticCount }    
  }*/
  static Int getStaticCount() 
  {
    return staticCount
  }
  // Instance Constructor  
  new make() 
  {  
    this.instanceCount = 0  
    echo("\nInstance Constructor ${this.instanceCount}")  
  }  
  // Static Constructor
  // Static constructors are methods executed to initialize the class itself. 
  // They are typically used to initialize static fields.
  static  
  {    
    staticCount = 0    
    echo("\nStatic Constructor $staticCount")
  }      
  // Instance Method  
  Void factorial(Int n) 
  {  
    this.instanceCount += 1  
    echo("\nFactorial($n)")  
  }  
  // Static Method  
  static Void fibonacci(Int n) 
  {  
    // Error: 
    // Cannot set const static field 'staticCount' outside of static initializer 
    // (static constructor) so we cannot increment staticCount
    // staticCount += 1  
    echo("\nFibonacci($n)")  
  }  
}

public class FiborialExtrasApp    
{    
  public static Void main()    
  {  
    // Calling Static Constructor and Methods  
    // No need to instantiate  
    Fiborial.fibonacci(5)  
      
    // Calling Instance Constructor and Methods  
    // Instance required  
    Fiborial fib := Fiborial()  
    fib.factorial(5)  
      
    Fiborial.fibonacci(15)  
    fib.factorial(5)  
      
    // Calling Instance Constructor and Methods  
    // for a second object  
    Fiborial fib2 := Fiborial()
    fib2.factorial(5)
      
    echo("")  
    // Calling Static Property  
    echo("Static Count = ${Fiborial.getStaticCount}")  
    // Calling Instance Property of object 1 and 2  
    echo("Instance 1 Count = ${fib.InstanceCount}")  
    echo("Instance 2 Count = ${fib2.InstanceCount}")   
  }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-s6K07kPjrRY/TzLxhXDA4bI/AAAAAAAAGNE/zbnPYATfyec/s1600/FiborialExtrasFantom.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://4.bp.blogspot.com/-s6K07kPjrRY/TzLxhXDA4bI/AAAAAAAAGNE/zbnPYATfyec/s400/FiborialExtrasFantom.png" width="352" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long/sys::Int, java.lang.Double/sys::Float, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using [java] com.carlosqt.util::Stopwatch
using [java] java.math::BigInteger

public class FiborialTypesApp    
{    
  public static Void main()    
  {     
    Stopwatch timer := Stopwatch()    
    Int facIntResult := 0
    Float facDblResult := 0f    
    BigInteger facBigResult := BigInteger.ZERO 
    
    echo("\nFactorial using Int64")  
    // Benchmark Factorial using Int64    
    for (i := 5; i &amp;lt;= 50; i += 5)    
    {    
      timer.start
      facIntResult = factorialInt64(i)    
      timer.stop    
      echo(" ($i) = ${timer.getElapsed} : $facIntResult")  
    }    
    echo("\nFactorial using Float/Double")
    // Benchmark Factorial using Double    
    for (i := 5; i &amp;lt;= 50; i += 5)    
    {    
      timer.start    
      facDblResult = factorialDouble(i)    
      timer.stop                
      echo(" ($i) = ${timer.getElapsed} : $facDblResult")  
    }    
    echo("\nFactorial using BigInteger")    
    // Benchmark Factorial using BigInteger    
    for (i := 5; i &amp;lt;= 50; i += 5)    
    {    
      timer.start();    
      facBigResult = factorialBigInteger(i);    
      timer.stop();    
      echo(" ($i) = ${timer.getElapsed} : $facBigResult")
    }            
  }  
      
  // Int64 Factorial    
  static Int factorialInt64(Int n)    
  {    
    if (n == 1)    
      return 1
    else    
      return n * factorialInt64(n - 1)  
  }  
    
  // Float Factorial  
  static Float factorialDouble(Int n)    
  {    
    if (n == 1)    
      return 1f
    else    
      return n * factorialDouble(n - 1)  
  }  
    
  // BigInteger Factorial   
  static BigInteger factorialBigInteger(Int n)    
  {    
    if (n == 1)    
      return BigInteger.ONE  
    else    
      return BigInteger.valueOf(n).multiply(factorialBigInteger(n - 1))
  }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-lmE5UIi6e-o/TzL1frLSuFI/AAAAAAAAGNM/NpN6vDZzPw8/s1600/FiborialTypesFantom.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="515" src="http://1.bp.blogspot.com/-lmE5UIi6e-o/TzL1frLSuFI/AAAAAAAAGNM/NpN6vDZzPw8/s640/FiborialTypesFantom.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/NaMvo6XHdLI" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7944302213515455918/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-fantom.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7944302213515455918?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7944302213515455918?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/NaMvo6XHdLI/factorial-and-fibonacci-in-fantom.html" title="Factorial and Fibonacci in Fantom" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-rXPtVanxqVU/TzLWep1p1aI/AAAAAAAAGM0/z08dJNRaqmg/s72-c/fiborial_fantom.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-fantom.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUEQ386cSp7ImA9WhJRGU0.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7071917279395530624</id><published>2012-02-05T03:29:00.000-08:00</published><updated>2012-07-21T15:03:22.119-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-07-21T15:03:22.119-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><category scheme="http://www.blogger.com/atom/ns#" term="Gosu" /><title>Factorial and Fibonacci in Gosu</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Gosu that implements 2 classes (in fact, they are 3 + an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Factorial and Fibonacci in Gosu
package com.series
uses com.series.Stopwatch
uses java.math.BigInteger
uses java.util.Scanner
uses java.lang.System

// static class
static class StaticFiborial {
  // Static Field
  private static var className: String = &amp;quot;Static Constructor&amp;quot;
  //  no available static constructor support
  // you can initialize your static fields instead
  /*static construct() {  // error: constructors cannot be static
    className = &amp;quot;Static Constructor&amp;quot;;
    print(className)
  }*/
  // Static Method - Factorial Recursive
  static function factorialR( n : int ) : BigInteger {
    if (n == 1) {
      return BigInteger.ONE
    }
    else {
      return BigInteger.valueOf(n).multiply(factorialR(n - 1))
    }
  }
  // Class/Static Method - Factorial Imperative
  static function factorialI( n : int ) : BigInteger {
    var res = BigInteger.ONE
    while (n &amp;gt; 1) {
      res = res.multiply(BigInteger.valueOf(n))
      n -= 1
    }
    return res
  }
  // Static Method - Fibonacci Recursive
  static function fibonacciR( n : int ) : long {
    if (n &amp;lt; 2) {
      return 1
    }
    else {
      return fibonacciR(n - 1) + fibonacciR(n - 2)
    }
  }
  // Static Method - Fibonacci Imperative
  static function fibonacciI( n : int ) : long {
    var pre : long = 1
    var cur : long = 1
    var tmp : long = 0
    for ( i in 2..n ) {
      tmp = cur + pre
      pre = cur
      cur = tmp
    }
    return cur
  }
  // Static Method - Benchmarking Algorithms
  static function benchmarkAlgorithm( algorithm : int, values : List&amp;lt;int&amp;gt;) {
    var timer = new Stopwatch()
    var testValue = 0
    var facTimeResult : BigInteger = BigInteger.ZERO
    var fibTimeResult : long = 0
    // &amp;quot;Switch&amp;quot; Flow Control Statement
    switch (algorithm)
    {
      case 1:
          print(&amp;quot;\nFactorial Imperative:&amp;quot;)
          // &amp;quot;For&amp;quot; Loop Statement
          for (i in 0..values.size()-1) {
            testValue = values.get(i).intValue()
            // Taking Time
            timer.start()
            facTimeResult = factorialI(testValue)
            timer.stop()
            // Getting Time
            print(&amp;quot; (${testValue}) = ${timer.getElapsed()}&amp;quot;)
          }
          break
      case 2:
          print(&amp;quot;\nFactorial Recursive:&amp;quot;)
          // &amp;quot;While&amp;quot; Loop Statement
          var i = 0
          while ( i &amp;lt; values.size() ) {
            testValue = values.get(i).intValue()
            // Taking Time
            timer.start()
            facTimeResult = factorialR(testValue)
            timer.stop()
            // Getting Time
            print(&amp;quot; (${testValue}) = ${timer.getElapsed()}&amp;quot;)
            i++
          }
          break
      case 3:
          print(&amp;quot;\nFibonacci Imperative:&amp;quot;)
          // &amp;quot;Do-While&amp;quot; Loop Statement
          var i = 0
          do {
            testValue = values.get(i).intValue()
            // Taking Time
            timer.start()
            fibTimeResult = fibonacciI(testValue)
            timer.stop()
            // Getting Time
            print(&amp;quot; (${testValue}) = ${timer.getElapsed()}&amp;quot;)
            i++
          } while (i &amp;lt; values.size());
          break
      case 4:
          print(&amp;quot;\nFibonacci Recursive:&amp;quot;)
          // &amp;quot;For Each&amp;quot; Loop Statement
          for (item in values) {
            testValue = item
            // Taking Time
            timer.start()
            facTimeResult = fibonacciR(testValue)
            timer.stop()
            // Getting Time
            print(&amp;quot; (${testValue}) = ${timer.getElapsed()}&amp;quot;)
          }
          break
    }
  }
}

// Instance Class
class InstanceFiborial {
  // Instance Field
  private var className : String
  // Instance Constructor
  construct() {
    this.className = &amp;quot;Instance Constructor&amp;quot;
    print(this.className)
  }
  // Instance Method - Factorial Recursive
  function factorialR( n : int ) : BigInteger {
    // Calling Static Method
    return StaticFiborial.factorialR(n)
  }
  // Instance Method - Factorial Imperative
  function factorialI( n : int ) : BigInteger {
    // Calling Static Method
    return StaticFiborial.factorialI(n)
  }
  // Instance Method - Fibonacci Recursive
  function fibonacciR( n : int ) : long {
    // Calling Static Method
    return StaticFiborial.fibonacciR(n)
  }
  // Instance Method - Factorial Imperative
  function fibonacciI( n : int ) : long {
    // Calling Static Method
    return StaticFiborial.fibonacciI(n)
  }
}

// Console Program
print(&amp;quot;Static Class&amp;quot;)
//Calling Static Class and Methods
//No instantiation needed. Calling method directly from the class
print(&amp;quot;FacImp(5) = &amp;quot; + StaticFiborial.factorialI(5))
print(&amp;quot;FacRec(5) = &amp;quot; + StaticFiborial.factorialR(5))
print(&amp;quot;FibImp(11)= &amp;quot; + StaticFiborial.fibonacciI(11))
print(&amp;quot;FibRec(11)= &amp;quot; + StaticFiborial.fibonacciR(11))

print(&amp;quot;\nInstance Class&amp;quot;)
//Calling Instance Class and Methods
//Need to instantiate before using. Calling method from instantiated object
var ff = new InstanceFiborial()
print(&amp;quot;FacImp(5) = ${ff.factorialI(5)}&amp;quot;)
print(&amp;quot;FacRec(5) = ${ff.factorialR(5)}&amp;quot;)
print(&amp;quot;FibImp(11)= ${ff.fibonacciI(11)}&amp;quot;)
print(&amp;quot;FibRec(11)= ${ff.fibonacciR(11)}&amp;quot;)

//Create a (generic) list of values to test
//From 5 to 50 by 5
var values = new List&amp;lt;int&amp;gt;()
var i = 5
while (i &amp;lt; 55) {
  values.add(i)
  i+=5
}

// Benchmarking Fibonacci
// 1 = Factorial Imperative
StaticFiborial.benchmarkAlgorithm(1, values)
// 2 = Factorial Recursive
StaticFiborial.benchmarkAlgorithm(2, values)

// Benchmarking Factorial
// 3 = Fibonacci Imperative
StaticFiborial.benchmarkAlgorithm(3, values)
// 4 = Fibonacci Recursive
StaticFiborial.benchmarkAlgorithm(4, values)

// Stop and exit
var sin = new Scanner(System.in)
var line = sin.nextLine()
sin.close()
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-RHilb6sjRnI/Ty2bJ9kFRoI/AAAAAAAAGMU/de5238sgIxk/s1600/fiborial_gosu.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-RHilb6sjRnI/Ty2bJ9kFRoI/AAAAAAAAGMU/de5238sgIxk/s1600/fiborial_gosu.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
uses java.math.BigInteger
uses java.lang.StringBuffer

static class Fiborial {
  // Using a StringBuffer as a list of string elements
  static function getFactorialSeries( n : int ) : String {
    // Create the String that will hold the list
    var series = new StringBuffer()
    // We begin by concatenating the number you want to calculate
    // in the following format: "!# ="
    series.append("!")
    series.append(n)
    series.append(" = ")
    // We iterate backwards through the elements of the series
    for (i in n..0){
      // and append it to the list
      series.append(i)
      if (i &amp;gt; 1)
        series.append(" * ")
      else
        series.append(" = ")
    }
    // Get the result from the Factorial Method
    // and append it to the end of the list
    series.append(factorial(n).toString())
    // return the list as a string
    return series.toString()
  }

  // Using a StringBuffer as a list of string elements
  static function getFibonnaciSeries( n : int ) : String {
    // Create the String that will hold the list
    var series = new StringBuffer()
    // We begin by concatenating the first 3 values which
    // are always constant
    series.append("0, 1, 1")
    // Then we calculate the Fibonacci of each element
    // and add append it to the list
    for (i in 2..n) {
      if (i &amp;lt; n)
        series.append(", ")
      else
        series.append(" = ")
      series.append(fibonacci(i))
    }
    // return the list as a string
    return series.toString()
  }

  static function factorial( n : int  ) : BigInteger {
    if (n == 1)
      return BigInteger.ONE
    else
      return BigInteger.valueOf(n).multiply(factorial(n - 1))
  }

  static function fibonacci( n : int ) : long {
    if (n &amp;lt; 2)
      return 1
    else
      return fibonacci(n - 1) + fibonacci(n - 2)
  }
}

// Printing Factorial Series
print("")
print(Fiborial.getFactorialSeries(5))
print(Fiborial.getFactorialSeries(7))
print(Fiborial.getFactorialSeries(9))
print(Fiborial.getFactorialSeries(11))
print(Fiborial.getFactorialSeries(40))
// Printing Fibonacci Series
print("")
print(Fiborial.getFibonnaciSeries(5))
print(Fiborial.getFibonnaciSeries(7))
print(Fiborial.getFibonnaciSeries(9))
print(Fiborial.getFibonnaciSeries(11))
print(Fiborial.getFibonnaciSeries(40))
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:








&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-InprhZCuVT4/Ty2o5Z4QRAI/AAAAAAAAGMc/OfJCLIW5sjA/s1600/FiborialSeriesGosu.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="294" src="http://1.bp.blogspot.com/-InprhZCuVT4/Ty2o5Z4QRAI/AAAAAAAAGMc/OfJCLIW5sjA/s640/FiborialSeriesGosu.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors/initializers, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;// Fiborial.gs
package com.series

// Instance Class
class Fiborial {
  // Instance Field
  private var _instanceCount : int
  // Static Field - no static constructor so it needs to be initialized here
  private static var _staticCount : int = 0
  // Instance Read-Only Property
  // Within instance members, you can always use
  // the "this" reference pointer to access your (instance) members.
  property get InstanceCount() : int {
    return this._instanceCount
  }
  // Static Read-Only Getter
  // As with Static Methods, you cannot reference your class members
  // with the "this" reference pointer since static members are not
  // instantiated.
  static property get StaticCount() : int {
    return _staticCount
  }
  // Instance Constructor
  construct() {
    this._instanceCount = 0
    print("\nInstance Constructor ${this.instanceCount}")
  }
  // Static Constructor
  // not supported in Gosu. Constructor cannot be static.
  /*static construct() {
    staticCount = 0;
    print("\nStatic Constructor $staticCount")
  }
  */
  // Instance Method
  function factorial( n : int ) {
    this._instanceCount += 1
    print("\nFactorial(${n})")
  }
  // Static Method
  static function fibonacci( n : int ) {
    _staticCount += 1
    print("\nFibonacci(${n})")
  }
}
&lt;/pre&gt;
&lt;pre class="javascript" name="code"&gt;// FiborialExtrasApp.gsp
package com.series

// Calling Static Constructor and Methods
// No need to instantiate
Fiborial.fibonacci(5)

// Calling Instance Constructor and Methods
// Instance required
var fib = new Fiborial()
fib.factorial(5)

Fiborial.fibonacci(15)
fib.factorial(5)

// Calling Instance Constructor and Methods
// for a second object
var fib2 = new Fiborial()
fib2.factorial(5)

print("")
// Calling Static Property
print("Static Count = ${Fiborial.getStaticCount()}")
// Calling Instance Property of object 1 and 2
print("Instance 1 Count = ${fib.getInstanceCount()}")
print("Instance 2 Count = ${fib2.getInstanceCount()}")
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-Laj7boTaId8/Ty5ip7nx2FI/AAAAAAAAGMk/bO6mW_lg0nw/s1600/FiborialExtrasGosu.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-Laj7boTaId8/Ty5ip7nx2FI/AAAAAAAAGMk/bO6mW_lg0nw/s400/FiborialExtrasGosu.png" width="373" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="javascript" name="code"&gt;package com.series
uses java.math.BigInteger
uses com.series.Stopwatch

// Long Factorial
function factorialInt64( n : int ) : long
{
  if (n == 1)
    return 1
  else
    return n * factorialInt64(n - 1)
}

// Double Factorial
function factorialDouble( n : int ) : double
{
  if (n == 1)
    return 1
  else
    return n * factorialDouble(n - 1)
}

// BigInteger Factorial
function factorialBigInteger( n : int ) : BigInteger
{
  if (n == 1)
    return BigInteger.ONE
  else
    return BigInteger.valueOf(n).multiply(factorialBigInteger(n - 1))
}

var timer = new Stopwatch()
var facIntResult : long = 0
var facDblResult : double = 0
var facBigResult = BigInteger.ZERO

print("\nFactorial using Int64")
// Benchmark Factorial using Int64
var i = 5
while (i &amp;lt; 55) {
  timer.start()
  facIntResult = factorialInt64(i)
  timer.stop()
  print(" (${i}) = ${timer.getElapsed()} : ${facIntResult}")
  i += 5
}
print("\nFactorial using Double")
// Benchmark Factorial using Double
i = 5
while (i &amp;lt; 55) {
  timer.start()
  facDblResult = factorialDouble(i)
  timer.stop()
  print(" (${i}) = ${timer.getElapsed()} : ${facDblResult}")
  i += 5
}
print("\nFactorial using BigInteger")
// Benchmark Factorial using BigInteger
i = 5
while (i &amp;lt; 55) {
  timer.start()
  facBigResult = factorialBigInteger(i)
  timer.stop()
  print(" (${i}) = ${timer.getElapsed()} : ${facBigResult}")
  i += 5
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-MLOJvE8Emnw/Ty5n3r0EpHI/AAAAAAAAGMs/_qUF6_Hg1rI/s1600/FiborialTypesGosu.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="582" src="http://1.bp.blogspot.com/-MLOJvE8Emnw/Ty5n3r0EpHI/AAAAAAAAGMs/_qUF6_Hg1rI/s640/FiborialTypesGosu.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/NCrnLruKSHo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7071917279395530624/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-gosu.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7071917279395530624?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7071917279395530624?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/NCrnLruKSHo/factorial-and-fibonacci-in-gosu.html" title="Factorial and Fibonacci in Gosu" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-RHilb6sjRnI/Ty2bJ9kFRoI/AAAAAAAAGMU/de5238sgIxk/s72-c/fiborial_gosu.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/02/factorial-and-fibonacci-in-gosu.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkcBRH88cCp7ImA9WhJRE00.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-6982556151800903228</id><published>2012-01-20T15:47:00.000-08:00</published><updated>2012-07-14T15:14:15.178-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-07-14T15:14:15.178-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Groovy" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Groovy</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Groovy that implements 2 classes (in fact, they are 3 + an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="groovy" name="code"&gt;// Factorial and Fibonacci in Groovy  
package com.series  
import java.math.BigInteger  
  
// Instance Class  
class StaticFiborial    
{      
    // Static Field      
    private static className  
    // Class/Static Constructor/Initializer    
    static    
    {      
        className = &amp;quot;Static Constructor&amp;quot;  
        println className  
    }      
    // Class/Static Method - Factorial Recursive      
    static factorialR(int n)      
    {      
        if (n == 1)      
            return BigInteger.ONE  
        else      
            return n * factorialR(n - 1)  
    }      
    // Class/Static Method - Factorial Imperative      
    static factorialI(int n)      
    {      
        def res = BigInteger.ONE  
        for (int i = n; i &amp;gt;= 1; i--)      
        {                      
            res *= i  
        }      
        return res  
    }      
    // Class/Static Method - Fibonacci Recursive      
    static fibonacciR(int n)      
    {      
        if (n &amp;lt; 2)      
            return 1  
        else      
            return fibonacciR(n - 1) + fibonacciR(n - 2)  
    }      
    // Class/Static Method - Fibonacci Imperative      
    static fibonacciI(int n)      
    {                  
        def pre, cur, tmp = 0  
        pre = cur = 1          
        for (i in 2..n)  
        {      
            tmp = cur + pre  
            pre = cur  
            cur = tmp  
        }      
        return cur    
    }          
    // Class/Static Method - Benchmarking Algorithms      
    static benchmarkAlgorithm(algorithm, values)      
    {                  
        def timer = new Stopwatch()  
        def i, testValue  
        def facTimeResult = BigInteger.ZERO  
        def fibTimeResult = 0  
        i = testValue = 0              
              
        // &amp;quot;Switch&amp;quot; Flow Control Statement      
        switch (algorithm)      
        {      
            case 1:      
                println &amp;quot;\nFactorial Imperative:&amp;quot;  
                // &amp;quot;For&amp;quot; Loop Statement      
                for (i = 0; i &amp;lt; values.size(); i++)      
                {                              
                    testValue = ((Integer)values.get(i)).intValue()  
                    // Taking Time      
                    timer.start()  
                    facTimeResult = factorialI(testValue)  
                    timer.stop()      
                    // Getting Time      
                    println &amp;quot; ($testValue) = ${timer.getElapsed()}&amp;quot;  
                }                          
                break      
            case 2:      
                println &amp;quot;\nFactorial Recursive:&amp;quot;  
                // &amp;quot;While&amp;quot; Loop Statement      
                while (i &amp;lt; values.size())      
                {                              
                    testValue = ((Integer)values.get(i)).intValue()  
                    // Taking Time      
                    timer.start()  
                    facTimeResult = factorialR(testValue)  
                    timer.stop()  
                    // Getting Time      
                    println &amp;quot; ($testValue) = ${timer.getElapsed()}&amp;quot;  
                    i++  
                }      
                break     
            case 3:      
                println &amp;quot;\nFibonacci Imperative:&amp;quot;  
                // &amp;quot;For&amp;quot; Loop Statement      
                for (j in 0..values.size()-1)  
                {   
                    testValue = ((Integer)values.get(j)).intValue()  
                    // Taking Time  
                    timer.start()  
                    fibTimeResult = fibonacciI(testValue)  
                    timer.stop()  
                    // Getting Time      
                    println &amp;quot; ($testValue) = ${timer.getElapsed()}&amp;quot;                      
                }                  
                break  
            case 4:      
                println &amp;quot;\nFibonacci Recursive:&amp;quot;  
                // &amp;quot;For Each&amp;quot; Loop Statement                      
                for (item in values)  
                {      
                    testValue = item  
                    // Taking Time      
                    timer.start()    
                    fibTimeResult = fibonacciR(testValue)  
                    timer.stop()  
                    // Getting Time  
                    println &amp;quot; ($testValue) = ${timer.getElapsed()}&amp;quot;  
                }   
                break  
            default:      
                println &amp;quot;DONG!&amp;quot;  
                break  
        }   
    }      
}  
  
// Instance Class      
class InstanceFiborial      
{      
    // Instance Field      
    private def className  
    // Instance Constructor      
    def InstanceFiborial()      
    {      
        this.className = &amp;quot;Instance Constructor&amp;quot;  
        println this.className  
    }      
    // Instance Method - Factorial Recursive      
    def factorialR(n)      
    {      
        // Calling Static Method      
        return StaticFiborial.factorialR(n)  
    }      
    // Instance Method - Factorial Imperative      
    def factorialI(n)      
    {      
        // Calling Static Method      
        return StaticFiborial.factorialI(n)      
    }      
    // Instance Method - Fibonacci Recursive  
    def fibonacciR(n)      
    {      
        // Calling Static Method      
        return StaticFiborial.fibonacciR(n)  
    }      
    // Instance Method - Factorial Imperative      
    def fibonacciI(n)      
    {      
        // Calling Static Method      
        return StaticFiborial.fibonacciI(n)  
    }      
}    
  
  
println &amp;quot;\nStatic Class&amp;quot;      
// Calling Static Class and Methods  
// No instantiation needed. Calling method directly from the class      
println &amp;quot;FacImp(5) = ${StaticFiborial.factorialI(5)}&amp;quot;  
println &amp;quot;FacRec(5) = ${StaticFiborial.factorialR(5)}&amp;quot;      
println &amp;quot;FibImp(11)= ${StaticFiborial.fibonacciI(11)}&amp;quot;      
println &amp;quot;FibRec(11)= ${StaticFiborial.fibonacciR(11)}&amp;quot;  
  
println &amp;quot;\nInstance Class&amp;quot;      
// Calling Instance Class and Methods       
// Need to instantiate before using. Calling method from instantiated object      
def ff = new InstanceFiborial()  
println &amp;quot;FacImp(5) = ${ff.factorialI(5)}&amp;quot;  
println &amp;quot;FacRec(5) = ${ff.factorialR(5)}&amp;quot;  
println &amp;quot;FibImp(11)= ${ff.fibonacciI(11)}&amp;quot;  
println &amp;quot;FibRec(11)= ${ff.fibonacciR(11)}&amp;quot;  
  
// Create a list of integer values to test  
// From 5 to 50 by 5      
def values = []  
5.step(55, 5) {  
    values.add(it)  
}  
  
// Benchmarking Fibonacci                           
// 1 = Factorial Imperative                  
StaticFiborial.benchmarkAlgorithm(1, values)  
// 2 = Factorial Recursive      
StaticFiborial.benchmarkAlgorithm(2, values)  
  
// Benchmarking Factorial                  
// 3 = Fibonacci Imperative      
StaticFiborial.benchmarkAlgorithm(3, values)  
// 4 = Fibonacci Recursive      
StaticFiborial.benchmarkAlgorithm(4, values)  
  
// Stop and exit      
println &amp;quot;Press any key to exit...&amp;quot;    
def sin = new Scanner(System.in)    
def line = sin.nextLine()    
sin.close()
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-rlbleL3PwXg/TxneTH-aNmI/AAAAAAAAGLw/4esHJ9f0gjc/s1600/fiborial_groovy.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/-rlbleL3PwXg/TxneTH-aNmI/AAAAAAAAGLw/4esHJ9f0gjc/s1600/fiborial_groovy.PNG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="groovy" name="code"&gt;package com.series  
import java.math.BigInteger    
import java.lang.StringBuffer  
    
class Fiborial    
{    
    // Using a StringBuffer as a list of string elements    
    static getFactorialSeries(n)    
    {    
        // Create the String that will hold the list    
        def series = new StringBuffer()  
        // We begin by concatenating the number you want to calculate    
        // in the following format: &amp;quot;!# =&amp;quot;    
        series.append(&amp;quot;!&amp;quot;)  
        series.append(n)  
        series.append(&amp;quot; = &amp;quot;)  
        // We iterate backwards through the elements of the series    
        for (i in n..0)  
        {    
            // and append it to the list    
            series.append(i)  
            if (i &amp;gt; 1)  
                series.append(&amp;quot; * &amp;quot;)  
            else     
                series.append(&amp;quot; = &amp;quot;)  
        }  
        // Get the result from the Factorial Method    
        // and append it to the end of the list    
        series.append(factorial(n))    
        // return the list as a string    
        return series
    }    
    
    // Using a StringBuffer as a list of string elements    
    static getFibonnaciSeries(n)    
    {    
        // Create the String that will hold the list    
        def series = new StringBuffer();    
        // We begin by concatenating the first 3 values which    
        // are always constant    
        series.append(&amp;quot;0, 1, 1&amp;quot;)  
        // Then we calculate the Fibonacci of each element    
        // and add append it to the list    
        for (i in 2..n)  
        {    
            if (i &amp;lt; n)    
                series.append(&amp;quot;, &amp;quot;)  
            else    
                series.append(&amp;quot; = &amp;quot;)  
                
            series.append(fibonacci(i))  
        }    
        // return the list as a string    
        return series    
    }    
    
    static factorial(n)    
    {    
        if (n == 1)      
            return BigInteger.ONE  
        else      
            return n * factorial(n - 1)  
    }            
    
    static fibonacci(n)    
    {    
        if (n &amp;lt; 2)      
            return 1  
        else      
            return fibonacci(n - 1) + fibonacci(n - 2)  
    }       
}    
  
  
// Printing Factorial Series    
println &amp;quot;&amp;quot;
println Fiborial.getFactorialSeries(5)    
println Fiborial.getFactorialSeries(7)  
println Fiborial.getFactorialSeries(9)  
println Fiborial.getFactorialSeries(11)  
println Fiborial.getFactorialSeries(40)  
// Printing Fibonacci Series    
println &amp;quot;&amp;quot;  
println Fiborial.getFibonnaciSeries(5)  
println Fiborial.getFibonnaciSeries(7)  
println Fiborial.getFibonnaciSeries(9)  
println Fiborial.getFibonnaciSeries(11)  
println Fiborial.getFibonnaciSeries(40)
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:








&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-H7Nl69131To/TxnrM-GrWlI/AAAAAAAAGL4/iM1JOrciF3A/s1600/FiborialSeriesGroovy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="297" src="http://3.bp.blogspot.com/-H7Nl69131To/TxnrM-GrWlI/AAAAAAAAGL4/iM1JOrciF3A/s640/FiborialSeriesGroovy.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, getters/setters, constructors/initializers, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="groovy" name="code"&gt;package com.series

// Instance Class    
class Fiborial    
{    
    // Instance Field    
    private def instanceCount    
    // Static Field    
    private static staticCount
    // Instance Read-Only Getter    
    // Within instance members, you can always use      
    // the "this" reference pointer to access your (instance) members.    
    def getInstanceCount()  
    {    
        return this.instanceCount     
    }    
    // Static Read-Only Getter        
    // As with Static Methods, you cannot reference your class members    
    // with the "this" reference pointer since static members are not    
    // instantiated.            
    static getStaticCount()  
    {    
        return staticCount    
    }    
    // Instance Constructor    
    def Fiborial()    
    {    
        this.instanceCount = 0
        println "\nInstance Constructor ${this.instanceCount}"
    }    
    // Static Constructor    
    static
    {    
        staticCount = 0;    
        println "\nStatic Constructor $staticCount"    
    }    
  
    // Instance Method    
    def factorial(n)    
    {    
        this.instanceCount += 1
        println "\nFactorial($n)"
    }    
  
    // Static Method    
    static fibonacci(n)    
    {    
        staticCount += 1    
        println "\nFibonacci($n)"
    }                    
}  

// Calling Static Constructor and Methods    
// No need to instantiate    
Fiborial.fibonacci(5)

// Calling Instance Constructor and Methods
// Instance required    
def fib = new Fiborial()
fib.factorial(5)           

Fiborial.fibonacci(15)
fib.factorial(5)

// Calling Instance Constructor and Methods    
// for a second object    
def fib2 = new Fiborial()
fib2.factorial(5)

println ""
// Calling Static Property    
println "Static Count = ${Fiborial.getStaticCount()}}"
// Calling Instance Property of object 1 and 2    
println "Instance 1 Count = ${fib.getInstanceCount()}"
println "Instance 2 Count = ${fib2.getInstanceCount()}"
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-N-Dwu_3qHxQ/TxnycZfo0mI/AAAAAAAAGMA/AmgT2atzzwI/s1600/FiborialExtrasGroovy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-N-Dwu_3qHxQ/TxnycZfo0mI/AAAAAAAAGMA/AmgT2atzzwI/s320/FiborialExtrasGroovy.png" width="306" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="groovy" name="code"&gt;package com.series    
import java.math.BigInteger  
      
// Long Factorial      
long factorialInt64(n)      
{      
    if (n == 1)      
        return 1    
    else      
        return n * factorialInt64(n - 1)    
}    
  
// Double Factorial    
double factorialDouble(n)      
{      
    if (n == 1)      
        return 1  
    else      
        return n * factorialDouble(n - 1)  
}    
  
// BigInteger Factorial     
BigInteger factorialBigInteger(n)      
{      
    if (n == 1)      
        return BigInteger.ONE  
    else      
        return n * factorialBigInteger(n - 1)
}    
  
def timer = new Stopwatch()  
long facIntResult = 0     
double facDblResult = 0  
def facBigResult = BigInteger.ZERO      
  
println &amp;quot;\nFactorial using Int64&amp;quot;  
// Benchmark Factorial using Int64      
for (i in (5..50).step(5)) {      
    timer.start()  
    facIntResult = factorialInt64(i)  
    timer.stop()      
    println &amp;quot; ($i) = ${timer.getElapsed()} : ${facIntResult}&amp;quot;    
}      
println &amp;quot;\nFactorial using Double&amp;quot;  
// Benchmark Factorial using Double      
for (i in (5..50).step(5)) {      
    timer.start()  
    facDblResult = factorialDouble(i)  
    timer.stop()  
    println &amp;quot; ($i) = ${timer.getElapsed()} : ${facDblResult}&amp;quot;  
}      
println &amp;quot;\nFactorial using BigInteger&amp;quot;  
// Benchmark Factorial using BigInteger      
for (i in (5..50).step(5)) {      
    timer.start()  
    facBigResult = factorialBigInteger(i)  
    timer.stop()  
    println &amp;quot; ($i) = ${timer.getElapsed()} : ${facBigResult}&amp;quot;              
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-D6rlPH3cYEA/Txn8wTpACQI/AAAAAAAAGMI/jGrp0RTNhGI/s1600/FiborialTypesGroovy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="577" src="http://4.bp.blogspot.com/-D6rlPH3cYEA/Txn8wTpACQI/AAAAAAAAGMI/jGrp0RTNhGI/s640/FiborialTypesGroovy.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Ir1lzEwcUoo" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/6982556151800903228/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/01/factorial-and-fibonacci-in-groovy.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/6982556151800903228?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/6982556151800903228?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Ir1lzEwcUoo/factorial-and-fibonacci-in-groovy.html" title="Factorial and Fibonacci in Groovy" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-rlbleL3PwXg/TxneTH-aNmI/AAAAAAAAGLw/4esHJ9f0gjc/s72-c/fiborial_groovy.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/01/factorial-and-fibonacci-in-groovy.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0YNQn05fCp7ImA9WhRbFEk.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-4492672056567259839</id><published>2012-01-10T23:37:00.000-08:00</published><updated>2012-02-05T05:39:53.324-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-02-05T05:39:53.324-08:00</app:edited><title /><content type="html">&lt;br /&gt;
Hi Everyone! Happy and successful 2012 to all of you!&lt;br /&gt;
&lt;br /&gt;
Last couple of months I haven't been active on this blog, I had a busy end of year plus December &amp;nbsp;holidays on where I hardly touched the keyboard :) anyway, I have noticed, thanks to google analytics, that many people had visited this blog from all around the world since I created it (2009-Today) (see below). &lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-Sqx4isoMmzE/Tw02_0K0zRI/AAAAAAAAGLc/znOfGFHwqZo/s1600/visits_all_time.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img border="0" height="246" src="http://4.bp.blogspot.com/-Sqx4isoMmzE/Tw02_0K0zRI/AAAAAAAAGLc/znOfGFHwqZo/s400/visits_all_time.png" width="400" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-1semAusKLcA/Tw03A_T5xWI/AAAAAAAAGLk/tVsVGytRw9o/s1600/pages_vues_par_pays.png" imageanchor="1" style="clear: left; display: inline !important; margin-bottom: 1em; margin-right: 1em; text-align: center;"&gt;&lt;img border="0" height="400" src="http://1.bp.blogspot.com/-1semAusKLcA/Tw03A_T5xWI/AAAAAAAAGLk/tVsVGytRw9o/s400/pages_vues_par_pays.png" width="252" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style="font-size: x-small;"&gt;Note: The number of visits from Belgium is not real... that is more because I visit it often hehe.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now, to me, this means that I have some public, and that what I'm doing is not meaningless so, this year, I will try to become more active and continue adding more code examples on the current languages and the new ones that appeared during last year and the ones that will show up this year.&lt;br /&gt;
&lt;br /&gt;
So, here are my priorities concerning this blog:&lt;br /&gt;
&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;Finilize the "Factorial and Fibonacci Series" in Groovy, Gosu, Zonnon, Fantom&lt;/li&gt;
&lt;li&gt;Adding Xtend, Ceylon (and Kotlin once released) to the blog posts "OO Hello World", "Basics by Example" and&amp;nbsp;
"Factorial and Fibonacci Series"&lt;/li&gt;
&lt;li&gt;I'm still considering including Oxygene (ObjectPascal/Delphi for the JVM) as a separate language. Since it is exactly the same than Delphi Prism (aka Embarcadero Prism)... I think I won't do it.&lt;/li&gt;
&lt;li&gt;JavaFX Script was deprecated as a language on 2011. I won't post about it any more.&lt;/li&gt;
&lt;li&gt;Will continue updating the Languages Page with the latest releases and languages.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
Voilà! that's it!&lt;br /&gt;
&lt;br /&gt;
Regards!&lt;br /&gt;
Carlos&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/FBdG1lAmm6g" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/4492672056567259839/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2012/01/hi-everyone-happy-and-successfull-2012.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4492672056567259839?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4492672056567259839?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/FBdG1lAmm6g/hi-everyone-happy-and-successfull-2012.html" title="" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://4.bp.blogspot.com/-Sqx4isoMmzE/Tw02_0K0zRI/AAAAAAAAGLc/znOfGFHwqZo/s72-c/visits_all_time.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2012/01/hi-everyone-happy-and-successfull-2012.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YDRn44eip7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2974074228341846556</id><published>2011-10-21T12:53:00.000-07:00</published><updated>2012-03-17T02:06:17.032-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:06:17.032-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="JRuby" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in JRuby</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in JRuby that implements 2 classes. There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally a main function called as module level code.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
WARNING: the code that you will see below is not following ruby guidelines/idiomatic coding, I did it in purpose to compare ruby's syntax and features side by side with other programming languages... For instance, instead of using a ruby bignum I imported and used java.math.BigInteger instead. Other examples, naming convention and so on, so bear with me!&lt;br /&gt;
&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"&gt;I'm using the same Stopwatch java class that I used in the Java version of this post. I just added the .class into a 'target' folder and added it to the classpath. then I java_imported it. &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&amp;nbsp;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;# Factorial and Fibonacci in JRuby  
require "java"    
$CLASSPATH &amp;lt;&amp;lt; "target"
java_import 'Stopwatch'
import java.lang.System
import java.math.BigInteger
    
module FiborialRb  
    # Static Class  
    # static classes are not supported in Ruby  
    class StaticFiborial  
        # Static Field  
        @@class_name = ""  
        # no builtin static constructor/initializer support    
        # you can initialize field at this point and even add extra code           
        @@class_name = "Static Constructor"  
        puts @@class_name  
        # Static Method - Factorial Recursive  
        def self.factorial_r(n)  
            if n &amp;lt; 2  
                BigInteger.new('1')
            else                
                BigInteger.new(n.to_s).multiply(self.factorial_r(n-1))
            end  
        end  
        # Static Method - Factorial Imperative  
        def self.factorial_i(n)  
            res = BigInteger.new('1')
            while n &amp;gt; 1                    
                res = BigInteger.new(res.multiply(n).to_s)
                n -= 1  
            end  
            res  
        end  
        # Static Method - Fibonacci Recursive     
        def self.fibonacci_r(n)  
            if n &amp;lt; 2  
                1  
            else  
                self.fibonacci_r(n - 1) + self.fibonacci_r(n - 2)  
            end  
        end  
        # Static Method - Fibonacci Imperative  
        def self.fibonacci_i(n)  
            pre = 1  
            cur = 1  
            tmp = 0  
            for i in 2..n
                tmp = cur + pre  
                pre = cur  
                cur = tmp  
            end  
            cur  
        end  
        # Static Method - Benchmarking Algorithms  
        def self.benchmark_algorithm(algorithm, values)  
            timer = Stopwatch.new    
            i = 0  
            testValue = 0      
            facTimeResult = BigInteger::ZERO    
            fibTimeResult = 0             
            # "case/switch" Flow Control Statement  
            case algorithm  
            when 1  
                puts "\nFactorial Imperative:"  
                # "For in range" Loop Statement  
                for i in 0..values.size - 1 do  
                    testValue = values[i]                      
                    # Taking Time  
                    timer.start  
                    facTimeResult = self.factorial_i(testValue)      
                    timer.stop  
                    # Getting Time  
                    puts " (#{testValue}) = #{timer.elapsed}"                      
                end  
            when 2  
                puts "\nFactorial Recursive:"  
                # "While" Loop Statement  
                while i &amp;lt; values.size do  
                    testValue = values[i]  
                    # Taking Time  
                    timer.start  
                    facTimeResult = self.factorial_r(testValue)      
                    timer.stop  
                    # Getting Time  
                    puts " (#{testValue}) = #{timer.elapsed}"  
                    i += 1  
                end  
            when 3  
                puts "\nFibonacci Imperative:"  
                # "until" Loop Statement  
                until i == values.size do                      
                    testValue = values[i]  
                    # Taking Time  
                    timer.start  
                    fibTimeResult = self.fibonacci_i(testValue)      
                    timer.stop  
                    # Getting Time  
                    puts " (#{testValue}) = #{timer.elapsed}"  
                    i += 1  
                end  
            when 4  
                puts "\nFibonacci Recursive:"  
                # "For each?" Statement  
                values.each do |testValue|  
                    # Taking Time  
                    timer.start  
                    fibTimeResult = self.fibonacci_r(testValue)      
                    timer.stop  
                    # Getting Time  
                    puts " (#{testValue}) = #{timer.elapsed}"  
                end  
            else  
                puts "DONG!"  
            end  
        end  
    end  
      
    # Instance Class  
    class InstanceFiborial  
        # Instance Field  
        @class_name = ""  
        # Instance Constructor/Initializer  
        def initialize  
            @class_name = "Instance Constructor"  
            puts @class_name  
        end  
        # Instance Method - Factorial Recursive      
        def factorial_r(n)    
            # Calling Static Method      
            StaticFiborial::factorial_r(n)  
        end  
        # Instance Method - Factorial Imperative      
        def factorial_i(n)  
            # Calling Static Method      
            StaticFiborial::factorial_i(n)      
        end  
        # Instance Method - Fibonacci Recursive        
        def fibonacci_r(n)  
            # Calling Static Method      
            StaticFiborial::fibonacci_r(n)      
        end  
        # Instance Method - Fibonacci Imperative      
        def fibonacci_i(n)  
            # Calling Static Method      
            StaticFiborial::fibonacci_i(n)  
        end  
    end  
    
    # Console Program    
    puts "Static Class"      
    # Calling Static Class and Methods      
    # No instantiation needed. Calling method directly from the class      
    puts "FacImp(5) = #{StaticFiborial::factorial_i(5)}"  
    puts "FacRec(5) = #{StaticFiborial::factorial_r(5)}"   
    puts "FibImp(11)= #{StaticFiborial::fibonacci_i(11)}"   
    puts "FibRec(11)= #{StaticFiborial::fibonacci_r(11)}"   
      
    puts "\nInstance Class"  
    # Calling Instance Class and Methods      
    # Need to instantiate before using. Calling method from instantiated object      
    ff = InstanceFiborial.new  
    puts "FacImp(5) = #{ff.factorial_i(5)}"  
    puts "FacRec(5) = #{ff.factorial_r(5)}"  
    puts "FibImp(11)= #{ff.fibonacci_i(11)}"  
    puts "FibRec(11)= #{ff.fibonacci_r(11)}"  
          
    # Create a (Ruby) list of values to test        
    # From 5 to 50 by 5      
    values = []  
    for i in (5..50).step(5)  
        values &amp;lt;&amp;lt; i  
    end  
  
    # Benchmarking Fibonacci      
    # 1 = Factorial Imperative     
    StaticFiborial::benchmark_algorithm(1,values)  
     # 2 = Factorial Recursive  
    StaticFiborial::benchmark_algorithm(2,values)  
    # Benchmarking Factorial      
    # 3 = Fibonacci Imperative   
    StaticFiborial::benchmark_algorithm(3,values)  
    # 4 = Fibonacci Recursive   
    StaticFiborial::benchmark_algorithm(4,values)  
      
    # Stop and exit    
    puts "Press any key to exit..."    
    gets    
end
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:  &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-ChkpeFKUvXQ/Tp84w9JBkZI/AAAAAAAAGHk/-OzaY9Hvw_s/s1600/fiborial_jruby.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-ChkpeFKUvXQ/Tp84w9JBkZI/AAAAAAAAGHk/-OzaY9Hvw_s/s640/fiborial_jruby.PNG" width="294" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;require 'java'
import java.lang.StringBuffer
import java.math.BigInteger

module FiborialSeriesRb

    class Fiborial  
         # Using a StringBuffer as a list of string elements    
         def self.get_factorial_series(n)  
            # Create the String to hold the list        
            series = StringBuffer.new      
            # We begin by concatenating the number you want to calculate        
            # in the following format: "!# ="        
            series.append("!")
            series.append(n)  
            series.append(" = ")  
            # We iterate backwards through the elements of the series  
            i = n  
            while i &amp;gt;= 1  
                # and append it to the list        
                series.append(i)      
                if i &amp;gt; 1       
                    series.append(" * ")        
                else  
                    series.append(" = ")      
                end  
                i -= 1  
            end  
            # Get the result from the Factorial Method        
            # and append it to the end of the list        
            series.append(self.factorial(n).to_s)  
            # return the list as a string  
            series.to_s  
         end  
           
         # Using a StringBuffer as a list of string elements  
         def self.get_fibonnaci_series(n)  
            # Create the String that will hold the list        
            series = StringBuffer.new  
            # We begin by concatenating the first 3 values which        
            # are always constant  
            series.append("0, 1, 1")        
            # Then we calculate the Fibonacci of each element        
            # and add append it to the list        
            for i in 2..n      
                if i &amp;lt; n      
                    series.append(", ")       
                else   
                    series.append(" = ")  
                end  
                series.append(self.fibonacci(i))  
            end  
            # return the list as a string        
            series.to_s    
         end  
           
        def self.factorial(n)  
            if n &amp;lt; 2  
                BigInteger.new('1')
            else  
                BigInteger.new(n.to_s).multiply(self.factorial(n-1))
            end  
        end  
          
        def self.fibonacci(n)
            if n &amp;lt; 2  
                1  
            else  
                self.fibonacci(n - 1) + self.fibonacci(n - 2)  
            end  
        end  
    end  
      
    # Printing Factorial Series        
    puts ""      
    puts Fiborial::get_factorial_series(5)      
    puts Fiborial::get_factorial_series(7)      
    puts Fiborial::get_factorial_series(9)      
    puts Fiborial::get_factorial_series(11)      
    puts Fiborial::get_factorial_series(40)      
    # Printing Fibonacci Series        
    puts ""      
    puts Fiborial::get_fibonnaci_series(5)      
    puts Fiborial::get_fibonnaci_series(7)      
    puts Fiborial::get_fibonnaci_series(9)      
    puts Fiborial::get_fibonnaci_series(11)      
    puts Fiborial::get_fibonnaci_series(40)   
      
    # Stop and exit    
    puts "Press any key to exit..."    
    gets    
end
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-pbUypvoMt1Y/TqHJvqpQdtI/AAAAAAAAGHw/nLjnhWplBVQ/s1600/FiborialSeriesJRuby.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-pbUypvoMt1Y/TqHJvqpQdtI/AAAAAAAAGHw/nLjnhWplBVQ/s640/FiborialSeriesJRuby.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.  &lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;require 'java'
 
# Instance Class    
class Fiborial  
    # Instance Field      
    @instance_count = 0  
    # Static Field  
    @@static_count = 0      
    # Instance Read-Only Getter  
    def get_instance_count()       
        @instance_count      
    end      
    # Static Read-Only Getter  
    def self.get_static_count()
        @@static_count  
    end      
    # Instance Constructor/Initializer  
    def initialize()    
        @instance_count = 0  
        puts "\nInstance Constructor #{@instance_count}"  
    end  
    # No Static Constructor/Initializer  
    # You can do a self.initialize() static method, but it will not be called  
    #def self.initialize()  
    #    @@static_count = 0    
    #    puts "\nStatic Constructor #{@@static_count}"  
    # Instance Method  
    def factorial(n)    
        @instance_count += 1       
        puts "\nFactorial(#{n.to_s})"  
    end  
    # Static Method     
    def self.fibonacci(n)  
        @@static_count += 1      
        puts "\nFibonacci(#{n.to_s})"  
    end          
    
    # Calling Static Constructor and Methods        
    # No need to instantiate        
    Fiborial::fibonacci(5)      
          
    # Calling Instance Constructor and Methods        
    # Instance required        
    fib = Fiborial.new        
    fib.factorial(5)  
    
    Fiborial::fibonacci(15)      
    fib.factorial(5)  
          
    # Calling Instance Constructor and Methods        
    # for a second object        
    fib2 = Fiborial.new     
    fib2.factorial(5)      
          
    puts ""  
    # Calling Static Getter      
    puts "Static Count = #{Fiborial::get_static_count}"   
    # Calling Instance Property of object 1 and 2        
    puts "Instance 1 Count = #{fib.get_instance_count}"  
    puts "Instance 2 Count = #{fib2.get_instance_count}"  
          
    gets  
end
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-PKf3w97RWYY/TqHKtuiheHI/AAAAAAAAGH4/hkUloCVlP6w/s1600/FiborialExtrasJRuby.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="342" src="http://2.bp.blogspot.com/-PKf3w97RWYY/TqHKtuiheHI/AAAAAAAAGH4/hkUloCVlP6w/s400/FiborialExtrasJRuby.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using int, float, System.Numerics.BigInteger&lt;/b&gt;  &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class="Apple-style-span" style="background-color: white; color: #333333; font-family: Georgia, serif; font-size: 13px; line-height: 20px;"&gt;So, it looks like integers in ruby can hold big integers (they are handled as bignum), so using JRuby int/long or java.math.BigInteger is the same so not much to say here.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;require 'java'
$CLASSPATH &amp;lt;&amp;lt; "target"
java_import 'Stopwatch'
import java.math.BigInteger
      
# Int/Long Factorial      
def factorial_int(n)  
    if n == 1  
        1.to_i  
    else      
        (n * factorial_int(n - 1)).to_i  
    end  
end  
# double/float Factorial  
def factorial_float(n)  
    if n == 1    
        1.0
    else  
        (n * factorial_float(n - 1)).to_f  
    end  
end  
# BigInteger Factorial         
def factorial_bigint(n)  
    if n == 1    
        BigInteger.new('1')  
    else            
        BigInteger.new(n.to_s).multiply(factorial_bigint(n-1))
    end  
end  
  
timer = Stopwatch.new  
facIntResult = 0    
facDblResult = 0.0      
facBigResult = BigInteger.new('0')  
i = 0      
          
puts "\nFactorial using Int/Long"  
# Benchmark Factorial using Int64        
for i in (5..50).step(5)  
    timer.start   
    facIntResult = factorial_int(i)  
    timer.stop  
    puts " (#{i.to_s}) = #{timer.elapsed} : #{facIntResult}"  
end  
puts "\nFactorial using Float/Double"  
# Benchmark Factorial using Double  
for i in (5..50).step(5)  
    timer.start      
    facDblResult = factorial_float(i)      
    timer.stop  
    puts " (#{i.to_s}) = #{timer.elapsed.to_s} : #{facDblResult.to_s}"  
end          
puts "\nFactorial using BigInteger"      
# Benchmark Factorial using BigInteger      
for i in (5..50).step(5)  
    timer.start  
    facBigResult = factorial_bigint(i)  
    timer.stop  
    puts " (#{i.to_s}) = #{timer.elapsed.to_s} : #{facBigResult.to_s}"  
end  
  
gets
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/--EPpgBL4Z4s/TqHNlnr9IiI/AAAAAAAAGIA/BdUHV-6ZgoI/s1600/FiborialJRubyTypes.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="524" src="http://1.bp.blogspot.com/--EPpgBL4Z4s/TqHNlnr9IiI/AAAAAAAAGIA/BdUHV-6ZgoI/s640/FiborialJRubyTypes.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/1L0NtG8BNZ0" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2974074228341846556/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/10/factorial-and-fibonacci-in-jruby.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2974074228341846556?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2974074228341846556?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/1L0NtG8BNZ0/factorial-and-fibonacci-in-jruby.html" title="Factorial and Fibonacci in JRuby" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-ChkpeFKUvXQ/Tp84w9JBkZI/AAAAAAAAGHk/-OzaY9Hvw_s/s72-c/fiborial_jruby.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/10/factorial-and-fibonacci-in-jruby.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEIASX09fyp7ImA9WhBWE04.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-4601880322929939928</id><published>2011-10-15T16:04:00.000-07:00</published><updated>2013-04-07T05:09:08.367-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2013-04-07T05:09:08.367-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Scala" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Scala</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update 1:&lt;/b&gt; Porting code examples to Scala 2.10.1 - support for String Interpolation. 
&lt;br /&gt;
&lt;br /&gt;
WARNING! I know that Scala is intended to be use in a very Functional way, however, my goal is to show its Imperative and OO language features, so it can be compared with other 19 OO languages. Said that, if you know how to do something on the examples below in a more Functional style you can add it in a comment :)&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Scala that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I'm using the same Stopwatch java class that I used in the Java version of this post. I just added the .java file in the same scala-eclipse project. &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html" target="_blank"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="scala" name="code"&gt;package com.series
import scala.math.BigInt._  
import java.util.Scanner
import blog.series.lib.Stopwatch

// Instance (Singleton) Class that works as a Module/Utils class             
// static is not a class modifier in Scala    
object StaticFiborial  
{  
    // 'Static' Field  
    // 'Static' Constructor/Initializer  
    private var _message:String = "'Static' Constructor"  
    println(_message)  
    // 'Static' Method - Factorial Recursive    
    def factorialR(n:Int):BigInt = {  
        if(n==1)  
            BigInt(1)  
        else  
            BigInt(n) * factorialR(n - 1)  
    }  
    // 'Static' Method - Factorial Imperative  
    def factorialI(n:Int):BigInt = {  
        var res:BigInt = 1        
        for (i &amp;lt;- n until 1 by -1) {  
            res = res * i  
        }        
        res  
    }  
    // 'Static' Method - Fibonacci Recursive   
    def fibonacciR(n:Int):Long = {  
        if(n&amp;lt;2)  
            1  
        else  
            fibonacciR(n - 1) + fibonacciR(n - 2)  
    }  
    // 'Static' Method - Fibonacci Imperative  
    def fibonacciI(n:Int):Long = {  
        var pre:Long = 1  
        var cur:Long = 1  
        var tmp:Long = 0  
        for(i &amp;lt;- 2 to n) {  
            tmp = cur + pre  
            pre = cur  
            cur = tmp  
        }  
        cur  
    }  
    // Static Method - Benchmarking Algorithms   
    def benchmarkAlgorithm(algorithm:Int, values:List[Int]) = {        
        val timer = new Stopwatch  
        var (i:Int, testValue:Int) = (0, 0)  
        var facTimeResult:BigInt = 0  
        var fibTimeResult:Long = 0  
        
        algorithm match {    
            case 1 =&amp;gt;   
                println("\nFactorial Imperative:")  
                // "For" Loop Statement  
                for (i &amp;lt;- 0 to values.size - 1) {  
                    testValue = values(i)  
                    // Taking Time      
                    timer.start()      
                    facTimeResult = factorialI(testValue)      
                    timer.stop()  
                    // Getting Time  
                    println(s" ($testValue) = ${timer.getElapsed}")  
                }  
            case 2 =&amp;gt;   
                println("\nFactorial Recursive:")  
                // "While" Loop Statement  
                while (i &amp;lt; values.size) {  
                    testValue = values(i)  
                    // Taking Time      
                    timer.start()      
                    facTimeResult = factorialR(testValue)      
                    timer.stop()  
                    // Getting Time  
                    println(s" ($testValue) = ${timer.getElapsed}")  
                    i += 1  
                }  
            case 3 =&amp;gt;  
                println("\nFibonacci Imperative:")  
                // "For" Loop Statement  
                for (i &amp;lt;- 0 to values.size - 1) {  
                    testValue = values(i)  
                    // Taking Time      
                    timer.start()      
                    fibTimeResult = fibonacciI(testValue)  
                    timer.stop()  
                    // Getting Time  
                    println(s" ($testValue) = ${timer.getElapsed}")  
                }  
            case 4 =&amp;gt;   
                println("\nFibonacci Recursive:")  
                // "For" Loop Statement  
                for (i &amp;lt;- 0 to values.size - 1) {  
                    testValue = values(i)  
                    // Taking Time      
                    timer.start()      
                    fibTimeResult = fibonacciR(testValue)  
                    timer.stop()  
                    // Getting Time  
                    println(s" ($testValue) = ${timer.getElapsed}")  
                }  
            case _ =&amp;gt;   
                println("DONG!")  
        }    
    }      
}  
  
class InstanceFiborial(message:String) {  
    // Instance Field  
    private var _message:String = message  
    // Instance Constructor      
    def this() = {  
        this("Instance Constructor")  
        println(_message)  
    }      
    // Instance Method - Factorial Recursive    
    def factorialR(n:Int):BigInt = {  
        // Calling 'Static' Method  
        StaticFiborial.factorialR(n)  
    }  
    // Instance Method - Factorial Imperative  
    def factorialI(n:Int):BigInt = {  
        // Calling 'Static' Method        
        StaticFiborial.factorialI(n)  
    }  
    // Instance Method - Fibonacci Recursive   
    def fibonacciR(n:Int):Long = {  
        // Calling 'Static' Method        
        StaticFiborial.fibonacciR(n)  
    }  
    // Instance Method - Fibonacci Imperative  
    def fibonacciI(n:Int):Long = {  
        // Calling 'Static' Method        
        StaticFiborial.fibonacciI(n)  
    }  
}  
  
object Program {  
    def main(args: Array[String]): Unit = {  
        // Calling 'Static' Class and Methods      
        // No instantiation needed. Calling method directly from the class      
        println(s"FacImp(5) = ${StaticFiborial.factorialI(5)}")      
        println(s"FacRec(5) = ${StaticFiborial.factorialR(5)}")      
        println(s"FibImp(11)= ${StaticFiborial.fibonacciI(11)}")      
        println(s"FibRec(11)= ${StaticFiborial.fibonacciR(11)}")   
          
        println("\nInstance Class")      
        // Calling Instance Class and Methods       
        // Need to instantiate before using. Call method from instantiated object      
        val ff = new InstanceFiborial()      
        println(s"FacImp(5) = ${ff.factorialI(5)}")      
        println(s"FacRec(5) = ${ff.factorialR(5)}")      
        println(s"FibImp(11)= ${ff.fibonacciI(11)}")      
        println(s"FibRec(11)= ${ff.fibonacciR(11)}")  
          
        // Create a (generic) list of integer values to test      
        // From 5 to 50 by 5  
        var values:List[Int] = Nil  
        for(i &amp;lt;- 5 until 55 by 5)  
            values = values ::: List(i)  
  
        // Benchmarking Fibonacci  
        // 1 = Factorial Imperative                  
        StaticFiborial.benchmarkAlgorithm(1, values)      
        // 2 = Factorial Recursive      
        StaticFiborial.benchmarkAlgorithm(2, values)      
    
        // Benchmarking Factorial                  
        // 3 = Fibonacci Imperative      
        StaticFiborial.benchmarkAlgorithm(3, values)      
        // 4 = Fibonacci Recursive      
        StaticFiborial.benchmarkAlgorithm(4, values)  
  
        println("Press any key to exit...")      
        val in = new Scanner(System.in)      
        in.nextLine()      
        in.close()           
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: 
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-ACgzJoZZiqg/TpoQSChsX2I/AAAAAAAAGGw/_bvYCLlqgLc/s1600/FiborialScala.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-ACgzJoZZiqg/TpoQSChsX2I/AAAAAAAAGGw/_bvYCLlqgLc/s640/FiborialScala.png" width="210" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="scala" name="code"&gt;import scala.math.BigInt._
import scala.collection.mutable.StringBuilder._

object Fiborial {
    // Using a StringBuilder as a list of string elements
    def getFactorialSeries(n:Int):String = {
        // Create the String that will hold the list
        val series:StringBuilder = new StringBuilder
        // We begin by concatenating the number you want to calculate
        // in the following format: "!# ="
        series.append("!")
        series.append(n)
        series.append(" = ")
        // We iterate backwards through the elements of the series
        for (i &amp;lt;- n until 0 by -1) {
            // and append it to the list
            series.append(i)
            if (i &amp;gt; 1)
                series.append(" * ")
            else 
                series.append(" = ")
        }
        // Get the result from the Factorial Method
        // and append it to the end of the list
        series.append(factorial(n))
        // return the list as a string
        series.toString
    }

    // Using a StringBuilder as a list of string elements
    def getFibonnaciSeries(n:Int):String = {
        // Create the String that will hold the list
        val series:StringBuilder = new StringBuilder
        // We begin by concatenating the first 3 values which
        // are always constant
        series.append("0, 1, 1")
        // Then we calculate the Fibonacci of each element
        // and add append it to the list
        for (i &amp;lt;- 2 to n) {
            if (i &amp;lt; n)
                series.append(", ")
            else
                series.append(" = ")
            
            series.append(fibonacci(i))
        }
        // return the list as a string
        series.toString
    }

    def factorial(n:Int):BigInt = {
        if(n==1)
            BigInt(1)
        else
            BigInt(n) * factorial(n - 1)
    }

    def fibonacci(n:Int):Long = {
        if (n &amp;lt; 2)
            1  
        else  
            fibonacci(n - 1) + fibonacci(n - 2)  
    }
}

object FiborialProgram {
    def main(args:Array[String]) {
        // Printing Factorial Series  
        println("")
        println(Fiborial.getFactorialSeries(5))
        println(Fiborial.getFactorialSeries(7))  
        println(Fiborial.getFactorialSeries(9))  
        println(Fiborial.getFactorialSeries(11))  
        println(Fiborial.getFactorialSeries(40))  
        // Printing Fibonacci Series  
        println("")  
        println(Fiborial.getFibonnaciSeries(5))  
        println(Fiborial.getFibonnaciSeries(7))  
        println(Fiborial.getFibonnaciSeries(9))  
        println(Fiborial.getFibonnaciSeries(11))  
        println(Fiborial.getFibonnaciSeries(40))  
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-ByIq-cWAks4/TpoQUW4NC0I/AAAAAAAAGG4/9F-Aq_lN-DY/s1600/FiborialSeriesScala.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="238" src="http://4.bp.blogspot.com/-ByIq-cWAks4/TpoQUW4NC0I/AAAAAAAAGG4/9F-Aq_lN-DY/s640/FiborialSeriesScala.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
There are no static classes in Scala, instead you can define an object which in fact is an instance singleton class that can be used as a static class.
It is possible to mix 'static' and instance members into the same class. You do that by creating a class (instance members) and an object ('static' members)
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="scala" name="code"&gt;package com.series
// To mix Instance and 'Static' methods in Scala you define a Class (instance)   
// and and object (static) with the same Name  
  
// Instance Class  
class Fiborial(init:Int) {  
    // Instance Field  
    private var _instanceCount:Int = init  
    // Instance Read-Only Getter  
    def InstanceCount = _instanceCount  
    // Instance Constructor  
    def this() = {  
        this(0)  
        println(s"\nInstance Constructor ${_instanceCount}")  
    }      
    // Instance Method   
    def factorial(n:Int) = {  
        _instanceCount += 1      
        println(s"\nFactorial($n)")  
    }  
}  
// 'Static' Class  
object Fiborial {  
    // 'Static' Field  
    private var _staticCount:Int = 0  
    // Instance Read-Only Getter  
    def StaticCount = _staticCount  
    // 'Static' Constructor/Initializer  
    println(s"\nStatic Constructor ${_staticCount}")  
    // 'Static' Method   
    def fibonacci(n:Int) = {  
        _staticCount += 1      
        println(s"\nFactorial($n)")  
    }  
}  
  
object Program {  
    def main(args: Array[String]) = {  
        // Calling Static Constructor and Methods  
        // No need to instantiate      
        Fiborial.fibonacci(5)                  
    
        // Calling Instance Constructor and Methods      
        // Instance required      
        val fib = new Fiborial      
        fib.factorial(5)    
    
        Fiborial.fibonacci(15)                  
        fib.factorial(5)      
    
        // Calling Instance Constructor and Methods      
        // for a second object      
        val fib2 = new Fiborial      
        fib2.factorial(5)      
              
        println("")  
        // Calling Static Property      
        println(s"Static Count = ${Fiborial.StaticCount}")      
        // Calling Instance Getter of object 1 and 2      
        println(s"Instance 1 Count = ${fib.InstanceCount}")      
        println(s"Instance 2 Count = ${fib2.InstanceCount}")     
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-ihJBR0m6gSw/TpoQXFWQVEI/AAAAAAAAGHA/1VBFg_9a0vI/s1600/FiborialExtrasScala.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-ihJBR0m6gSw/TpoQXFWQVEI/AAAAAAAAGHA/1VBFg_9a0vI/s1600/FiborialExtrasScala.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using scala.Long, scala.Double, scala.math.BigInt&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="scala" name="code"&gt;import scala.math.BigInt._
import blog.series.lib.Stopwatch

object Program {

    def main(args: Array[String]): Unit = {
        val timer = new Stopwatch()  
        var facLngResult:Long = 0  
        var facDblResult:Double = 0  
        var facBigResult:BigInt = BigInt(0)  
            
        println("\nFactorial using Long")    
        // Benchmark Factorial using Long  
        for(i &amp;lt;- 5 until 55 by 5) {            
            timer.start   
            facLngResult = factorialLong(i)    
            timer.stop  
            println(s" ($i) = ${timer.getElapsed} : $facLngResult")    
        }  
        println("\nFactorial using Double")  
        // Benchmark Factorial using Double    
        for(i &amp;lt;- 5 until 55 by 5) {            
            timer.start    
            facDblResult = factorialDouble(i)    
            timer.stop    
            println(s" ($i) = ${timer.getElapsed} : $facDblResult")  
        }  
        println("\nFactorial using BigInteger")  
        // Benchmark Factorial using BigInteger  
        for(i &amp;lt;- 5 until 55 by 5) {            
            timer.start    
            facBigResult = factorialBigInt(i)    
            timer.stop    
            println(s" ($i) = ${timer.getElapsed} : $facBigResult")  
        }  
    }  
    // Long Factorial   
    def factorialLong(n:Int):Long = {      
        if(n==1)  
            1.toLong  
        else  
            n.toLong * factorialLong(n - 1)  
    }  
    // Double Factorial   
    def factorialDouble(n:Int):Double = {  
        if(n==1)  
            1.toDouble  
        else  
            n.toDouble * factorialDouble(n - 1)  
    }  
    // BigInteger Factorial     
    def factorialBigInt(n:Int):BigInt = {       
        if(n==1)  
            BigInt(1)  
        else  
            BigInt(n) * factorialBigInt(n - 1)  
    }  

}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-lfUppcTTNoE/TpoQY1oiCzI/AAAAAAAAGHI/nqAG6EWrGoQ/s1600/FiborialScalaTypes.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="512" src="http://1.bp.blogspot.com/-lfUppcTTNoE/TpoQY1oiCzI/AAAAAAAAGHI/nqAG6EWrGoQ/s640/FiborialScalaTypes.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Ilcsy3LPED4" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/4601880322929939928/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/10/factorial-and-fibonacci-in-scala.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4601880322929939928?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4601880322929939928?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Ilcsy3LPED4/factorial-and-fibonacci-in-scala.html" title="Factorial and Fibonacci in Scala" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-ACgzJoZZiqg/TpoQSChsX2I/AAAAAAAAGGw/_bvYCLlqgLc/s72-c/FiborialScala.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/10/factorial-and-fibonacci-in-scala.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UEQX0_eCp7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-4052449432112013270</id><published>2011-10-02T06:00:00.000-07:00</published><updated>2012-03-17T02:06:40.340-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:06:40.340-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Jython" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Jython</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Jython that implements 2 classes. There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally a main function called as module level code.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
WARNING: the code that you will see below is not following python(ic) guidelines/idiomatic coding, I did it in purpose to compare python's syntax and features side by side with other programming languages... For instance, instead of using a python int or long I imported and used System.Numerics.BigInteger instead. Other examples, naming convention and so on, so bear with me!&lt;br /&gt;
&lt;br /&gt;
I'm using the same Stopwatch java class that I used in the Java version of this post. I just added the .class in the python paths.&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# Factorial and Fibonacci in Jython
import java
from java.util import Scanner
from java.math import BigInteger
from java.lang import System 
import Stopwatch

# Instance Class
# static classes are not supported in Python
class StaticFiborial:
    # Static Field
    __className = ''
    # no builtin static constructor/initializer support
    # you can initialize field at this point and even add extra code
    __className = 'Static Initializer'
    print __className
    # Static Method - Factorial Recursive  
    @staticmethod
    def factorialR(n):
        if n == 1:
            return BigInteger.ONE
        else:            
            return BigInteger.valueOf(n).multiply(StaticFiborial.factorialR(n-1))            
    # Static Method - Factorial Imperative
    @staticmethod
    def factorialI(n):
        res = BigInteger.ONE
        for i in range(n, 1, -1):            
            res = res.multiply(BigInteger.valueOf(i))
        return res
    # Static Method - Fibonacci Recursive 
    @staticmethod
    def fibonacciR(n):
        if n &amp;lt; 2:
            return 1
        else:
            return StaticFiborial.fibonacciR(n - 1) + StaticFiborial.fibonacciR(n - 2)
    # Static Method - Fibonacci Imperative
    @staticmethod
    def fibonacciI(n):
        pre, cur, tmp = 0, 0, 0
        pre, cur = 1, 1
        for i in range(2, n + 1):  
            tmp = cur + pre  
            pre = cur  
            cur = tmp  
        return cur 
    # Static Method - Benchmarking Algorithms 
    @staticmethod
    def benchmarkAlgorithm(algorithm, values):
        timer = Stopwatch()
        i = 0  
        testValue = 0  
        facTimeResult = BigInteger.valueOf(0)
        fibTimeResult = 0    
          
        # 'if-elif-else' Flow Control Statement    
        if algorithm == 1:  
            print '\nFactorial Imperative:'  
            # 'For in range' Loop Statement   
            for i in range(len(values)):
                testValue = values[i]  
                # Taking Time    
                timer.start()  
                facTimeResult = StaticFiborial.factorialI(testValue)  
                timer.stop()                            
                # Getting Time    
                print ' (' + str(testValue) + ') = ', timer.elapsed  
        elif algorithm == 2:  
            print '\nFactorial Recursive:'  
            # 'While' Loop Statement  
            while i &amp;lt; len(values):  
                testValue = values[i]  
                # Taking Time    
                timer.start()  
                facTimeResult = StaticFiborial.factorialR(testValue)  
                timer.stop()                            
                # Getting Time    
                print ' (' + str(testValue) + ') = ', timer.elapsed
                i += 1  
        elif algorithm == 3:  
            print '\nFibonacci Imperative:'   
            # 'For in List' Loop Statement               
            for item in values:
                testValue = item  
                # Taking Time  
                timer.start()  
                fibTimeResult = StaticFiborial.fibonacciI(testValue)  
                timer.stop()  
                # Getting Time  
                print ' (' + str(testValue) + ') = ', timer.elapsed                  
        elif algorithm == 4:
            print '\nFibonacci Recursive:'  
            # 'For in List' Loop Statement   
            for item in values:  
                testValue = item  
                # Taking Time  
                timer.start()  
                fibTimeResult = StaticFiborial.fibonacciR(testValue)  
                timer.stop()  
                # Getting Time                
                print ' (' + str(testValue) + ') = ', timer.elapsed
        else:  
            print 'DONG!'

# Instance Class  
class InstanceFiborial(object):
    # Instances Field  
    __className = ''
    # Instance Constructor  
    def __init__(self):  
        self.__className = 'Instance Constructor'
        print self.__className  
    # Instance Method - Factorial Recursive  
    def factorialR(self, n):
        # Calling Static Method  
        return StaticFiborial.factorialR(n)  
    # Instance Method - Factorial Imperative  
    def factorialI(self, n):  
        # Calling Static Method  
        return StaticFiborial.factorialI(n)  
    # Instance Method - Fibonacci Recursive    
    def fibonacciR(self, n):
        # Calling Static Method  
        return StaticFiborial.fibonacciR(n)  
    # Instance Method - Fibonacci Imperative  
    def fibonacciI(self, n):  
        # Calling Static Method  
        return StaticFiborial.fibonacciI(n)  


# Console Program  
def main():
    print 'Static Class'  
    # Calling Static Class and Methods  
    # No instantiation needed. Calling method directly from the class  
    print 'FacImp(5) = ', StaticFiborial.factorialI(5)
    print 'FacRec(5) = ', StaticFiborial.factorialR(5)
    print 'FibImp(11)= ', StaticFiborial.fibonacciI(11)
    print 'FibRec(11)= ', StaticFiborial.fibonacciR(11)
  
    print '\nInstance Class'  
    # Calling Instance Class and Methods  
    # Need to instantiate before using. Calling method from instantiated object  
    ff = InstanceFiborial()
    print 'FacImp(5) = ', ff.factorialI(5)
    print 'FacRec(5) = ', ff.factorialR(5)
    print 'FibImp(11)= ', ff.fibonacciI(11)
    print 'FibRec(11)= ', ff.fibonacciR(11)
  
    # Create a (Python) list of values to test    
    # From 5 to 50 by 5  
    values = []
    for i in range(5,55,5):
        values.append(i)

    # Benchmarking Fibonacci  
    # 1 = Factorial Imperative  
    StaticFiborial.benchmarkAlgorithm(1, values)  
    # 2 = Factorial Recursive  
    StaticFiborial.benchmarkAlgorithm(2, values) 
    # Benchmarking Factorial  
    # 3 = Fibonacci Imperative  
    StaticFiborial.benchmarkAlgorithm(3, values)  
    # 4 = Fibonacci Recursive  
    StaticFiborial.benchmarkAlgorithm(4, values)
    
    # Stop and exit
    sin = Scanner(System.in)    
    line = sin.nextLine()    
    sin.close()
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-Urt4bhwen1s/Tp8y9lYKckI/AAAAAAAAGHQ/W_esWsDGEUU/s1600/fiborial_jython.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-Urt4bhwen1s/Tp8y9lYKckI/AAAAAAAAGHQ/W_esWsDGEUU/s640/fiborial_jython.PNG" width="268" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import java
from java.util import Scanner
from java.math import BigInteger
from java.lang import System, StringBuffer

class Fiborial:  
    # Using a StringBuffer as a list of string elements    
    @staticmethod
    def getFactorialSeries(n):
        # Create the String that will hold the list    
        series = StringBuffer()   
        # We begin by concatenating the number you want to calculate    
        # in the following format: "!# ="    
        series.append("!")  
        series.append(n)  
        series.append(" = ")
        # We iterate backwards through the elements of the series    
        for i in range(n, 0, -1):
            # and append it to the list    
            series.append(i)  
            if i &amp;gt; 1:   
                series.append(" * ")    
            else:     
                series.append(" = ")  
        # Get the result from the Factorial Method    
        # and append it to the end of the list    
        series.append(Fiborial.factorial(n).toString())
        # return the list as a string    
        return series.toString()  
  
    # Using a StringBuffer as a list of string elements    
    @staticmethod
    def getFibonnaciSeries(n):  
        # Create the String that will hold the list    
        series = StringBuffer()
        # We begin by concatenating the first 3 values which    
        # are always constant    
        series.append("0, 1, 1")    
        # Then we calculate the Fibonacci of each element    
        # and add append it to the list    
        for i in range(2, n+1):  
            if i &amp;lt; n:  
                series.append(", ")   
            else:  
                series.append(" = ")    
            series.append(Fiborial.fibonacci(i))  
        # return the list as a string    
        return series.toString()  
    @staticmethod      
    def factorial(n):
        if n == 1:
            return BigInteger.ONE
        else:
            return BigInteger.valueOf(n).multiply(Fiborial.factorial(n-1))
    @staticmethod  
    def fibonacci(n):  
        if n &amp;lt; 2:  
            return 1    
        else:    
            return Fiborial.fibonacci(n - 1) + Fiborial.fibonacci(n - 2)  
  
def main():
    # Printing Factorial Series    
    print ""  
    print Fiborial.getFactorialSeries(5)  
    print Fiborial.getFactorialSeries(7)  
    print Fiborial.getFactorialSeries(9)  
    print Fiborial.getFactorialSeries(11)  
    print Fiborial.getFactorialSeries(40)  
    # Printing Fibonacci Series    
    print ""  
    print Fiborial.getFibonnaciSeries(5)  
    print Fiborial.getFibonnaciSeries(7)  
    print Fiborial.getFibonnaciSeries(9)  
    print Fiborial.getFibonnaciSeries(11)  
    print Fiborial.getFibonnaciSeries(40)  
      
    sin = Scanner(System.in)    
    line = sin.nextLine()    
    sin.close()
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-5DQPHdglutM/Tohbdb0jb8I/AAAAAAAAGFU/LbWMe0WjtGw/s1600/fiborial_jy_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="299" src="http://4.bp.blogspot.com/-5DQPHdglutM/Tohbdb0jb8I/AAAAAAAAGFU/LbWMe0WjtGw/s640/fiborial_jy_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import java
from java.util import Scanner
from java.lang import System
    
# Instance Class
class Fiborial:
    # Instance Field  
    __instanceCount = 0
    # Static Field      
    __staticCount = 0    
    print "\nStatic Constructor", __staticCount
    # Instance Read-Only Property    
    # Within instance members, you can always use      
    # the "self" reference pointer to access your (instance) members.              
    def getInstanceCount(self):   
        return self.__instanceCount  
    InstanceCount = property(getInstanceCount, None, None)
    # Static Property
    # looks like it is not supported even if the code identify it as such    
    @staticmethod
    def getStaticCount():        
        return Fiborial.__staticCount        
    #StaticCount = property(getStaticCount, None, None)
    # The problem seems to be the use of: property(getStaticCount,..)
    # it requires an instance method and not a static one (Test.getStaticCount)    
    # Instance Constructor    
    def __init__(self):
        self.__instanceCount = 0    
        print "\nInstance Constructor", self.__instanceCount
    # No Static Constructor    
    #@staticmethod
    #def __init__():
    #    Fiborial.__staticCount = 0
    #    print "\nStatic Constructor", Fiborial.__staticCount
    # Instance Method
    def factorial(self, n):
        self.__instanceCount += 1   
        print "\nFactorial(" + str(n) + ")"
    # Static Method
    @staticmethod    
    def fibonacci(n):
        Fiborial.__staticCount += 1  
        print "\nFibonacci(" + str(n) + ")"

def main():
    # Calling Static Constructor and Methods    
    # No need to instantiate    
    Fiborial.fibonacci(5)  
      
    # Calling Instance Constructor and Methods    
    # Instance required    
    fib = Fiborial()    
    fib.factorial(5)  

    Fiborial.fibonacci(15)  
    fib.factorial(5)  
      
    # Calling Instance Constructor and Methods    
    # for a second object    
    fib2 = Fiborial()  
    fib2.factorial(5)  
      
    print ""  
    # Calling Static Property
    # using the static method referenced by the property
    #print "Static Count =", Fiborial.StaticCount
    print "Static Count =", Fiborial.getStaticCount()
    # Calling Instance Property of object 1 and 2    
    print "Instance 1 Count =", fib.InstanceCount
    print "Instance 2 Count =", fib2.InstanceCount
      
    sin = Scanner(System.in)    
    line = sin.nextLine()    
    sin.close()
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-dCKmyjqrsrI/Tohc7EPKjUI/AAAAAAAAGFY/JrGzFG1BfBc/s1600/fiborial_jy_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="356" src="http://3.bp.blogspot.com/-dCKmyjqrsrI/Tohc7EPKjUI/AAAAAAAAGFY/JrGzFG1BfBc/s400/fiborial_jy_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using int, float, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So, it looks like integers in python can hold big integers, so using Jython int/long or java.math.BigInteger is the same so not much to say here.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import java
from java.util import Scanner
from java.math import BigInteger
from java.lang import System 
import Stopwatch

# Int/Long Factorial  
def factorial_int(n):  
    if n == 1:
        return int(1)
    else:  
        return int(n * factorial_int(n - 1))
      
# double/float Factorial
def factorial_float(n):
    if n == 1:
        return float(1.0)
    else:  
        return float(n * factorial_float(n - 1))

# BigInteger Factorial     
def factorial_bigint(n):
    if n == 1:
        return BigInteger.ONE
    else:
        return BigInteger.valueOf(n).multiply(factorial_bigint(n-1))
  
timer = Stopwatch()  
facIntResult = 0
facDblResult = 0.0  
facBigResult = BigInteger.valueOf(0)
i = 0  
      
print "\nFactorial using Int/Long"
# Benchmark Factorial using Int64    

for i in range(5,55,5):  
    timer.start()
    facIntResult = factorial_int(i)
    timer.stop()          
    print " (" + str(i) + ") =", timer.elapsed, " :", facIntResult  
      
print "\nFactorial using Float/Double"  
# Benchmark Factorial using Double  
for i in range(5,55,5):
    timer.start()  
    facDblResult = factorial_float(i)  
    timer.stop()          
    print " (" + str(i) + ") =", timer.elapsed, " :", facDblResult
      
print "\nFactorial using BigInteger"  
# Benchmark Factorial using BigInteger  
for i in range(5,55,5):  
    timer.start()
    facBigResult = factorial_bigint(i)  
    timer.stop()
    print " (" + str(i) + ") =", timer.elapsed, " :", facBigResult    

sin = Scanner(System.in)    
line = sin.nextLine()    
sin.close()
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-St-5VVRmsDc/Tohfx54ae-I/AAAAAAAAGFc/Iw9rKu-EhyI/s1600/fiborial_jy_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="572" src="http://2.bp.blogspot.com/-St-5VVRmsDc/Tohfx54ae-I/AAAAAAAAGFc/Iw9rKu-EhyI/s640/fiborial_jy_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;br /&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/xttCmq2GQ-o" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/4052449432112013270/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/10/factorial-and-fibonacci-in-jython.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4052449432112013270?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4052449432112013270?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/xttCmq2GQ-o/factorial-and-fibonacci-in-jython.html" title="Factorial and Fibonacci in Jython" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-Urt4bhwen1s/Tp8y9lYKckI/AAAAAAAAGHQ/W_esWsDGEUU/s72-c/fiborial_jython.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/10/factorial-and-fibonacci-in-jython.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UCQHozfCp7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-4053867735005040097</id><published>2011-07-17T09:54:00.000-07:00</published><updated>2012-03-17T02:07:41.484-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:07:41.484-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="IronRuby" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in IronRuby</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in IronRuby that implements 2 classes. There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally a main function called as module level code.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
WARNING: the code that you will see below is not following ruby guidelines/idiomatic coding, I did it in purpose to compare ruby's syntax and features side by side with other programming languages... For instance, instead of using a ruby bignum I imported and used System.Numerics.BigInteger instead. Other examples, naming convention and so on, so bear with me!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;# Factorial and Fibonacci in IronRuby
require "mscorlib"  
require "System"
require "System.Numerics"

include System::Collections::Generic
include System::Diagnostics
include System::Numerics
  
module FiborialRb
    # Static Class
    # static classes are not supported in Ruby
    class StaticFiborial
        # Static Field
        @@class_name = ""
        # no builtin static constructor/initializer support  
        # you can initialize field at this point and even add extra code         
        @@class_name = "Static Constructor"
        puts @@class_name
        # Static Method - Factorial Recursive
        def self.factorial_r(n)
            if n &amp;lt; 2
                BigInteger.One
            else
                BigInteger.Multiply(BigInteger.new(n), self.factorial_r(n - 1))                
            end
        end
        # Static Method - Factorial Imperative
        def self.factorial_i(n)
            res = BigInteger.One
            while n &amp;gt; 1
                res = BigInteger.Multiply(res, BigInteger.new(n))
                n -= 1
            end
            res
        end
        # Static Method - Fibonacci Recursive   
        def self.fibonacci_r(n)
            if n &amp;lt; 2
                1
            else
                self.fibonacci_r(n - 1) + self.fibonacci_r(n - 2)
            end
        end
        # Static Method - Fibonacci Imperative
        def self.fibonacci_i(n)
            pre = 1
            cur = 1
            tmp = 0
            for i in 2..n
                tmp = cur + pre
                pre = cur
                cur = tmp
            end
            cur
        end
        # Static Method - Benchmarking Algorithms
        def self.benchmark_algorithm(algorithm, values)
            timer = Stopwatch.new  
            i = 0
            testValue = 0    
            facTimeResult = BigInteger.Zero  
            fibTimeResult = 0           
            # "case/switch" Flow Control Statement
            case algorithm
            when 1
                puts "\nFactorial Imperative:"
                # "For in range" Loop Statement
                for i in 0..values.size - 1 do
                    testValue = values[i]                    
                    # Taking Time
                    timer.Start
                    facTimeResult = self.factorial_i(testValue)    
                    timer.Stop
                    # Getting Time
                    puts " (#{testValue}) = #{timer.Elapsed}"                    
                end
            when 2
                puts "\nFactorial Recursive:"
                # "While" Loop Statement
                while i &amp;lt; values.size do
                    testValue = values[i]
                    # Taking Time
                    timer.Start
                    facTimeResult = self.factorial_r(testValue)    
                    timer.Stop
                    # Getting Time
                    puts " (#{testValue}) = #{timer.Elapsed}"
                    i += 1
                end
            when 3
                puts "\nFibonacci Imperative:"
                # "until" Loop Statement
                until i == values.size do                    
                    testValue = values[i]
                    # Taking Time
                    timer.Start
                    fibTimeResult = self.fibonacci_i(testValue)    
                    timer.Stop
                    # Getting Time
                    puts " (#{testValue}) = #{timer.Elapsed}"
                    i += 1
                end
            when 4
                puts "\nFibonacci Recursive:"
                # "For each?" Statement
                values.each do |testValue|
                    # Taking Time
                    timer.Start
                    fibTimeResult = self.fibonacci_r(testValue)    
                    timer.Stop
                    # Getting Time
                    puts " (#{testValue}) = #{timer.Elapsed}"
                end
            else
                puts "DONG!"
            end
        end
    end
    
    # Instance Class
    class InstanceFiborial
        # Instance Field
        @class_name = ""
        # Instance Constructor/Initializer
        def initialize
            @class_name = "Instance Constructor"
            puts @class_name
        end
        # Instance Method - Factorial Recursive    
        def factorial_r(n)  
            # Calling Static Method    
            StaticFiborial::factorial_r(n)
        end
        # Instance Method - Factorial Imperative    
        def factorial_i(n)
            # Calling Static Method    
            StaticFiborial::factorial_i(n)    
        end
        # Instance Method - Fibonacci Recursive      
        def fibonacci_r(n)
            # Calling Static Method    
            StaticFiborial::fibonacci_r(n)    
        end
        # Instance Method - Fibonacci Imperative    
        def fibonacci_i(n)
            # Calling Static Method    
            StaticFiborial::fibonacci_i(n)
        end
    end
  
    # Console Program  
    puts "Static Class"    
    # Calling Static Class and Methods    
    # No instantiation needed. Calling method directly from the class    
    puts "FacImp(5) = #{StaticFiborial::factorial_i(5)}"
    puts "FacRec(5) = #{StaticFiborial::factorial_r(5)}" 
    puts "FibImp(11)= #{StaticFiborial::fibonacci_i(11)}" 
    puts "FibRec(11)= #{StaticFiborial::fibonacci_r(11)}" 
    
    puts "\nInstance Class"
    # Calling Instance Class and Methods    
    # Need to instantiate before using. Calling method from instantiated object    
    ff = InstanceFiborial.new
    puts "FacImp(5) = #{ff.factorial_i(5)}"
    puts "FacRec(5) = #{ff.factorial_r(5)}"
    puts "FibImp(11)= #{ff.fibonacci_i(11)}"
    puts "FibRec(11)= #{ff.fibonacci_r(11)}"
        
    # Create a (Ruby) list of values to test      
    # From 5 to 50 by 5    
    values = []
    for i in (5..50).step(5)
        values &amp;lt;&amp;lt; i
    end

    # Benchmarking Fibonacci    
    # 1 = Factorial Imperative   
    StaticFiborial::benchmark_algorithm(1,values)
     # 2 = Factorial Recursive
    StaticFiborial::benchmark_algorithm(2,values)
    # Benchmarking Factorial    
    # 3 = Fibonacci Imperative 
    StaticFiborial::benchmark_algorithm(3,values)
    # 4 = Fibonacci Recursive 
    StaticFiborial::benchmark_algorithm(4,values)
    
    # Stop and exit  
    puts "Press any key to exit..."  
    gets  
end  
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:  &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-Mk-Pxl-KHCE/TiL8Lna2geI/AAAAAAAAF-Y/0fD7GR6Jde0/s1600/FiborialIRb.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-Mk-Pxl-KHCE/TiL8Lna2geI/AAAAAAAAF-Y/0fD7GR6Jde0/s640/FiborialIRb.png" width="272" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt; &lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;require "mscorlib"  
require "System"
require "System.Numerics"

include System::Text
include System::Numerics
  
module FiborialSeriesRb    
    
    class Fiborial
         # Using a StringBuilder as a list of string elements  
         def self.get_factorial_series(n)
            # Create the String that will hold the list      
            series = StringBuilder.new    
            # We begin by concatenating the number you want to calculate      
            # in the following format: "!# ="      
            series.Append("!")
            series.Append(n)
            series.Append(" = ")
            # We iterate backwards through the elements of the series
            i = n
            while i &amp;gt;= 1
                # and append it to the list      
                series.Append(i)    
                if i &amp;gt; 1     
                    series.Append(" * ")      
                else
                    series.Append(" = ")    
                end
                i -= 1
            end
            # Get the result from the Factorial Method      
            # and append it to the end of the list      
            series.Append(self.factorial(n).to_s)
            # return the list as a string
            series.to_s
         end
         
         # Using a StringBuilder as a list of string elements
         def self.get_fibonnaci_series(n)
            # Create the String that will hold the list      
            series = StringBuilder.new
            # We begin by concatenating the first 3 values which      
            # are always constant
            series.Append("0, 1, 1")      
            # Then we calculate the Fibonacci of each element      
            # and add append it to the list      
            for i in 2..n    
                if i &amp;lt; n    
                    series.Append(", ")     
                else 
                    series.Append(" = ")
                end
                series.Append(self.fibonacci(i))
            end
            # return the list as a string      
            series.to_s  
         end
         
        def self.factorial(n)
            if n &amp;lt; 2
                BigInteger.One
            else
                BigInteger.Multiply(BigInteger.new(n), self.factorial(n - 1))                
            end
        end
        
        def self.fibonacci(n)
            if n &amp;lt; 2
                1
            else
                self.fibonacci(n - 1) + self.fibonacci(n - 2)
            end
        end
    end
    
    # Printing Factorial Series      
    puts ""    
    puts Fiborial::get_factorial_series(5)    
    puts Fiborial::get_factorial_series(7)    
    puts Fiborial::get_factorial_series(9)    
    puts Fiborial::get_factorial_series(11)    
    puts Fiborial::get_factorial_series(40)    
    # Printing Fibonacci Series      
    puts ""    
    puts Fiborial::get_fibonnaci_series(5)    
    puts Fiborial::get_fibonnaci_series(7)    
    puts Fiborial::get_fibonnaci_series(9)    
    puts Fiborial::get_fibonnaci_series(11)    
    puts Fiborial::get_fibonnaci_series(40) 
    
    # Stop and exit  
    puts "Press any key to exit..."  
    gets  
end
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-JVmhmbrLCSY/TiMCva2ItWI/AAAAAAAAF-c/Hq8wJv4YJJE/s1600/Fiborial_Series_IRb.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="270" src="http://1.bp.blogspot.com/-JVmhmbrLCSY/TiMCva2ItWI/AAAAAAAAF-c/Hq8wJv4YJJE/s640/Fiborial_Series_IRb.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;  Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.  &lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;require "mscorlib"  

# Instance Class  
class Fiborial
    # Instance Field    
    @instance_count = 0
    # Static Field
    @@static_count = 0    
    # Instance Read-Only Getter
    def get_instance_count()     
        @instance_count    
    end    
    # Static Read-Only Getter
    def self.get_static_count()          
        @@static_count
    end    
    # Instance Constructor/Initializer
    def initialize()  
        @instance_count = 0
        puts "\nInstance Constructor #{@instance_count}"
    end
    # No Static Constructor/Initializer
    # You can do a self.initialize() static method, but it will not be called
    #def self.initialize()
    #    @@static_count = 0  
    #    puts "\nStatic Constructor #{@@static_count}"
    # Instance Method
    def factorial(n)  
        @instance_count += 1     
        puts "\nFactorial(#{n.to_s})"
    end
    # Static Method   
    def self.fibonacci(n)
        @@static_count += 1    
        puts "\nFibonacci(#{n.to_s})"
    end        
  
    # Calling Static Constructor and Methods      
    # No need to instantiate      
    Fiborial::fibonacci(5)    
        
    # Calling Instance Constructor and Methods      
    # Instance required      
    fib = Fiborial.new      
    fib.factorial(5)
  
    Fiborial::fibonacci(15)    
    fib.factorial(5)
        
    # Calling Instance Constructor and Methods      
    # for a second object      
    fib2 = Fiborial.new   
    fib2.factorial(5)    
        
    puts ""
    # Calling Static Getter    
    puts "Static Count = #{Fiborial::get_static_count}" 
    # Calling Instance Property of object 1 and 2      
    puts "Instance 1 Count = #{fib.get_instance_count}"
    puts "Instance 2 Count = #{fib2.get_instance_count}"
        
    gets
end
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-zU3VtzBQzbA/TiMNY9I9a2I/AAAAAAAAF-g/o1kXybGNWNA/s1600/FiborialExtras2IRb.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-zU3VtzBQzbA/TiMNY9I9a2I/AAAAAAAAF-g/o1kXybGNWNA/s1600/FiborialExtras2IRb.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using int, float, System.Numerics.BigInteger&lt;/b&gt;  &lt;br /&gt;
So, it looks like integers in python can hold big integers, so using (Iron)Ruby int/long or System.Numerics.BigInteger is the same so not much to say here.  NOTE: as with the previous scripts you need to manually add a reference to the System.Numerics.dll assembly to your project &amp;nbsp; or SearchPath + require &amp;nbsp;so you can add it to your code.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="ruby" name="code"&gt;require "mscorlib"
require "System"
require "System.Numerics.dll"

include System::Numerics
include System::Diagnostics
    
# Int/Long Factorial    
def factorial_int(n)
    if n == 1
        1.to_i
    else    
        (n * factorial_int(n - 1)).to_i
    end
end
# double/float Factorial
def factorial_float(n)
    if n == 1  
        1.0
    else
        (n * factorial_float(n - 1)).to_f
    end
end
# BigInteger Factorial       
def factorial_bigint(n)
    if n == 1  
        BigInteger.One
    else          
        BigInteger.Multiply(BigInteger.new(n), factorial_bigint(n-1))  
    end
end

timer = Stopwatch.new
facIntResult = 0  
facDblResult = 0.0    
facBigResult = BigInteger.Zero  
i = 0    
        
puts "\nFactorial using Int/Long"
# Benchmark Factorial using Int64      
for i in (5..50).step(5)
    timer.Start 
    facIntResult = factorial_int(i)
    timer.Stop
    puts " (#{i.to_s}) = #{timer.Elapsed} : #{facIntResult}"
end
puts "\nFactorial using Float/Double"
# Benchmark Factorial using Double
for i in (5..50).step(5)
    timer.Start    
    facDblResult = factorial_float(i)    
    timer.Stop
    puts " (#{i.to_s}) = #{timer.Elapsed.to_s} : #{facDblResult.to_s}"
end        
puts "\nFactorial using BigInteger"    
# Benchmark Factorial using BigInteger    
for i in (5..50).step(5)
    timer.Start
    facBigResult = factorial_bigint(i)
    timer.Stop
    puts " (#{i.to_s}) = #{timer.Elapsed.to_s} : #{facBigResult.to_s}"
end

gets
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/--d03BoMpHy0/TiMSjbVj0rI/AAAAAAAAF-o/cAkUp4zgIog/s1600/FiborialExtrasIRb3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="516" src="http://2.bp.blogspot.com/--d03BoMpHy0/TiMSjbVj0rI/AAAAAAAAF-o/cAkUp4zgIog/s640/FiborialExtrasIRb3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/fok9V3JFO58" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/4053867735005040097/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/07/factorial-and-fibonacci-in-ironruby.html#comment-form" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4053867735005040097?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/4053867735005040097?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/fok9V3JFO58/factorial-and-fibonacci-in-ironruby.html" title="Factorial and Fibonacci in IronRuby" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-Mk-Pxl-KHCE/TiL8Lna2geI/AAAAAAAAF-Y/0fD7GR6Jde0/s72-c/FiborialIRb.png" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/07/factorial-and-fibonacci-in-ironruby.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0UDQ3c_fyp7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-275433060648050337</id><published>2011-07-11T15:40:00.000-07:00</published><updated>2012-03-17T02:07:52.947-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:07:52.947-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="IronPython" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in IronPython</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in IronPython that implements 2 classes. There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally a main function called as module level code.&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
WARNING: the code that you will see below is not following python(ic) guidelines/idiomatic coding, I did it in purpose to compare python's syntax and features side by side with other programming languages... For instance, instead of using a python int or long I imported and used System.Numerics.BigInteger instead. Other examples, naming convention and so on, so bear with me!&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;# Factorial and Fibonacci in IronPython
import clr
clr.AddReference('System.Numerics.dll')
from System.Numerics import BigInteger
from System import Console
from System.Diagnostics import Stopwatch

# Instance Class
# static classes are not supported in Python
class StaticFiborial:
    # Static Field
    __className = ''
    # no builtin static constructor/initializer support
    # you can initialize field at this point and even add extra code
    __className = 'Static Initializer'
    print __className
    # Static Method - Factorial Recursive  
    @staticmethod
    def factorialR(n):
        if n == 1:
            return BigInteger.One            
        else:            
            return BigInteger.Multiply(BigInteger(n), StaticFiborial.factorialR(n-1))            
    # Static Method - Factorial Imperative
    @staticmethod
    def factorialI(n):
        res = BigInteger.One        
        for i in range(n, 1, -1):
            res = BigInteger.Multiply(res, BigInteger(i))
        return res
    # Static Method - Fibonacci Recursive 
    @staticmethod
    def fibonacciR(n):
        if n &amp;lt; 2:
            return 1
        else:
            return StaticFiborial.fibonacciR(n - 1) + StaticFiborial.fibonacciR(n - 2)
    # Static Method - Fibonacci Imperative
    @staticmethod
    def fibonacciI(n):
        pre, cur, tmp = 0, 0, 0
        pre, cur = 1, 1
        for i in range(2, n + 1):  
            tmp = cur + pre  
            pre = cur  
            cur = tmp  
        return cur 
    # Static Method - Benchmarking Algorithms 
    @staticmethod
    def benchmarkAlgorithm(algorithm, values):
        timer = Stopwatch()
        i = 0  
        testValue = 0  
        facTimeResult = BigInteger.Zero
        fibTimeResult = 0    
          
        # 'if-elif-else' Flow Control Statement    
        if algorithm == 1:  
            print '\nFactorial Imperative:'  
            # 'For in range' Loop Statement   
            for i in range(values.Count):                  
                testValue = values[i]  
                # Taking Time    
                timer.Start()  
                facTimeResult = StaticFiborial.factorialI(testValue)  
                timer.Stop()                            
                # Getting Time    
                print ' (' + str(testValue) + ') = ', timer.Elapsed  
        elif algorithm == 2:  
            print '\nFactorial Recursive:'  
            # 'While' Loop Statement  
            while i &amp;lt; len(values):  
                testValue = values[i]  
                # Taking Time    
                timer.Start()  
                facTimeResult = StaticFiborial.factorialR(testValue)  
                timer.Stop()                            
                # Getting Time    
                print ' (' + str(testValue) + ') = ', timer.Elapsed
                i += 1  
        elif algorithm == 3:  
            print '\nFibonacci Imperative:'   
            # 'For in List' Loop Statement               
            for item in values:
                testValue = item  
                # Taking Time  
                timer.Start()  
                fibTimeResult = StaticFiborial.fibonacciI(testValue)  
                timer.Stop()  
                # Getting Time  
                print ' (' + str(testValue) + ') = ', timer.Elapsed                  
        elif algorithm == 4:
            print '\nFibonacci Recursive:'  
            # 'For in List' Loop Statement   
            for item in values:  
                testValue = item  
                # Taking Time  
                timer.Start()  
                fibTimeResult = StaticFiborial.fibonacciR(testValue)  
                timer.Stop()  
                # Getting Time                
                print ' (' + str(testValue) + ') = ', timer.Elapsed
        else:  
            print 'DONG!'

# Instance Class  
class InstanceFiborial(object):
    # Instances Field  
    __className = ''
    # Instance Constructor  
    def __init__(self):  
        self.__className = 'Instance Constructor'
        print self.__className  
    # Instance Method - Factorial Recursive  
    def factorialR(self, n):
        # Calling Static Method  
        return StaticFiborial.factorialR(n)  
    # Instance Method - Factorial Imperative  
    def factorialI(self, n):  
        # Calling Static Method  
        return StaticFiborial.factorialI(n)  
    # Instance Method - Fibonacci Recursive    
    def fibonacciR(self, n):
        # Calling Static Method  
        return StaticFiborial.fibonacciR(n)  
    # Instance Method - Fibonacci Imperative  
    def fibonacciI(self, n):  
        # Calling Static Method  
        return StaticFiborial.fibonacciI(n)  


# Console Program  
def main():
    print 'Static Class'  
    # Calling Static Class and Methods  
    # No instantiation needed. Calling method directly from the class  
    print 'FacImp(5) = ', StaticFiborial.factorialI(5)
    print 'FacRec(5) = ', StaticFiborial.factorialR(5)
    print 'FibImp(11)= ', StaticFiborial.fibonacciI(11)
    print 'FibRec(11)= ', StaticFiborial.fibonacciR(11)
  
    print '\nInstance Class'  
    # Calling Instance Class and Methods  
    # Need to instantiate before using. Calling method from instantiated object  
    ff = InstanceFiborial()
    print 'FacImp(5) = ', ff.factorialI(5)
    print 'FacRec(5) = ', ff.factorialR(5)
    print 'FibImp(11)= ', ff.fibonacciI(11)
    print 'FibRec(11)= ', ff.fibonacciR(11)
  
    # Create a (Python) list of values to test    
    # From 5 to 50 by 5  
    values = []
    for i in range(5,55,5):
        values.append(i)

    # Benchmarking Fibonacci  
    # 1 = Factorial Imperative  
    StaticFiborial.benchmarkAlgorithm(1, values)  
    # 2 = Factorial Recursive  
    StaticFiborial.benchmarkAlgorithm(2, values) 
    # Benchmarking Factorial  
    # 3 = Fibonacci Imperative  
    StaticFiborial.benchmarkAlgorithm(3, values)  
    # 4 = Fibonacci Recursive  
    StaticFiborial.benchmarkAlgorithm(4, values)
    
    # Stop and exit
    Console.Read()  
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-tnqFKsQMzR0/ThX8SkT41vI/AAAAAAAAF7g/rGR8Fwnh9a8/s1600/FiborialIPy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-tnqFKsQMzR0/ThX8SkT41vI/AAAAAAAAF7g/rGR8Fwnh9a8/s640/FiborialIPy.png" width="312" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import clr
clr.AddReference('System.Numerics.dll')
from System.Numerics import BigInteger
from System.Text import StringBuilder
from System import Console

class Fiborial:  
    # Using a StringBuilder as a list of string elements    
    @staticmethod
    def getFactorialSeries(n):
        # Create the String that will hold the list    
        series = StringBuilder()   
        # We begin by concatenating the number you want to calculate    
        # in the following format: "!# ="    
        series.Append("!")  
        series.Append(n)  
        series.Append(" = ")
        # We iterate backwards through the elements of the series    
        for i in range(n, 0, -1):
            # and append it to the list    
            series.Append(i)  
            if i &amp;gt; 1:   
                series.Append(" * ")    
            else:     
                series.Append(" = ")  
        # Get the result from the Factorial Method    
        # and append it to the end of the list    
        series.Append(Fiborial.factorial(n).ToString())
        # return the list as a string    
        return series.ToString()  
  
    # Using a StringBuilder as a list of string elements    
    @staticmethod
    def getFibonnaciSeries(n):  
        # Create the String that will hold the list    
        series = StringBuilder()
        # We begin by concatenating the first 3 values which    
        # are always constant    
        series.Append("0, 1, 1")    
        # Then we calculate the Fibonacci of each element    
        # and add append it to the list    
        for i in range(2, n+1):  
            if i &amp;lt; n:  
                series.Append(", ")   
            else:  
                series.Append(" = ")    
            series.Append(Fiborial.fibonacci(i))  
        # return the list as a string    
        return series.ToString()  
    @staticmethod      
    def factorial(n):
        if n == 1:
            return BigInteger.One
        else:            
            return BigInteger.Multiply(BigInteger(n), Fiborial.factorial(n-1))
    @staticmethod  
    def fibonacci(n):  
        if n &amp;lt; 2:  
            return 1    
        else:    
            return Fiborial.fibonacci(n - 1) + Fiborial.fibonacci(n - 2)  
  
def main():
    # Printing Factorial Series    
    print ""  
    print Fiborial.getFactorialSeries(5)  
    print Fiborial.getFactorialSeries(7)  
    print Fiborial.getFactorialSeries(9)  
    print Fiborial.getFactorialSeries(11)  
    print Fiborial.getFactorialSeries(40)  
    # Printing Fibonacci Series    
    print ""  
    print Fiborial.getFibonnaciSeries(5)  
    print Fiborial.getFibonnaciSeries(7)  
    print Fiborial.getFibonnaciSeries(9)  
    print Fiborial.getFibonnaciSeries(11)  
    print Fiborial.getFibonnaciSeries(40)  
      
    Console.Read()  
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-XM4_l-j8tYU/Tht2n3AVy6I/AAAAAAAAF74/20lNDz_-FeI/s1600/Fiborial_Series_IPy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="274" src="http://1.bp.blogspot.com/-XM4_l-j8tYU/Tht2n3AVy6I/AAAAAAAAF74/20lNDz_-FeI/s640/Fiborial_Series_IPy.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;from System import Console
    
# Instance Class
class Fiborial:
    # Instance Field  
    __instanceCount = 0
    # Static Field      
    __staticCount = 0    
    print "\nStatic Constructor", __staticCount
    # Instance Read-Only Property    
    # Within instance members, you can always use      
    # the "self" reference pointer to access your (instance) members.              
    def getInstanceCount(self):   
        return self.__instanceCount  
    InstanceCount = property(getInstanceCount, None, None)
    # Static Property
    # looks like it is not supported even if the code identify it as such    
    @staticmethod
    def getStaticCount():        
        return Fiborial.__staticCount        
    #StaticCount = property(getStaticCount, None, None)
    # The problem seems to be the use of: property(getStaticCount,..)
    # it requires an instance method and not a static one (Test.getStaticCount)    
    # Instance Constructor    
    def __init__(self):
        self.__instanceCount = 0    
        print "\nInstance Constructor", self.__instanceCount
    # No Static Constructor    
    #@staticmethod
    #def __init__():
    #    Fiborial.__staticCount = 0
    #    print "\nStatic Constructor", Fiborial.__staticCount
    # Instance Method
    def factorial(self, n):
        self.__instanceCount += 1   
        print "\nFactorial(" + str(n) + ")"
    # Static Method
    @staticmethod    
    def fibonacci(n):
        Fiborial.__staticCount += 1  
        print "\nFibonacci(" + str(n) + ")"

def main():
    # Calling Static Constructor and Methods    
    # No need to instantiate    
    Fiborial.fibonacci(5)  
      
    # Calling Instance Constructor and Methods    
    # Instance required    
    fib = Fiborial()    
    fib.factorial(5)  

    Fiborial.fibonacci(15)  
    fib.factorial(5)  
      
    # Calling Instance Constructor and Methods    
    # for a second object    
    fib2 = Fiborial()  
    fib2.factorial(5)  
      
    print ""  
    # Calling Static Property
    # using the static method referenced by the property
    #print "Static Count =", Fiborial.StaticCount
    print "Static Count =", Fiborial.getStaticCount()
    # Calling Instance Property of object 1 and 2    
    print "Instance 1 Count =", fib.InstanceCount
    print "Instance 2 Count =", fib2.InstanceCount
      
    Console.Read()  
  
if __name__ == '__main__':
    main()
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-NBK3O44FDgM/TiMOK6bvXNI/AAAAAAAAF-k/LqiPbjt45Bg/s1600/FiborialExtras2IPy.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://1.bp.blogspot.com/-NBK3O44FDgM/TiMOK6bvXNI/AAAAAAAAF-k/LqiPbjt45Bg/s320/FiborialExtras2IPy.png" width="302" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using int, float, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
So, it looks like integers in python can hold big integers, so using (Iron)Python int/long or System.Numerics.BigInteger is the same so not much to say here.&lt;br /&gt;
&lt;br /&gt;
NOTE: as with the previous scripts you need to manually add a reference to the System.Numerics.dll assembly to your project &amp;nbsp; or SearchPath + clr.AddReference &amp;nbsp;so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="python" name="code"&gt;import clr
clr.AddReference('System.Numerics.dll')
from System.Numerics import BigInteger
from System import Console
from System.Diagnostics import Stopwatch
  
# Int/Long Factorial  
def factorial_int(n):  
    if n == 1:
        return int(1)
    else:  
        return int(n * factorial_int(n - 1))
      
# double/float Factorial
def factorial_float(n):
    if n == 1:
        return float(1.0)
    else:  
        return float(n * factorial_float(n - 1))

# BigInteger Factorial     
def factorial_bigint(n):
    if n == 1:
        return BigInteger.One            
    else:            
        return BigInteger.Multiply(BigInteger(n), factorial_bigint(n-1))
  
timer = Stopwatch()  
facIntResult = 0
facDblResult = 0.0  
facBigResult = BigInteger.Zero
i = 0  
      
print "\nFactorial using Int/Long"
# Benchmark Factorial using Int64    

for i in range(5,55,5):  
    timer.Start()
    facIntResult = factorial_int(i)
    timer.Stop()          
    print " (" + str(i) + ") =", timer.Elapsed, " :", facIntResult  
      
print "\nFactorial using Float/Double"  
# Benchmark Factorial using Double  
for i in range(5,55,5):
    timer.Start()  
    facDblResult = factorial_float(i)  
    timer.Stop()          
    print " (" + str(i) + ") =", timer.Elapsed, " :", facDblResult
      
print "\nFactorial using BigInteger"  
# Benchmark Factorial using BigInteger  
for i in range(5,55,5):  
    timer.Start()
    facBigResult = factorial_bigint(i)  
    timer.Stop()
    print " (" + str(i) + ") =", timer.Elapsed, " :", facBigResult    

Console.Read()
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-AVvFlDHlo4U/Tht52dZ7khI/AAAAAAAAF78/uZkSvNryWIc/s1600/FiborialExtrasIPy3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="516" src="http://3.bp.blogspot.com/-AVvFlDHlo4U/Tht52dZ7khI/AAAAAAAAF78/uZkSvNryWIc/s640/FiborialExtrasIPy3.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;br /&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Zu_I07lCxWc" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/275433060648050337/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/07/factorial-and-fibonacci-in-ironpython.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/275433060648050337?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/275433060648050337?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Zu_I07lCxWc/factorial-and-fibonacci-in-ironpython.html" title="Factorial and Fibonacci in IronPython" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-tnqFKsQMzR0/ThX8SkT41vI/AAAAAAAAF7g/rGR8Fwnh9a8/s72-c/FiborialIPy.png" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/07/factorial-and-fibonacci-in-ironpython.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUFR3oycCp7ImA9WhVXGUw.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-2121608085704135337</id><published>2011-06-02T07:10:00.000-07:00</published><updated>2012-04-20T02:30:16.498-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-20T02:30:16.498-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Cobra" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Cobra</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script data-counter="right" type="IN/Share"&gt;
&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Cobra that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;# Factorial and Fibonacci in Cobra  
use System.Collections.Generic  
use System.Diagnostics  
use System.Numerics  

namespace FiborialCobra
  
    # Static Class
    class StaticFiborial is public
        shared
            # Static Field  
            var __className as String  
            # Static Constructor  
            cue init
                __className = 'Static Constructor'
                print '[__className]'
            # Static Method - Factorial Recursive    
            def factorialR(n as int) as BigInteger is public
                if n == 1 
                    return BigInteger.one
                else                        
                    return BigInteger.multiply(BigInteger(n), .factorialR(n - 1))
            # Static Method - Factorial Imperative    
            def factorialI(n as int) as BigInteger is public                
                res as BigInteger = BigInteger.one
                for i as int in n:0:-1
                    res = BigInteger.multiply(res, BigInteger(i))
                return res
            # Static Method - Fibonacci Recursive    
            def fibonacciR(n as int) as int64 is public
                if n &amp;lt; 2  
                    return 1
                else    
                    return .fibonacciR(n - 1) + .fibonacciR(n - 2)  
            # Static Method - Fibonacci Imperative  
            def fibonacciI(n as int) as int64 is public  
                pre as int64 = 1  
                cur as int64 = 1  
                tmp as int64 = 0  
                for i as int in 2:n+1
                    tmp = cur + pre
                    pre = cur  
                    cur = tmp  
                    i=i # ignore compiler warning
                return cur
            # Static Method - Benchmarking Algorithms  
            def benchmarkAlgorithm(algorithm as int, values as List&amp;lt;of int&amp;gt;) is public  
                timer as Stopwatch = Stopwatch()  
                i as int = 0
                testValue as int = 0  
                facTimeResult as BigInteger = BigInteger.zero                
                fibTimeResult as int64 = 0
                facTimeResult = facTimeResult
                fibTimeResult = fibTimeResult
                
                # "if-elif-else" Flow Control Statement
                if algorithm == 1  
                    print '\nFactorial Imperative:'
                    # "For in range" Loop Statement   
                    for i as int in values.count                  
                        testValue = values[i]
                        # Taking Time    
                        timer.start  
                        facTimeResult = .factorialI(testValue)  
                        timer.stop
                        # Getting Time    
                        print ' ([testValue]) = [timer.elapsed]'
                else if algorithm == 2  
                    print '\nFactorial Recursive:'
                    # "While" Loop Statement  
                    while i &amp;lt; values.count
                        testValue = values[i]  
                        # Taking Time    
                        timer.start
                        facTimeResult = .factorialR(testValue)
                        timer.stop
                        # Getting Time    
                        print ' ([testValue]) = [timer.elapsed]'
                        i += 1  
                else if algorithm == 3
                    print "\nFibonacci Imperative:"   
                    # "Do-While" Loop Statement  
                    post while i &amp;lt; values.count
                        testValue = values[i]  
                        # Taking Time  
                        timer.start
                        fibTimeResult = .fibonacciI(testValue)  
                        timer.stop  
                        # Getting Time  
                        print ' ([testValue]) = [timer.elapsed]'
                        i += 1  
                else if algorithm == 4  
                    print "\nFibonacci Recursive:"  
                    # "For in List" Loop Statement   
                    for i as int in values.count
                        testValue = values[i]
                        # Taking Time  
                        timer.start 
                        fibTimeResult = .fibonacciR(testValue)  
                        timer.stop
                        # Getting Time  
                        print ' ([testValue]) = [timer.elapsed]'
                else  
                    print 'DONG!'

    # Instance Class  
    class InstanceFiborial is public
        # Instances Field  
        var __className as String  
        # Instance Constructor  
        cue init  
            base.init
            __className = "Instance Constructor"  
            print __className  
        # Instance Method - Factorial Recursive  
        def factorialR(n as int) as BigInteger is public 
            # Calling Static Method  
            return StaticFiborial.factorialR(n)  
        # Instance Method - Factorial Imperative  
        def factorialI(n as int) as BigInteger is public 
            # Calling Static Method  
            return StaticFiborial.factorialI(n)  
        # Instance Method - Fibonacci Recursive    
        def fibonacciR(n as int) as int64 is public
            # Calling Static Method  
            return StaticFiborial.fibonacciR(n)  
        # Instance Method - Fibonacci Imperative  
        def fibonacciI(n as int) as int64 is public  
            # Calling Static Method  
            return StaticFiborial.fibonacciI(n)  
                    
    # Console Program  
    class Program is public  
        def main is shared 
            print '\nStatic Class'  
            # Calling Static Class and Methods  
            # No instantiation needed. Calling method directly from the class  
            print 'FacImp(5) = [StaticFiborial.factorialI(5)]'  
            print 'FacRec(5) = [StaticFiborial.factorialR(5)]'  
            print 'FibImp(11)= [StaticFiborial.fibonacciI(11)]'  
            print 'FibRec(11)= [StaticFiborial.fibonacciR(11)]'  
          
            print '\nInstance Class'  
            # Calling Instance Class and Methods  
            # Need to instantiate before using. Call method from instantiated obj  
            ff as InstanceFiborial = InstanceFiborial()
            print 'FacImp(5) = [ff.factorialI(5)]'  
            print 'FacRec(5) = [ff.factorialR(5)]'  
            print 'FibImp(11)= [ff.fibonacciI(11)]'  
            print 'FibRec(11)= [ff.fibonacciR(11)]'  
          
            # Create a List of integer values to test  
            # From 5 to 50 by 5  
            values as List&amp;lt;of int&amp;gt; = List&amp;lt;of int&amp;gt;()  
            for i as int in 5:55:5
                values.add(i)

            # Benchmarking Fibonacci  
            # 1 = Factorial Imperative  
            StaticFiborial.benchmarkAlgorithm(1, values)  
            # 2 = Factorial Recursive  
            StaticFiborial.benchmarkAlgorithm(2, values)  
            # Benchmarking Factorial  
            # 3 = Fibonacci Imperative  
            StaticFiborial.benchmarkAlgorithm(3, values)  
            # 4 = Fibonacci Recursive  
            StaticFiborial.benchmarkAlgorithm(4, values)
          
            # Stop and Exit  
            Console.read
&lt;/pre&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-Lj5qDjfbtfg/TeeZH2K6ZcI/AAAAAAAAF6s/OxsUisdbE4M/s1600/fiborial_cobra.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://1.bp.blogspot.com/-Lj5qDjfbtfg/TeeZH2K6ZcI/AAAAAAAAF6s/OxsUisdbE4M/s640/fiborial_cobra.PNG" width="268" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;use System.Text  
use System.Numerics  

namespace FiborialSeries   
    # Instance Class    
    class Fiborial is public
        shared
            # Using a StringBuilder as a list of string elements    
            def getFactorialSeries(n as int) as String is public
                # Create the String that will hold the list    
                series as StringBuilder = StringBuilder()   
                # We begin by concatenating the number you want to calculate    
                # in the following format: '!# ='    
                series.append('!')  
                series.append(n)  
                series.append(' = ')  
                # We iterate backwards through the elements of the series    
                for i as int in n:0:-1  
                    # and append it to the list    
                    series.append(i)  
                    if i &amp;gt; 1   
                        series.append(' * ')    
                    else  
                        series.append(' = ')  
                # Get the result from the Factorial Method    
                # and append it to the end of the list    
                series.append(.factorial(n))  
                # return the list as a string    
                return series.toString 
          
            # Using a StringBuilder as a list of string elements    
            def getFibonnaciSeries(n as int) as String is public
                # Create the String that will hold the list
                series as StringBuilder = StringBuilder()   
                # We begin by concatenating the first 3 values which    
                # are always constant    
                series.append('0, 1, 1')    
                # Then we calculate the Fibonacci of each element    
                # and add append it to the list    
                for i as int in 2:n+1
                    if i &amp;lt; n  
                        series.append(', ')   
                    else
                        series.append(' = ')    
                    series.append(.fibonacci(i))  
                # return the list as a string    
                return series.toString 
                  
            def factorial(n as int) as BigInteger is public
                if n == 1
                    return BigInteger.one
                else
                    return BigInteger.multiply(BigInteger(n), .factorial(n - 1))
              
            def fibonacci(n as int) as int64 is public
                if n &amp;lt; 2
                    return 1    
                else    
                    return .fibonacci(n - 1) + .fibonacci(n - 2)  
      
    # Console Program  
    class Program is public  
        def main is shared 
            # Printing Factorial Series    
            print ''  
            print Fiborial.getFactorialSeries(5)  
            print Fiborial.getFactorialSeries(7)  
            print Fiborial.getFactorialSeries(9)  
            print Fiborial.getFactorialSeries(11)  
            print Fiborial.getFactorialSeries(40)  
            # Printing Fibonacci Series    
            print ''  
            print Fiborial.getFibonnaciSeries(5)  
            print Fiborial.getFibonnaciSeries(7)  
            print Fiborial.getFibonnaciSeries(9)  
            print Fiborial.getFibonnaciSeries(11)  
            print Fiborial.getFibonnaciSeries(40)  
              
            Console.read
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-kbLSRzBwIDE/TeeZN1_AbxI/AAAAAAAAF6w/AMhipV69jm0/s1600/fiborial_cobra_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="282" src="http://2.bp.blogspot.com/-kbLSRzBwIDE/TeeZN1_AbxI/AAAAAAAAF6w/AMhipV69jm0/s640/fiborial_cobra_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;namespace FiborialExtrasCobra2  
      
    # Instance Classes can have both: static and instance members.
          
    # Instance Class    
    class Fiborial is public  
        # Instance Field  
        var __instanceCount as int
        # Static Field  
        var __staticCount as int is shared 
        # Instance Read-Only Property            
        pro instanceCount as int is public  
            get  
                return __instanceCount          
        # Static Read-Only Property    
        # Remeber that Properties are Methods to the CLR, so, 
        # you can also define static properties for static fields.             
        pro staticCount as int is shared, public
            get    
                return __staticCount    
        # Instance Constructor    
        cue init
            base.init
            __instanceCount = 0
            print '\nInstance Constructor [__instanceCount]'  
        # Static Constructor    
        cue init is shared        
            __staticCount = 0    
            print '\nStatic Constructor [__staticCount]'
        # Instance Method  
        def factorial(n as int) is public
            __instanceCount += 1   
            print '\nFactorial([n])'   
        # Static Method    
        def fibonacci(n as int) is shared, public
            __staticCount += 1  
            print '\nFibonacci([n])'   
      
    # Console Program  
    class Program is public
        def main is shared     
            # Calling Static Constructor and Methods    
            # No need to instantiate    
            Fiborial.fibonacci(5)  
              
            # Calling Instance Constructor and Methods    
            # Instance required    
            fib as Fiborial = Fiborial()    
            fib.factorial(5)  
              
            Fiborial.fibonacci(15)  
            fib.factorial(5)  
              
            # Calling Instance Constructor and Methods    
            # for a second object    
            fib2 as Fiborial = Fiborial()  
            fib2.factorial(5)  
              
            print ''  
            # Calling Static Property    
            print 'Static Count = [Fiborial.staticCount]'  
            # Calling Instance Property of object 1 and 2    
            print 'Instance 1 Count = [fib.instanceCount]'  
            print 'Instance 2 Count = [fib2.instanceCount]'  
            Console.read
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-LcVR31CzHi0/TeeZPqzTLfI/AAAAAAAAF60/aCUZ_b2cqVI/s1600/fiborial_cobra_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="350" src="http://3.bp.blogspot.com/-LcVR31CzHi0/TeeZPqzTLfI/AAAAAAAAF60/aCUZ_b2cqVI/s400/fiborial_cobra_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;a href="http://4.bp.blogspot.com/_0_HCzHGe4_k/TM8x5bVLv0I/AAAAAAAAFyU/ZHtgJE97Fdk/s1600/delphi_properties.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double/Float, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;use System.Diagnostics  
use System.Numerics  

namespace FiborialExtrasCobra3  

    class FiborialExtrasProgram 
        shared            

            def main
                timer as Stopwatch = Stopwatch()  
                facIntResult as int64 = 0  
                facDblResult as float = 0  
                facBigResult as BigInteger = BigInteger.zero
                i as int = 0
                  
                print '\nFactorial using Int64'  
                # Benchmark Factorial using Int64                    
                for i as int in 5:55:5  
                    timer.start
                    facIntResult = .factorialInt64(i)  
                    timer.stop         
                    print ' ([i]) = [timer.elapsed] : [facIntResult]'  
                  
                print '\nFactorial using Float'  
                # Benchmark Factorial using float  
                for i as int in 5:55:5  
                    timer.start
                    facDblResult = .factorialFloat(i)  
                    timer.stop         
                    print ' ([i]) = [timer.elapsed] : [facDblResult]'  
                  
                print '\nFactorial using BigInteger'  
                # Benchmark Factorial using BigInteger  
                for i as int in 5:55:5  
                    timer.start
                    facBigResult = .factorialBigInteger(i)  
                    timer.stop         
                    print ' ([i]) = [timer.elapsed] : [facBigResult]'  
                  
                Console.read
                
            # Long Factorial  
            def factorialInt64(n as int) as int64
                if n == 1  
                    return 1  
                else  
                    return n * .factorialInt64(n - 1)  
                  
            # float/Number Factorial     
            def factorialFloat(n as int) as float
                if n == 1  
                    return 1  
                else  
                    return n * .factorialFloat(n - 1)  
               
            # BigInteger Factorial     
            def factorialBigInteger(n as int) as BigInteger   
                if n == 1  
                    return BigInteger.one  
                else  
                    return BigInteger.multiply(BigInteger(n), .factorialBigInteger(n - 1))
&lt;/pre&gt;
&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-8TTodOsnGuQ/TeeZRQ-VxJI/AAAAAAAAF64/-KBFEytAc-s/s1600/fiborial_cobra_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="490" src="http://2.bp.blogspot.com/-8TTodOsnGuQ/TeeZRQ-VxJI/AAAAAAAAF64/-KBFEytAc-s/s640/fiborial_cobra_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/VW3gHanyLa8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/2121608085704135337/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/06/factorial-and-fibonacci-in-cobra.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2121608085704135337?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/2121608085704135337?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/VW3gHanyLa8/factorial-and-fibonacci-in-cobra.html" title="Factorial and Fibonacci in Cobra" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-Lj5qDjfbtfg/TeeZH2K6ZcI/AAAAAAAAF6s/OxsUisdbE4M/s72-c/fiborial_cobra.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/06/factorial-and-fibonacci-in-cobra.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QBQ30_eCp7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7336081667902266861</id><published>2011-05-15T15:56:00.001-07:00</published><updated>2012-03-17T02:09:12.340-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:09:12.340-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Stopwatch class for Java</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to continue with my next "Factorial and Fibonacci" posts in some Java/JVM languages; I was looking for an official Java version of the .NET Timer class "Stopwatch" (System.Diagnostics.Stopwatch), so I can measure and display the elapsed time results in the same way I had been doing it in my previous posts. &lt;br /&gt;
&lt;br /&gt;
Let's show some C# code of what I meant before continuing.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;
using System.Numerics;
using System.Diagnostics;

namespace CSStopwatchApp
{
    class StopwatchApp
    {
        static void Main(string[] args)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();
            Fibonacci(50);
            timer.Stop();

            Console.WriteLine("Elapsed time in ticks: {0}", 
                timer.Elapsed.Ticks);
            Console.WriteLine("Elapsed time in milliseconds: {0}", 
                timer.Elapsed.Milliseconds);
            Console.WriteLine("Elapsed time in seconds: {0}", 
                timer.Elapsed.Seconds);
            Console.WriteLine("Elapsed time in minutes: {0}", 
                timer.Elapsed.Minutes);
            Console.WriteLine("Elapsed time in hours: {0}", 
                timer.Elapsed.Hours);
            Console.WriteLine("Elapsed time with format: {0}", 
                timer.Elapsed);
        }
                
        private static BigInteger Fibonacci(int n)
        {
            if (n &amp;lt; 2)
                return 1;
            else
                return Fibonacci(n - 1) + Fibonacci(n - 2);
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OpaXn-_3hqE/Tcsjx0Dc0DI/AAAAAAAAF54/CXmaGtLBx6M/s1600/StopwatchFib50_csharp.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="198" src="http://1.bp.blogspot.com/-OpaXn-_3hqE/Tcsjx0Dc0DI/AAAAAAAAF54/CXmaGtLBx6M/s640/StopwatchFib50_csharp.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
However, looks like there isn't one, instead, there are 2 methods used to measure time in Java: System.nanoTime() and System.currentTimeMillis() being the first one more precise when timing code execution.&lt;br /&gt;
&lt;br /&gt;
&lt;hr /&gt;&lt;b&gt;currentTimeMillis&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public static long currentTimeMillis()
&lt;/pre&gt;Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds. &lt;br /&gt;
&lt;br /&gt;
For example, to measure how long some code takes to execute: &lt;br /&gt;
&lt;pre class="java" name="code"&gt;long startTime = System.currentTimeMillis();
   // ... the code being measured ...
   long estimatedTime = System.currentTimeMillis() - startTime;
&lt;/pre&gt;&lt;br /&gt;
Returns:&lt;br /&gt;
the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;nanoTime&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;public static long nanoTime()
&lt;/pre&gt;Returns the current value of the most precise available system timer, in nanoseconds. &lt;br /&gt;
&lt;br /&gt;
This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (263 nanoseconds) will not accurately compute elapsed time due to numerical overflow. &lt;br /&gt;
&lt;br /&gt;
For example, to measure how long some code takes to execute: &lt;br /&gt;
&lt;pre class="java" name="code"&gt;long startTime = System.nanoTime();
   // ... the code being measured ...
   long estimatedTime = System.nanoTime() - startTime;
 &lt;/pre&gt;&lt;br /&gt;
Returns:&lt;br /&gt;
The current value of the system timer, in nanoseconds.&lt;br /&gt;
&lt;hr /&gt;&lt;br /&gt;
So, I decided to do my own version of the Stopwatch class, not before doing some google to see if someone did it already ;) you know, code reuse FTW!&lt;br /&gt;
&lt;br /&gt;
Quickly I found a basic version using System.currentTimeMillis() written by Corey Goldberg and provided with a GPL license here: &lt;a href="http://www.goldb.org/stopwatchjava.html"&gt;http://www.goldb.org/stopwatchjava.html&lt;/a&gt; (thanks man!), so I took it and extended it to use System.nanoTime() instead, and implemented some other missing methods and the most important (for me) the Elapsed time formatted as "hh:mm:ss.sss" using the SimpleDateFormat class, which looks like only considers 3 milliseconds... so I added the rest (the nanoseconds part) to have: 00:00:00.0000000 (hh:mm:ss.sssssss), just like the .NET version output it. Here it is:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Stopwatch class in Java&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;/*
 *  Copyright (c) 2011, Carlos Quintanilla
 *  Special thanks to Corey Goldberg (for his StopWatch.java | Java Timer Class)
 *  here http://www.goldb.org/stopwatchjava.html
 * 
 *  Stopwatch.java is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 */

package stopwatchapp;

import java.text.SimpleDateFormat;
import java.util.Calendar;  

/**
 * @author Carlos Quintanilla
 */

public class Stopwatch {
    // constants
    private final long nsPerTick = 100;
    private final long nsPerMs = 1000000;
    private final long nsPerSs = 1000000000;
    private final long nsPerMm = 60000000000L;
    private final long nsPerHh = 3600000000000L;

    private long startTime = 0;
    private long stopTime = 0;
    private boolean running = false;
    
    /**
     * Starts measuring elapsed time
     * for an interval.
     */
    public void start() {
        this.startTime = System.nanoTime();       
        this.running = true;
    }
    
    /**
     * Stops measuring elapsed time
     * for an interval.
     */
    public void stop() {
        this.stopTime = System.nanoTime();
        this.running = false;
    }
    
    /**
     * Stops time interval measurement 
     * and resets the elapsed time to zero.
     */ 
    public void reset() {
        this.startTime = 0;
        this.stopTime = 0;
        this.running = false;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in nanoseconds.
     * 1 Tick = 100 nanoseconds 
     */
    public long getElapsedTicks() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }
        return elapsed / nsPerTick;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in milliseconds.
     * 10000 Ticks = 1 millisecond (1000000 nanoseconds)
     */
    public long getElapsedMilliseconds() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }
        return elapsed / nsPerMs;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in seconds.
     * 10000000 Ticks = 1 second (1000 milliseconds)
     */
    public long getElapsedSeconds() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }        
        return elapsed / nsPerSs;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in minutes.
     * 600000000 Ticks = 1 minute (60 seconds)
     */
    public long getElapsedMinutes() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }        
        return elapsed / nsPerMm;
    }
    
    /**
     * Gets the total elapsed time measured 
     * by the current instance, in hours.
     * 36000000000 Ticks = 1 hour (60 minutes)
     */
    public long getElapsedHours() {
        long elapsed;
        if (running) {
             elapsed = (System.nanoTime() - startTime);
        }
        else {
            elapsed = (stopTime - startTime);
        }        
        return elapsed / nsPerHh;
    }
    
    /**
     * Gets the total elapsed time with format 
     * 00:00:00.0000000 = 00:mm:ss.SSS + 9999 Ticks
     */ 
    public String getElapsed() {
        String timeFormatted = "";
        timeFormatted = this.formatTime(this.getElapsedTicks());        
        return timeFormatted;
    }
    
    /**
     * Gets the total elapsed time with format 
     * 00:00:00.0000000 = 00:mm:ss.SSS + #### Ticks
     * @param elapsedTicks elapsed ticks between start and stop nano time
     */ 
    private String formatTime(final long elapsedTicks) {        
        String formattedTime = "";
        // should be hh:mm:ss.SSS, but 00 starts with 01 
        SimpleDateFormat formatter = new SimpleDateFormat("00:mm:ss.SSS");
        Calendar calendar = Calendar.getInstance();        
        
        if (elapsedTicks &amp;lt;= 9999) {
            calendar.setTimeInMillis(0);
            formattedTime = formatter.format(calendar.getTime()) 
                    + String.valueOf(String.format("%04d", elapsedTicks));
        }
        else {
            calendar.setTimeInMillis(elapsedTicks * nsPerTick / nsPerMs);            
            String formattedTicks = String.format("%07d", elapsedTicks);
            formattedTicks = formattedTicks.substring(formattedTicks.length() - 4);
            formattedTime = formatter.format(calendar.getTime()) + formattedTicks;
        }
        return formattedTime;
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
If we add that class in any Java project, we can now do what the C# code at the beginning of this post does! Let's see the Java version of the code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package stopwatchapp;
import java.math.BigInteger;

public class StopwatchApp {

    public static void main(String[] args) {
        
        Stopwatch timer = new Stopwatch();
        timer.start();
        Fibonacci(50);
        timer.stop();
        
        System.out.println("Elapsed time in ticks: " 
            + timer.getElapsedTicks());
        System.out.println("Elapsed time in milliseconds: " 
            + timer.getElapsedMilliseconds());
        System.out.println("Elapsed time in seconds: " 
            + timer.getElapsedSeconds());
        System.out.println("Elapsed time in minutes: " 
            + timer.getElapsedMinutes());
        System.out.println("Elapsed time in hours: " 
            + timer.getElapsedHours());
        System.out.println("Elapsed time with format: " 
            + timer.getElapsed());
    }
    
    private static BigInteger Fibonacci(int n)
    {
        if (n &amp;lt; 2)
            return BigInteger.ONE;
        else
            return Fibonacci(n - 1).add(Fibonacci(n - 2));
    }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-DyS62UU_nMU/Tcsn0ib4pmI/AAAAAAAAF6A/LHp8CZdmTQs/s1600/StopwatchFib50_java.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="238" src="http://4.bp.blogspot.com/-DyS62UU_nMU/Tcsn0ib4pmI/AAAAAAAAF6A/LHp8CZdmTQs/s640/StopwatchFib50_java.png" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That's it! now I'm ready to work on the next posts using this java timer class. Hope it is helpful to you too since I found lot's of forums asking for it and the answer was always use: System.nanoTime() and System.currentTimeMillis() &lt;br /&gt;
&lt;br /&gt;
By the way, if you want to run the example, change Fibonacci(50) to a lower value such as Fibonacci(35 or 40) to not wait for the result some minutes.&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/AnXKYivMiIE" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7336081667902266861/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html#comment-form" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7336081667902266861?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7336081667902266861?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/AnXKYivMiIE/stopwatch-class-for-java.html" title="Stopwatch class for Java" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://1.bp.blogspot.com/-OpaXn-_3hqE/Tcsjx0Dc0DI/AAAAAAAAF54/CXmaGtLBx6M/s72-c/StopwatchFib50_csharp.png" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0QCRXc_eSp7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-1304605657994355004</id><published>2011-05-15T15:56:00.000-07:00</published><updated>2012-03-17T02:09:24.941-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:09:24.941-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Java" /><category scheme="http://www.blogger.com/atom/ns#" term="JVM" /><title>Factorial and Fibonacci in Java</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Java that implements 2 classes (in fact, they are 3 + an extra utility Stopwatch class from my previous post &lt;a href="http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html"&gt;http://carlosqt.blogspot.com/2011/05/stopwatch-class-for-java.html&lt;/a&gt;). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including java.math.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;// Factorial and Fibonacci in Java
package fiborial;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

// Instance Class         
// static is not a class modifier in Java
public class StaticFiborial
{  
    // Static Field  
    private static String className;  
    // Static Constructor/Initializer
    static
    {  
        className = "Static Constructor";  
        System.out.println(className);        
    }  
    // Static Method - Factorial Recursive  
    public static BigInteger factorialR(int n)  
    {  
        if (n == 1)  
            return BigInteger.ONE;
        else  
            return BigInteger.valueOf(n).multiply(factorialR(n - 1));
    }  
    // Static Method - Factorial Imperative  
    public static BigInteger factorialI(int n)  
    {  
        BigInteger res = BigInteger.ONE;  
        for (int i = n; i &amp;gt;= 1; i--)  
        {                  
            res = res.multiply(BigInteger.valueOf(i));  
        }  
        return res;
    }  
    // Static Method - Fibonacci Recursive  
    public static long fibonacciR(int n)  
    {  
        if (n &amp;lt; 2)  
            return 1;  
        else  
            return fibonacciR(n - 1) + fibonacciR(n - 2);  
    }  
    // Static Method - Fibonacci Imperative  
    public static long fibonacciI(int n)  
    {              
        long pre, cur, tmp = 0;  
        pre = cur = 1;              
        for (int i = 2; i &amp;lt;= n; i++)  
        {  
            tmp = cur + pre;  
            pre = cur;  
            cur = tmp;  
        }  
        return cur;  
    }      
    // Static Method - Benchmarking Algorithms  
    public static void benchmarkAlgorithm(int algorithm, List&amp;lt;Integer&amp;gt; values)  
    {              
        Stopwatch timer = new Stopwatch();  
        int i, testValue;  
        BigInteger facTimeResult = BigInteger.valueOf(0);  
        long fibTimeResult = 0;  
        i = testValue = 0;              
          
        // "Switch" Flow Control Statement  
        switch (algorithm)  
        {  
            case 1:  
                System.out.println("\nFactorial Imperative:");  
                // "For" Loop Statement  
                for (i = 0; i &amp;lt; values.size(); i++)  
                {                          
                    testValue = ((Integer)values.get(i)).intValue();  
                    // Taking Time  
                    timer.start();  
                    facTimeResult = factorialI(testValue);  
                    timer.stop();                          
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                }                      
                break;  
            case 2:  
                System.out.println("\nFactorial Recursive:");  
                // "While" Loop Statement  
                while (i &amp;lt; values.size())  
                {                          
                    testValue = ((Integer)values.get(i)).intValue();  
                    // Taking Time  
                    timer.start();  
                    facTimeResult = factorialR(testValue);  
                    timer.stop();  
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                    i++;  
                }  
                break;  
            case 3:  
                System.out.println("\nFibonacci Imperative:");  
                // "Do-While" Loop Statement  
                do {  
                    testValue = ((Integer)values.get(i)).intValue();  
                    // Taking Time  
                    timer.start();  
                    fibTimeResult = fibonacciI(testValue);  
                    timer.stop();  
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                    i++;  
                } while (i &amp;lt; values.size());  
                break;  
            case 4:  
                System.out.println("\nFibonacci Recursive:");  
                // "For Each" Loop Statement  
                for (Integer item : values)  
                {  
                    testValue = item;  
                    // Taking Time  
                    timer.start();  
                    fibTimeResult = fibonacciR(testValue);  
                    timer.stop();  
                    // Getting Time  
                    System.out.println(" (" + testValue + ") = " 
                        + timer.getElapsed());  
                }  
                break;  
            default:  
                System.out.println("DONG!");  
                break;  
        }                  
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborial;
import java.math.BigInteger;
// Instance Class  
public class InstanceFiborial  
{  
    // Instance Field  
    private String className;  
    // Instance Constructor  
    public InstanceFiborial()  
    {  
        this.className = "Instance Constructor";  
        System.out.println(this.className);
    }  
    // Instance Method - Factorial Recursive  
    public BigInteger factorialR(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.factorialR(n);  
    }  
    // Instance Method - Factorial Imperative  
    public BigInteger factorialI(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.factorialI(n);  
    }  
    // Instance Method - Fibonacci Recursive  
    public long fibonacciR(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.fibonacciR(n);  
    }  
    // Instance Method - Factorial Imperative  
    public long fibonacciI(int n)  
    {  
        // Calling Static Method  
        return StaticFiborial.fibonacciI(n);  
    }  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborial;
import java.util.Scanner; 
import java.util.ArrayList;
import java.util.List;

public class StaticFiborialProgram 
{
    public static void main(String[] args)
    {
        System.out.println("\nStatic Class");  
        // Calling Static Class and Methods  
        // No instantiation needed. Calling method directly from the class  
        System.out.println("FacImp(5) = " + StaticFiborial.factorialI(5));  
        System.out.println("FacRec(5) = " + StaticFiborial.factorialR(5));  
        System.out.println("FibImp(11)= " + StaticFiborial.fibonacciI(11));  
        System.out.println("FibRec(11)= " + StaticFiborial.fibonacciR(11));  

        System.out.println("\nInstance Class");  
        // Calling Instance Class and Methods   
        // Need to instantiate before using. Calling method from instantiated object  
        InstanceFiborial ff = new InstanceFiborial();  
        System.out.println("FacImp(5) = " + ff.factorialI(5));  
        System.out.println("FacRec(5) = " + ff.factorialR(5));  
        System.out.println("FibImp(11)= " + ff.fibonacciI(11));  
        System.out.println("FibRec(11)= " + ff.fibonacciR(11));  

        // Create a (generic) list of integer values to test  
        // From 5 to 50 by 5  
        List&amp;lt;Integer&amp;gt; values = new ArrayList&amp;lt;Integer&amp;gt;();  
        for(int i = 5; i &amp;lt;= 50; i += 5)  
            values.add(i);  

        // Benchmarking Fibonacci                       
        // 1 = Factorial Imperative              
        StaticFiborial.benchmarkAlgorithm(1, values);  
        // 2 = Factorial Recursive  
        StaticFiborial.benchmarkAlgorithm(2, values);   

        // Benchmarking Factorial              
        // 3 = Fibonacci Imperative  
        StaticFiborial.benchmarkAlgorithm(3, values);  
        // 4 = Fibonacci Recursive  
        StaticFiborial.benchmarkAlgorithm(4, values);   

        // Stop and exit  
        System.out.println("Press any key to exit...");  
        Scanner in = new Scanner(System.in);  
        String line = in.nextLine();  
        in.close();  
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-1ddC06izr7s/Tp80eQYjkQI/AAAAAAAAGHc/JxGncqLHTnU/s1600/fiborial_java.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://2.bp.blogspot.com/-1ddC06izr7s/Tp80eQYjkQI/AAAAAAAAGHc/JxGncqLHTnU/s640/fiborial_java.PNG" width="321" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialseries;
import java.math.BigInteger;
import java.lang.StringBuffer;

class Fiborial
{
    // Using a StringBuffer as a list of string elements
    public static String getFactorialSeries(int n)
    {
        // Create the String that will hold the list
        StringBuffer series = new StringBuffer();
        // We begin by concatenating the number you want to calculate
        // in the following format: "!# ="
        series.append("!");
        series.append(n);
        series.append(" = ");
        // We iterate backwards through the elements of the series
        for (int i = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--)
        {
            // and append it to the list
            series.append(i);
            if (i &amp;gt; 1)
                series.append(" * ");
            else 
                series.append(" = "); 
        }
        // Get the result from the Factorial Method
        // and append it to the end of the list
        series.append(factorial(n));
        // return the list as a string
        return series.toString();
    }

    // Using a StringBuffer as a list of string elements
    public static String getFibonnaciSeries(int n)
    {
        // Create the String that will hold the list
        StringBuffer series = new StringBuffer();
        // We begin by concatenating the first 3 values which
        // are always constant
        series.append("0, 1, 1");
        // Then we calculate the Fibonacci of each element
        // and add append it to the list
        for (int i = 2; i &amp;lt;= n; i++)
        {
            if (i &amp;lt; n)
                series.append(", ");
            else
                series.append(" = ");
            
            series.append(fibonacci(i));
        }
        // return the list as a string
        return series.toString();
    }

    public static BigInteger factorial(int n)
    {
        if (n == 1)  
            return BigInteger.ONE;
        else  
            return BigInteger.valueOf(n).multiply(factorial(n - 1));
    }        

    public static long fibonacci(int n)
    {
        if (n &amp;lt; 2)  
            return 1;  
        else  
            return fibonacci(n - 1) + fibonacci(n - 2);  
    }   
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialseries;

class FiborialExtrasProgram
{    
    public static void main(String[] args) 
    {            
        // Printing Factorial Series
        System.out.println("");
        System.out.println(Fiborial.getFactorialSeries(5));
        System.out.println(Fiborial.getFactorialSeries(7));
        System.out.println(Fiborial.getFactorialSeries(9));
        System.out.println(Fiborial.getFactorialSeries(11));
        System.out.println(Fiborial.getFactorialSeries(40));
        // Printing Fibonacci Series
        System.out.println("");
        System.out.println(Fiborial.getFibonnaciSeries(5));
        System.out.println(Fiborial.getFibonnaciSeries(7));
        System.out.println(Fiborial.getFibonnaciSeries(9));
        System.out.println(Fiborial.getFibonnaciSeries(11));
        System.out.println(Fiborial.getFibonnaciSeries(40));
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/--JLNr9ezjsE/TdBVbVgbX5I/AAAAAAAAF6M/3eWTdjzsp3s/s1600/fiborial_java_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="312" src="http://3.bp.blogspot.com/--JLNr9ezjsE/TdBVbVgbX5I/AAAAAAAAF6M/3eWTdjzsp3s/s640/fiborial_java_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, getters/setters, constructors/initializers, methods, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialextrasjava2;

// Instance Class  
class Fiborial  
{  
    // Instance Field  
    private int instanceCount;  
    // Static Field  
    private static int staticCount;          
    // Instance Read-Only Getter  
    // Within instance members, you can always use    
    // the "this" reference pointer to access your (instance) members.  
    public int getInstanceCount()
    {  
        return this.instanceCount;   
    }  
    // Static Read-Only Getter      
    // As with Static Methods, you cannot reference your class members  
    // with the "this" reference pointer since static members are not  
    // instantiated.          
    public static int getStaticCount()
    {  
        return staticCount;  
    }  
    // Instance Constructor  
    public Fiborial()  
    {  
        this.instanceCount = 0;  
        System.out.println("\nInstance Constructor " + this.instanceCount); 
    }  
    // Static Constructor  
    static
    {  
        staticCount = 0;  
        System.out.println("\nStatic Constructor " + staticCount);  
    }  

    // Instance Method  
    public void factorial(int n)  
    {  
        this.instanceCount += 1;  
        System.out.println("\nFactorial(" + n + ")");  
    }  

    // Static Method  
    public static void fibonacci(int n)  
    {  
        staticCount += 1;  
        System.out.println("\nFibonacci(" + n + ")");  
    }                  
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialextrasjava2;

class FiborialExtras2Program
{    
    public static void main(String[] args) 
    {            
        // Calling Static Constructor and Methods  
        // No need to instantiate  
        Fiborial.fibonacci(5);              

        // Calling Instance Constructor and Methods  
        // Instance required  
        Fiborial fib = new Fiborial();  
        fib.factorial(5);              

        Fiborial.fibonacci(15);              
        fib.factorial(5);  

        // Calling Instance Constructor and Methods  
        // for a second object  
        Fiborial fib2 = new Fiborial();  
        fib2.factorial(5);  
          
        System.out.println("");
        // Calling Static Property  
        System.out.println("Static Count = " + Fiborial.getStaticCount());  
        // Calling Instance Property of object 1 and 2  
        System.out.println("Instance 1 Count = " + fib.getInstanceCount());  
        System.out.println("Instance 2 Count = " + fib2.getInstanceCount());          
    }
}
&lt;/pre&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-ikkKX1Qg4ak/TdBY4mWs84I/AAAAAAAAF6U/bee3t-6xTWs/s1600/fiborial_java_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="430" src="http://3.bp.blogspot.com/-ikkKX1Qg4ak/TdBY4mWs84I/AAAAAAAAF6U/bee3t-6xTWs/s640/fiborial_java_extras2.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt; &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using java.lang.Long, java.lang.Double, java.math.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="java" name="code"&gt;package fiborialextrasjava3;
import java.math.BigInteger;

class FiborialExtrasProgram
{    
    public static void main(String[] args) 
    {            
        Stopwatch timer = new Stopwatch();  
        long facIntResult = 0;  
        double facDblResult = 0;  
        BigInteger facBigResult = BigInteger.valueOf(0);  

        System.out.println("\nFactorial using Int64");
        // Benchmark Factorial using Int64  
        for (int i = 5; i &amp;lt;= 50; i += 5)  
        {  
            timer.start();  
            facIntResult = factorialInt64(i);  
            timer.stop();  
            System.out.println(" (" + i + ") = " 
                + timer.getElapsed() + " : " + facIntResult);
        }  
        System.out.println("\nFactorial using Double");  
        // Benchmark Factorial using Double  
        for (int i = 5; i &amp;lt;= 50; i += 5)  
        {  
            timer.start();  
            facDblResult = factorialDouble(i);  
            timer.stop();              
            System.out.println(" (" + i + ") = " 
                + timer.getElapsed() + " : " + facDblResult);
        }  
        System.out.println("\nFactorial using BigInteger");  
        // Benchmark Factorial using BigInteger  
        for (int i = 5; i &amp;lt;= 50; i += 5)  
        {  
            timer.start();  
            facBigResult = factorialBigInteger(i);  
            timer.stop();  
            System.out.println(" (" + i + ") = " 
                + timer.getElapsed() + " : " + facBigResult);
        }          
    }
    
    // Long Factorial  
    public static long factorialInt64(int n)  
    {  
        if (n == 1)  
            return 1;
        else  
            return n * factorialInt64(n - 1);
    }
    
    // Double Factorial
    public static double factorialDouble(int n)  
    {  
        if (n == 1)  
            return 1;
        else  
            return n * factorialDouble(n - 1);
    }
    
    // BigInteger Factorial 
    public static BigInteger factorialBigInteger(int n)  
    {  
        if (n == 1)  
            return BigInteger.ONE;
        else  
            return BigInteger.valueOf(n).multiply(factorialBigInteger(n - 1));
    }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-aA5uKpZYg5E/TdBWQXCVWeI/AAAAAAAAF6Q/VbKJSlx2Ja8/s1600/fiborial_java_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="546" src="http://4.bp.blogspot.com/-aA5uKpZYg5E/TdBWQXCVWeI/AAAAAAAAF6Q/VbKJSlx2Ja8/s640/fiborial_java_extras_big_int.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/Y8Xa38-IP0s" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/1304605657994355004/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/05/factorial-and-fibonacci-in-java.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1304605657994355004?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/1304605657994355004?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/Y8Xa38-IP0s/factorial-and-fibonacci-in-java.html" title="Factorial and Fibonacci in Java" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://2.bp.blogspot.com/-1ddC06izr7s/Tp80eQYjkQI/AAAAAAAAGHc/JxGncqLHTnU/s72-c/fiborial_java.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/05/factorial-and-fibonacci-in-java.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkEFSX06fip7ImA9WhVXGUg.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7296712681658845745</id><published>2011-04-03T13:27:00.000-07:00</published><updated>2012-04-20T14:50:18.316-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-04-20T14:50:18.316-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="PHP" /><category scheme="http://www.blogger.com/atom/ns#" term="Phalanger" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Phalanger</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update 1:&lt;/b&gt; using BigInteger Multiply method instead of unsupported custom * Operator.&lt;br /&gt;
&lt;b&gt;Update 2:&lt;/b&gt; Porting code examples to Phalanger 3 - syntax changes on namespace use.&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Phalanger that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php      
# Factorial and Fibonacci in Phalanger        
namespace FiborialPhp;

use System;
use System\Collections\Generic as G;
use System\Diagnostics as D;
use System\Numerics as N;

# Instance Class           
# static is not a class modifier in PHP    
[\Export]
class StaticFiborial    
{      
    # Static Field     
    private static $className;    
    # no available static __constructor support    
    # Static Initializer Method instead, but need to be explicitly invoked    
    public static function StaticFiborialConstructor()    
    {                
        $className = &amp;quot;Static Constructor&amp;quot;;    
        echo $className . &amp;quot;\n&amp;quot;;    
    }            
    # Static Method - Factorial Recursive    
    public static function FactorialR(int $n)    
    {      
        if($n == 1)     
            return N\BigInteger::$One;  
        else                    
            return N\BigInteger::Multiply(new N\BigInteger($n), self::FactorialR($n-1));  
    }            
    # Static Method - Factorial Imperative        
    public static function FactorialI(int $n)     
    {                    
        $res = N\BigInteger::$One;
        for ($i = $n; $i &amp;gt;= 1; $i--)  
            $res = N\BigInteger::Multiply($res, new N\BigInteger($i));                  
        return $res;    
    }       
    # Static Method - Fibonacci Recursive        
    public static function FibonacciR(int $n)     
    {        
        if ($n &amp;lt; 2)    
            return 1;        
        else        
            return self::FibonacciR($n - 1) + self::FibonacciR($n - 2);        
    }    
    # Static Method - Fibonacci Imperative        
    public static function FibonacciI(int $n)     
    {    
        $pre = 0; $cur = 0; $tmp = 0;    
        $pre = 1; $cur = 1;    
        for ($i = 2; $i &amp;lt;= $n; $i++)     
        {    
            $tmp = $cur + $pre;        
            $pre = $cur;        
            $cur = $tmp;        
        }        
        return $cur;    
    }    
    # Static Method - Benchmarking Algorithms        
    public static function BenchmarkAlgorithm(int $algorithm, G\List&amp;lt;:int:&amp;gt; $values)     
    {    
        $timer = new D\Stopwatch();    
        $i = 0;     
        $testValue = 0;                
        $facTimeResult = N\BigInteger::$Zero;  
        $fibTimeResult = 0;        
                
        # &amp;quot;Switch&amp;quot; Flow Constrol Statement        
        switch ($algorithm)        
        {        
            case 1:        
                echo &amp;quot;\nFactorial Imperative:\n&amp;quot;;    
                # &amp;quot;For&amp;quot; Loop Statement        
                for ($i = 0; $i &amp;lt; $values-&amp;gt;Count; $i++)      
                {                                                    
                    $testValue = $values-&amp;gt;get_Item($i);    
                    # Taking Time        
                    $timer-&amp;gt;Start();        
                    $facTimeResult = self::FactorialI($testValue);        
                    $timer-&amp;gt;Stop();                                
                    # Getting Time                              
                    echo &amp;quot; ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n&amp;quot;;    
                }                            
                break;        
            case 2:        
                echo &amp;quot;\nFactorial Recursive:\n&amp;quot;;    
                # &amp;quot;While&amp;quot; Loop Statement        
                while ($i &amp;lt; $values-&amp;gt;Count)        
                {                                
                    $testValue = $values-&amp;gt;get_Item($i);                            
                    # Taking Time        
                    $timer-&amp;gt;Start();        
                    $facTimeResult = self::FactorialR($testValue);        
                    $timer-&amp;gt;Stop();        
                    # Getting Time        
                    echo &amp;quot; ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n&amp;quot;;    
                    $i++;    
                }    
                break;        
            case 3:        
                echo &amp;quot;\nFibonacci Imperative:\n&amp;quot;;    
                # &amp;quot;Do-While&amp;quot; Loop Statement        
                do     
                {        
                    $testValue = $values-&amp;gt;get_Item($i);    
                    # Taking Time        
                    $timer-&amp;gt;Start();        
                    $fibTimeResult = self::FibonacciI($testValue);        
                    $timer-&amp;gt;Stop();        
                    # Getting Time        
                    echo &amp;quot; ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n&amp;quot;;    
                    $i++;        
                } while ($i &amp;lt; $values-&amp;gt;Count);                            
                break;        
            case 4:        
                echo &amp;quot;\nFibonacci Recursive:\n&amp;quot;;    
                # &amp;quot;ForEach&amp;quot; Loop Statement        
                foreach ($values as $item)        
                {        
                    $testValue = (int)$item;        
                    # Taking Time        
                    $timer-&amp;gt;Start();        
                    $fibTimeResult = self::FibonacciR($testValue);    
                    $timer-&amp;gt;Stop();        
                    # Getting Time        
                    echo &amp;quot; ($testValue) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()}\n&amp;quot;;    
                }        
                break;        
            default:        
                echo &amp;quot;DONG!\n&amp;quot;;    
                break;    
        }                        
    }        
}    
    
[\Export]     
# Instance Class    
class InstanceFiborial    
{      
    # Instance  Field     
    private $className;    
    # Instance Constructor                            
    function __construct()      
    {      
        $this-&amp;gt;className = &amp;quot;Instance Constructor&amp;quot;;    
        echo $this-&amp;gt;className . &amp;quot;\n&amp;quot;;    
    }    
    # Instance Method - Factorial Recursive    
    public function FactorialR(int $n)    
    {      
        # Calling Static Method    
        return StaticFiborial::FactorialR($n);    
    }    
    # Instance Method - Factorial Imperative        
    public function FactorialI(int $n)     
    {        
        # Calling Static Method    
        return StaticFiborial::FactorialI($n);    
    }       
    # Instance Method - Fibonacci Recursive        
    public function FibonacciR(int $n)     
    {        
        # Calling Static Method    
        return StaticFiborial::FibonacciR($n);    
    }    
    # Instance Method - Fibonacci Imperative        
    public function FibonacciI(int $n)     
    {    
        # Calling Static Method    
        return StaticFiborial::FibonacciI($n);    
    }    
}    
    
# Console Program      
class Program      
{      
    public static function Main()      
    {      
        # Static Initializer/Constructor for StaticFiborial Class     
        # explicitly called somewhere in your code ^_^    
        StaticFiborial::StaticFiborialConstructor();    
                
        echo &amp;quot;\nStatic Class\n&amp;quot;;    
        # Calling Static Class and Methods      
        # No instantiation needed. Calling method directly from the class      
        echo &amp;quot;FacImp(5) = &amp;quot; . StaticFiborial::FactorialI(5)-&amp;gt;ToString() . &amp;quot;\n&amp;quot;;    
        echo &amp;quot;FacRec(5) = &amp;quot; . StaticFiborial::FactorialR(5)-&amp;gt;ToString() . &amp;quot;\n&amp;quot;;    
        echo &amp;quot;FibImp(11)= &amp;quot; . StaticFiborial::FibonacciI(11)-&amp;gt;ToString() . &amp;quot;\n&amp;quot;;    
        echo &amp;quot;FibRec(11)= &amp;quot; . StaticFiborial::FibonacciR(11)-&amp;gt;ToString() . &amp;quot;\n&amp;quot;;    
      
        echo &amp;quot;\nInstance Class\n&amp;quot;;      
        # Calling Instance Class and Methods      
        # Need to instantiate before using. Calling method from instantiated object      
        $ff = new InstanceFiborial();    
        echo &amp;quot;FacImp(5) = {$ff-&amp;gt;FactorialI(5)-&amp;gt;ToString()}\n&amp;quot;;    
        echo &amp;quot;FacRec(5) = {$ff-&amp;gt;FactorialR(5)-&amp;gt;ToString()}\n&amp;quot;;    
        echo &amp;quot;FibImp(11)= {$ff-&amp;gt;FibonacciI(11)-&amp;gt;ToString()}\n&amp;quot;;    
        echo &amp;quot;FibRec(11)= {$ff-&amp;gt;FibonacciR(11)-&amp;gt;ToString()}\n&amp;quot;;    
                              
        # From 5 to 50 by 5    
        $values = new G\List&amp;lt;:int:&amp;gt;;    
        for($i = 5; $i &amp;lt;= 50; $i += 5)    
            $values-&amp;gt;Add($i);    
    
        # Benchmarking Fibonacci      
        # 1 = Factorial Imperative      
        StaticFiborial::BenchmarkAlgorithm(1, $values);    
        # 2 = Factorial Recursive      
        StaticFiborial::BenchmarkAlgorithm(2, $values);    
        # Benchmarking Factorial      
        # 3 = Fibonacci Imperative      
        StaticFiborial::BenchmarkAlgorithm(3, $values);    
        # 4 = Fibonacci Recursive      
        StaticFiborial::BenchmarkAlgorithm(4, $values);    
    
        # Stop and exit      
        echo &amp;quot;Press any key to exit...&amp;quot;;      
        fgets(STDIN);
        return 0;      
    }      
}    
 
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-X61JPUcuhPI/TZjVj7xUISI/AAAAAAAAF5Q/CHB3_U7MHew/s1600/fiborial_php.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-X61JPUcuhPI/TZjVj7xUISI/AAAAAAAAF5Q/CHB3_U7MHew/s640/fiborial_php.PNG" width="294" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php        
namespace FiborialSeries;
use System;
use System\Text as T;    
use System\Numerics as N;
      
[\Export]
class Fiborial    
{      
    # Using a StringBuilder as a list of string elements                
    static function GetFactorialSeries(int $n)     
    {            
        # Create the String that will hold the list        
        $series = new T\StringBuilder();        
        # We begin by concatenating the number you want to calculate        
        # in the following format: &amp;quot;!# =&amp;quot;        
        $series-&amp;gt;Append(&amp;quot;!&amp;quot;);        
        $series-&amp;gt;Append($n);        
        $series-&amp;gt;Append(&amp;quot; = &amp;quot;);        
        # We iterate backwards through the elements of the series        
        for ($i = $n; $i &amp;lt;= $n &amp;amp;&amp;amp; $i &amp;gt; 0; $i--)     
        {        
            # and append it to the list        
            $series-&amp;gt;Append($i);    
            if ($i &amp;gt; 1)        
                $series-&amp;gt;Append(&amp;quot; * &amp;quot;);        
            else         
                $series-&amp;gt;Append(&amp;quot; = &amp;quot;);         
        }        
        # Get the result from the Factorial Method        
        # and append it to the end of the list                                        
        # $series-&amp;gt;Append(self::Factorial($n)-&amp;gt;ToString());    
        # BUT! that throws an exception with big numbers (&amp;gt; fact(30))    
        # Overflow ex &amp;quot;Value was either too large or too small for a Decimal.&amp;quot;  
        # because I think it is a bug i used an ugly workaround which is  
        # using the &amp;quot;.&amp;quot; in the return.  
        return $series-&amp;gt;ToString() . self::Factorial($n)-&amp;gt;ToString();  
    }        
        
    # Using a StringBuilder as a list of string elements        
    static function GetFibonnaciSeries(int $n)        
    {        
        # Create the String that will hold the list        
        $series = new T\StringBuilder();    
        # We begin by concatenating the first 3 values which        
        # are always constant        
        $series-&amp;gt;Append(&amp;quot;0, 1, 1&amp;quot;);        
        # Then we calculate the Fibonacci of each element        
        # and add append it to the list        
        for ($i = 2; $i &amp;lt;= $n; $i++)        
        {        
            if ($i &amp;lt; $n)        
                $series-&amp;gt;Append(&amp;quot;, &amp;quot;);        
            else        
                $series-&amp;gt;Append(&amp;quot; = &amp;quot;);        
            
            $series-&amp;gt;Append(self::Fibonacci($i));    
        }        
        # return the list as a string        
        return $series-&amp;gt;ToString();        
    }        
    
    static function Factorial(int $n)    
    {      
        if($n == 1)     
            return new N\BigInteger(1);  
        else                    
            return N\BigInteger::Multiply(new N\BigInteger($n), self::Factorial($n - 1));  
    }    
            
    static function Fibonacci(int $n)     
    {        
        if ($n &amp;lt; 2)    
            return 1;    
        else        
            return self::Fibonacci($n - 1) + self::Fibonacci($n - 2);        
    }        
}    
    
class Program      
{      
    public static function Main()      
    {      
        # Printing Factorial Series        
        echo &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFactorialSeries(5) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFactorialSeries(7) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFactorialSeries(9) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFactorialSeries(11) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFactorialSeries(40) . &amp;quot;\n&amp;quot;;      
        # Printing Fibonacci Series  
        echo &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFibonnaciSeries(5) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFibonnaciSeries(7) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFibonnaciSeries(9) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFibonnaciSeries(11) . &amp;quot;\n&amp;quot;;    
        echo Fiborial::GetFibonnaciSeries(40) . &amp;quot;\n&amp;quot;;    
                 
        fgets(STDIN);
        return 0;      
    }      
}    
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-AEEfUDpyqgI/TZjVs6d8leI/AAAAAAAAF5U/Uu1kQYSvJlc/s1600/fiborial_php_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://4.bp.blogspot.com/-AEEfUDpyqgI/TZjVs6d8leI/AAAAAAAAF5U/Uu1kQYSvJlc/s640/fiborial_php_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instance classes can contain both, instance and static members such as: fields, properties, constructors, methods, etc. &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php    
namespace FiborialExtras2;
use System;

# Instance Class  
[\Export]       
class Fiborial  
{    
    # Instance Field  
    private $instanceCount;  
    # Static Field  
    private static $staticCount;          
    # Instance Read-Only Property/Getter  
    # Within instance members, you can always use    
    # the &amp;quot;this&amp;quot; reference pointer to access your (instance) members.  
    public function getInstanceCount()  
    {  
        return $this-&amp;gt;instanceCount;  
    }  
    # Static Read-Only Property/Getter  
    # As with Static Methods, you cannot reference your class members  
    # with the &amp;quot;this&amp;quot; reference pointer since static members are not  
    # instantiated.          
    public static function getStaticCount()  
    {  
        return $staticCount;  
    }  
    # Instance Constructor            
    public function __construct()    
    {    
        $this-&amp;gt;instanceCount = 0;  
        echo &amp;quot;\nInstance Constructor {$this-&amp;gt;instanceCount}\n&amp;quot;;  
    }    
    # Static Constructor  
    public static function FiborialStaticConstructor()  
    {  
        $staticCount = 0;  
        echo &amp;quot;\nStatic Constructor {$staticCount}\n&amp;quot;;  
    }      
    # Instance Method  
    public function Factorial(int $n)  
    {    
        $this-&amp;gt;instanceCount += 1;  
        echo &amp;quot;\nFactorial({$n})\n&amp;quot;;  
    }  
    # Static Method  
    public static function Fibonacci(int $n)   
    {      
        $staticCount += 1;  
        echo &amp;quot;\nFibonacci({$n})\n&amp;quot;;  
    }      
}  
  
class Program    
{    
    public static function Main()    
    {    
        # Calling Static Constructor/Initializer and Methods  
        # No need to instantiate  
        Fiborial::FiborialStaticConstructor();  
        Fiborial::Fibonacci(5);              
  
        // Calling Instance Constructor and Methods  
        // Instance required  
        $fib = new Fiborial();  
        $fib-&amp;gt;Factorial(5);  
  
        Fiborial::Fibonacci(15);              
        $fib-&amp;gt;Factorial(5);  
  
        // Calling Instance Constructor and Methods  
        // for a second object  
        $fib2 = new Fiborial();  
        $fib2-&amp;gt;Factorial(5);  
              
        echo &amp;quot;\n&amp;quot;;  
        // Calling Static Property  
        echo &amp;quot;Static Count = &amp;quot; . Fiborial::getStaticCount() . &amp;quot;\n&amp;quot;;  
        // Calling Instance Property of object 1 and 2  
        echo &amp;quot;Instance 1 Count = {$fib-&amp;gt;getInstanceCount()}\n&amp;quot;;  
        echo &amp;quot;Instance 2 Count = {$fib2-&amp;gt;getInstanceCount()}\n&amp;quot;;  
  
        fgets(STDIN);    
        return 0;    
    }    
}  
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-FHWCh_GtAGM/TZjV1x7COKI/AAAAAAAAF5Y/_sN4bvGIa3I/s1600/fiborial_php_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="400" src="http://3.bp.blogspot.com/-FHWCh_GtAGM/TZjV1x7COKI/AAAAAAAAF5Y/_sN4bvGIa3I/s400/fiborial_php_extras2.PNG" width="377" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="php" name="code"&gt;&amp;lt;?php      
use System\Numerics as N;
use System\Diagnostics as D;      
    
function FactorialInt64(int $n)     
{        
    if ($n == 1)        
        return 1;        
    else        
        return $n * FactorialInt64($n - 1);        
}        
    
function FactorialDouble(int $n)     
{        
    if ($n == 1)        
        return (double)1;        
    else        
        return (double)($n * FactorialDouble($n - 1));    
}    
    
function FactorialBigInteger(int $n)     
{        
    if($n == 1)     
        return N\BigInteger::$One;  
    else                    
        return N\BigInteger::Multiply(new N\BigInteger($n), FactorialBigInteger($n - 1));  
}    
    
class Program    
{    
    public static function Main()      
    {      
            $timer = new D\Stopwatch();    
            $facIntResult = 0;        
            $facDblResult = (double)0;        
            $facBigResult = N\BigInteger::$Zero;     
    
            echo &amp;quot;\nFactorial using Int64\n&amp;quot;;        
            // Benchmark Factorial using Int64        
            for ($i = 5; $i &amp;lt;= 50; $i += 5)        
            {        
                $timer-&amp;gt;Start();        
                $facIntResult = FactorialInt64($i);        
                $timer-&amp;gt;Stop();        
                echo &amp;quot; ({$i}) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()} : {$facIntResult}\n&amp;quot;;    
            }                    
            echo &amp;quot;\nFactorial using Double\n&amp;quot;;        
            // Benchmark Factorial using Double    
            for ($i = 5; $i &amp;lt;= 50; $i += 5)        
            {        
                $timer-&amp;gt;Start();        
                $facDblResult = FactorialDouble($i);        
                $timer-&amp;gt;Stop();        
                echo &amp;quot; ({$i}) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()} : {$facDblResult}\n&amp;quot;;    
            }        
            echo &amp;quot;\nFactorial using N\BigInteger\n&amp;quot;;    
            // Benchmark Factorial using N\BigInteger                    
            for ($i = 5; $i &amp;lt;= 50; $i += 5)    
            {        
                    
                $timer-&amp;gt;Start();        
                $facBigResult = FactorialBigInteger($i);        
                $timer-&amp;gt;Stop();        
                echo &amp;quot; ({$i}) = {$timer-&amp;gt;Elapsed-&amp;gt;ToString()} : {$facBigResult-&amp;gt;ToString()}\n&amp;quot;;    
            }      
                          
            fgets(STDIN);      
            return 0;      
    }      
}    
?&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-VI1M_xqbHQs/TeeuEFEl1XI/AAAAAAAAF68/rHQl2Dl9Qms/s1600/fiborial_php_extras_big_int2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="482" src="http://2.bp.blogspot.com/-VI1M_xqbHQs/TeeuEFEl1XI/AAAAAAAAF68/rHQl2Dl9Qms/s640/fiborial_php_extras_big_int2.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s1600/fiborial_n_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/fwEwO-BgbR8" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7296712681658845745/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/04/factorial-and-fibonacci-in-phalanger.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7296712681658845745?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7296712681658845745?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/fwEwO-BgbR8/factorial-and-fibonacci-in-phalanger.html" title="Factorial and Fibonacci in Phalanger" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-X61JPUcuhPI/TZjVj7xUISI/AAAAAAAAF5Q/CHB3_U7MHew/s72-c/fiborial_php.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/04/factorial-and-fibonacci-in-phalanger.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MERnw-fyp7ImA9WhVSGUo.&quot;"><id>tag:blogger.com,1999:blog-694679611587040520.post-7518171880813965006</id><published>2011-03-27T10:14:00.000-07:00</published><updated>2012-03-17T02:10:07.257-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2012-03-17T02:10:07.257-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Nemerle" /><category scheme="http://www.blogger.com/atom/ns#" term="CLR" /><title>Factorial and Fibonacci in Nemerle</title><content type="html">&lt;a class="twitter-share-button" data-count="horizontal" data-via="carlosqt" href="http://twitter.com/share"&gt;Tweet&lt;/a&gt;&lt;script src="http://platform.twitter.com/widgets.js" type="text/javascript"&gt;
&lt;/script&gt;
&lt;script src="//platform.linkedin.com/in.js" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="IN/Share" data-counter="right"&gt;&lt;/script&gt;
&lt;br /&gt;
&lt;br /&gt;
Here below a little program in Nemerle that implements 2 classes (in fact, they are 3). There is the main class, called Fiborial (Fibo(nnacci)+(Facto)rial) that implements the &lt;i&gt;Fibonacci&lt;/i&gt; and the &lt;i&gt;Factorial&lt;/i&gt; algorithms in two ways, one &lt;i&gt;Recursive&lt;/i&gt; (using recursion) and the other &lt;i&gt;Imperative&lt;/i&gt; (using loops and states). The second class is just an instance class that does the same thing, but its there just to show the difference between static and instance classes, and finally the third one (which will not appear in other languages) is the Program class which has the static execution method "Main".&lt;br /&gt;
&lt;br /&gt;
You can also find 3 more little examples at the bottom. One prints out the Factorial's Series and Fibonacci's Series, the second one just shows a class that mixes both: static and instance members, and finally the third one that uses different return types (including System.Numerics.BigInteger) for the Factorial method to compare the timing and result.&lt;br /&gt;
&lt;br /&gt;
As with the previous posts, you can copy and paste the code below in your favorite IDE/Editor and start playing and learning with it. This little "working" program will teach you some more basics of the Programming Language.&lt;br /&gt;
&lt;br /&gt;
There are some "comments" on the code added just to tell you what are or how are some features called. In case you want to review the theory, you can read my previous post, where I give a definition of each of the concepts mentioned on the code. You can find it here: &lt;a href="http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html"&gt;http://carlosqt.blogspot.com/2011/01/new-series-factorial-and-fibonacci.html&lt;/a&gt;&amp;nbsp;&lt;a href="http://carlosqt.blogspot.com/2010/08/new-series-languages-basics-by-example.html"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The Fiborial Program&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;// Factorial and Fibonacci in Nemerle
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Nemerle.IO;

namespace FiborialN
{
    // Module = Static Class
    // all members become static by default
    // no need to explicitly use static on members (i did anyway)
    module StaticFiborial
    {
        // Static Field
        static mutable className : string; 
        // Static Constructor
        static this()
        {
            className = "Static Constructor";
            printf("%s", className);
        }
        // Static Method - Factorial Recursive
        public static FactorialR(n : int) : BigInteger
        {            
            if (n == 1)
                 BigInteger(1);
            else 
                 BigInteger(n) * FactorialR(n - 1);
        }
        // Static Method - Factorial Imperative
        public static FactorialI(n : int) : BigInteger
        {
            mutable res : BigInteger = BigInteger(1);
            for (mutable i : int = n; i &amp;gt;= 1; i--)
                res *= i;
            res;
        }
        // Static Method - Fibonacci Recursive
        public static FibonacciR(n : int) : long
        {
            def oneLong : long = 1;
            if (n &amp;lt; 2)
                oneLong;
            else
                FibonacciR(n - 1) + FibonacciR(n - 2);
        }
        // Static Method - Fibonacci Imperative
        public static FibonacciI(n : int) : long
        {            
            mutable pre : long = 1;
            mutable cur : long = 1;
            mutable tmp : long = 0;
            
            for (mutable i : int = 2; i &amp;lt;= n; i++)
            {
                tmp = cur + pre;
                pre = cur;
                cur = tmp;
            }
            cur;
        }
        // Static Method - Benchmarking Algorithms
        public static BenchmarkAlgorithm(algorithm : int, values : list[int]) : void
        {            
            def timer : Stopwatch = Stopwatch();
            mutable i : int = 0;
            mutable testValue : int = 0;
            mutable facTimeResult : BigInteger = BigInteger(0);
            mutable fibTimeResult : long = 0;
           
            // "Switch" Flow Constrol Statement
            match (algorithm)
            {
                | 1 =&amp;gt;
                    printf("\nFactorial Imperative:\n");
                    // "For" Loop Statement
                    for (i = 0; i &amp;lt; values.Length; i++)
                    {
                        testValue = values.Nth(i);
                        // Taking Time
                        timer.Start();
                        facTimeResult = FactorialI(testValue);
                        timer.Stop();                        
                        // Getting Time
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                    }
                | 2 =&amp;gt;
                    printf("\nFactorial Recursive:\n");
                    // 'While' Loop Statement  
                    while (i &amp;lt; values.Length) 
                    {
                        testValue = values.Nth(i);  
                        // Taking Time  
                        timer.Start();  
                        facTimeResult = FactorialR(testValue);  
                        timer.Stop();  
                        // Getting Time  
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                        i++;
                    }
                | 3 =&amp;gt;
                    printf("\nFibonacci Imperative:\n");
                    // 'Do-While' Loop Statement  
                    do {  
                        testValue = values.Nth(i);  
                        // Taking Time 
                        timer.Start();  
                        fibTimeResult = FibonacciI(testValue);  
                        timer.Stop();  
                        // Getting Time  
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                        i++;  
                    } while (i &amp;lt; values.Length);  
                | 4 =&amp;gt;
                    printf("\nFibonacci Recursive:\n");
                    // 'For Each' Loop Statement  
                    foreach (item : int in values) {  
                        testValue = item;
                        // Taking Time  
                        timer.Start();  
                        fibTimeResult = FibonacciR(testValue);  
                        timer.Stop();  
                        // Getting Time  
                        printf(" (%d) = %s\n", testValue, timer.Elapsed.ToString());
                    }  
                | _ =&amp;gt; printf("DONG!");
            }                
        }
    }
    
    // Instance Class  
    public class InstanceFiborial 
    {  
        // Instance Field  
        mutable className : String;  
        // Instance Constructor  
        public this() 
        {  
            this.className = "Instance Constructor";  
            printf("%s", this.className);
        }  
        // Instance Method - Factorial Recursive  
        public FactorialR(n : int) : BigInteger 
        {  
            // Calling Static Method  
            StaticFiborial.FactorialR(n);  
        }  
        // Instance Method - Factorial Imperative  
        public FactorialI(n : int) : BigInteger 
        {  
            // Calling Static Method  
            StaticFiborial.FactorialI(n);  
        }  
        // Instance Method - Fibonacci Recursive  
        public FibonacciR(n : int) : long 
        {  
            // Calling Static Method  
            StaticFiborial.FibonacciR(n);  
        }  
        // Instance Method - Factorial Imperative  
        public FibonacciI(n : int) : long 
        {  
            // Calling Static Method  
            StaticFiborial.FibonacciI(n);  
        }  
    }  
    
    module Program
    {
        Main() : void
        {          
            printf("\nStatic Class\n");
            // Calling Static Class and Methods  
            // No instantiation needed. Calling method directly from the class 
            printf("FacImp(5) = %s\n", StaticFiborial.FactorialI(5).ToString());  
            printf("FacRec(5) = %s\n", StaticFiborial.FactorialR(5).ToString());  
            printf("FibImp(11)= %s\n", StaticFiborial.FibonacciI(11).ToString());  
            printf("FibRec(11)= %s\n", StaticFiborial.FibonacciR(11).ToString());  

            printf("\nInstance Class\n");  
            // Calling Instance Class and Methods   
            // Need to instantiate before using. Calling method from instantiated object  
            def ff : InstanceFiborial = InstanceFiborial();  
            printf("FacImp(5) = %s\n", ff.FactorialI(5).ToString());  
            printf("FacRec(5) = %s\n", ff.FactorialR(5).ToString());  
            printf("FibImp(11)= %s\n", ff.FibonacciI(11).ToString());  
            printf("FibRec(11)= %s\n", ff.FibonacciR(11).ToString()); 

            // Create a (nemerle) list of integer values to test
            // From 5 to 50 by 5
            mutable values : list[int] = [];
            foreach (i in $[5,10..50])
                values ::= i;
                    
            // Benchmarking Fibonacci                       
            // 1 = Factorial Imperative              
            StaticFiborial.BenchmarkAlgorithm(1, values.Reverse());
            // 2 = Factorial Recursive  
            StaticFiborial.BenchmarkAlgorithm(2, values.Reverse());

            // Benchmarking Factorial              
            // 3 = Fibonacci Imperative  
            StaticFiborial.BenchmarkAlgorithm(3, values.Reverse());
            // 4 = Fibonacci Recursive  
            StaticFiborial.BenchmarkAlgorithm(4, values.Reverse());        

            // Stop and Exit 
            _ = Console.ReadLine();
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is: &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-RsydOKZ3ajM/TY9vABXaJ2I/AAAAAAAAF5A/Sei1PrF70JE/s1600/fiborial_n.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="640" src="http://3.bp.blogspot.com/-RsydOKZ3ajM/TY9vABXaJ2I/AAAAAAAAF5A/Sei1PrF70JE/s640/fiborial_n.PNG" width="478" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TM8Wwm7ILyI/AAAAAAAAFyQ/AziXveRyTGo/s1600/output_delphi.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Humm, looks like Fibonnaci's algorithm implemented using recursion is definitively more complex than the others 3 right? I will grab these results for this and each of the upcoming posts to prepare a comparison of time execution between all the programming languages, then we will be able to talk about the algorithm's complexity as well.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Printing the Factorial and Fibonacci Series&lt;/b&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;  
using System.Text;  
using System.Numerics;
using Nemerle.IO;

namespace FiborialSeries
{
    static class Fiborial
    {
        // Using a StringBuilder as a list of string elements  
        public static GetFactorialSeries(n : int) : string
        {  
            // Create the String that will hold the list  
            def series : StringBuilder = StringBuilder();  
            // We begin by concatenating the number you want to calculate  
            // in the following format: "!# ="  
            _ = series.Append("!");
            _ = series.Append(n);  
            _ = series.Append(" = ");  
            // We iterate backwards through the elements of the series  
            for (mutable i : int = n; i &amp;lt;= n &amp;amp;&amp;amp; i &amp;gt; 0; i--)  
            {  
                // and append it to the list  
                _ = series.Append(i);  
                if (i &amp;gt; 1)  
                    _ = series.Append(" * ");  
                else   
                    _ = series.Append(" = ");   
            }  
            // Get the result from the Factorial Method  
            // and append it to the end of the list  
            _ = series.Append(Factorial(n));  
            // return the list as a string  
            series.ToString();  
        }
        // Using a StringBuilder as a list of string elements  
        public static GetFibonnaciSeries(n : int) : string 
        {  
            // Create the String that will hold the list  
            def series : StringBuilder = StringBuilder();  
            // We begin by concatenating the first 3 values which  
            // are always constant  
            _ = series.Append("0, 1, 1");  
            // Then we calculate the Fibonacci of each element  
            // and add append it to the list  
            for (mutable i : int = 2; i &amp;lt;= n; i++)  
            {  
                if (i &amp;lt; n)  
                    _ = series.Append(", ");  
                else  
                    _ = series.Append(" = ");  
                  
                _ = series.Append(Fibonacci(i));  
            }  
            // return the list as a string  
            series.ToString();  
        }  
        // Static Method - Factorial Recursive
        public static Factorial(n : int) : BigInteger
        {            
            if (n == 1)
                 BigInteger(1);
            else 
                 BigInteger(n) * Factorial(n - 1);
        }        
        // Static Method - Fibonacci Recursive
        public static Fibonacci(n : int) : long
        {
            def oneLong : long = 1;
            if (n &amp;lt; 2)
                oneLong;
            else
                Fibonacci(n - 1) + Fibonacci(n - 2);
        }        
    }
        
    module Program
    {
        Main() : void
        {          
            printf("\nStatic Class\n");
            // Printing Factorial Series  
            printf("\n");
            printf("%s\n", Fiborial.GetFactorialSeries(5));
            printf("%s\n", Fiborial.GetFactorialSeries(7));  
            printf("%s\n", Fiborial.GetFactorialSeries(9));  
            printf("%s\n", Fiborial.GetFactorialSeries(11));  
            printf("%s\n", Fiborial.GetFactorialSeries(40));  
            // Printing Fibonacci Series  
            printf("\n");
            printf("%s\n", Fiborial.GetFibonnaciSeries(5));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(7));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(9));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(11));  
            printf("%s\n", Fiborial.GetFibonnaciSeries(40));              
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-gefgraJE6Ew/TY9vVa9TQCI/AAAAAAAAF5E/JTNThf_e5zQ/s1600/fiborial_n_extras_series.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="345" src="http://1.bp.blogspot.com/-gefgraJE6Ew/TY9vVa9TQCI/AAAAAAAAF5E/JTNThf_e5zQ/s640/fiborial_n_extras_series.PNG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Mixing Instance and Static Members in the same Class&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We can also define instance classes that have both, instance and static members such as: fields, properties, constructors, methods, etc. However, we cannot do that if the class is marked as static because of the features mentioned in the previous post:&lt;br /&gt;
The main features of a static class are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;They only contain static members.&lt;/li&gt;
&lt;li&gt;They cannot be instantiated.&lt;/li&gt;
&lt;li&gt;They are sealed.&lt;/li&gt;
&lt;li&gt;They cannot contain Instance Constructors&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;using System;  
namespace FiborialExtrasN2
{
    // Instance Class
    class Fiborial  
    {  
        // Instance Field  
        mutable instanceCount : int;  
        // Static Field  
        static mutable staticCount : int;          
        // Instance Read-Only Property  
        // Within instance members, you can always use    
        // the "this" reference pointer to access your (instance) members.  
        public InstanceCount : int
        {  
            get { this.instanceCount; }  
        }  
        // Static Read-Only Property  
        // Remeber that Properties are Methods to the CLR, so, you can also  
        // define static properties for static fields.   
        // As with Static Methods, you cannot reference your class members  
        // with the "this" reference pointer since static members are not  
        // instantiated.          
        public static StaticCount : int
        {  
            get { staticCount; }  
        }  
        // Instance Constructor  
        public this()  
        {  
            this.instanceCount = 0;  
            Console.WriteLine("\nInstance Constructor {0}", this.instanceCount);  
        }  
        // Static Constructor  
        static this()  
        {  
            staticCount = 0;  
            Console.WriteLine("\nStatic Constructor {0}", staticCount);  
        }  
  
        // Instance Method  
        public Factorial(n : int) : void
        {  
            this.instanceCount += 1;  
            Console.WriteLine("\nFactorial({0})", n);  
        }  
  
        // Static Method  
        public static Fibonacci(n : int) : void
        {  
            staticCount += 1;  
            Console.WriteLine("\nFibonacci({0})", n);  
        }                   
    }
        
    module Program
    {
        Main() : void
        {          
            // Calling Static Constructor and Methods  
            // No need to instantiate  
            Fiborial.Fibonacci(5);              
  
            // Calling Instance Constructor and Methods  
            // Instance required  
            def fib : Fiborial = Fiborial();  
            fib.Factorial(5);              
  
            Fiborial.Fibonacci(15);              
            fib.Factorial(5);  
  
            // Calling Instance Constructor and Methods  
            // for a second object  
            def fib2 : Fiborial = Fiborial();  
            fib2.Factorial(5);  
              
            Console.WriteLine();  
            // Calling Static Property  
            Console.WriteLine("Static Count = {0}", Fiborial.StaticCount);  
            // Calling Instance Property of object 1 and 2  
            Console.WriteLine("Instance 1 Count = {0}", fib.InstanceCount);  
            Console.WriteLine("Instance 2 Count = {0}", fib2.InstanceCount); 
        }
    }
}
&lt;/pre&gt;&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-OpwI1augWPk/TY9vqUwmDuI/AAAAAAAAF5I/MEQCMmYKHt0/s1600/fiborial_n_extras2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="391" src="http://1.bp.blogspot.com/-OpwI1augWPk/TY9vqUwmDuI/AAAAAAAAF5I/MEQCMmYKHt0/s400/fiborial_n_extras2.PNG" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/_0_HCzHGe4_k/TJYz5ZgkFGI/AAAAAAAAFwk/Y8rwLu2Bags/s1600/output_ipy_ext.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Factorial using System.Int64, System.Double, System.Numerics.BigInteger&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The Factorial of numbers over 20 are massive!&lt;br /&gt;
For instance: !40 = 815915283247897734345611269596115894272000000000!&lt;br /&gt;
Because of this, the previous version of this program was giving the "wrong" result &lt;br /&gt;
!40 = -70609262346240000 when using "long" (System.Int64) type, but it was not until I did the Fiborial version in VB.NET that I realized about this faulty code, because instead of giving me a wrong value, VB.NET, JScript.NET, Boo execution thrown an Overflow Exception when using the "Long/long" (System.Int64) type.&lt;br /&gt;
&lt;br /&gt;
My first idea was to use ulong and ULong, but both failed for "big" numbers. I then used Double (double floating point) type and got no more exception/wrong result. The result of the factorial was now correct !40 = 1.1962222086548E+56, but still I wanted to show the Integer value of it, so I did some research and found that there is a new System.Numerics.BigInteger class in the .NET Framework 4.0. Adding the reference to the project and using this new class as the return type of the Factorial methods, I was able to get the result I was expecting.&lt;br /&gt;
!40 = 815915283247897734345611269596115894272000000000&lt;br /&gt;
&lt;br /&gt;
What I also found was that using different types change the time the algorithm takes to finish:&lt;br /&gt;
System.Int64 &amp;lt; System.Double &amp;lt; System.Numerics.BigInteger  &lt;br /&gt;
Almost by double!&lt;br /&gt;
&lt;br /&gt;
To illustrate what I just "tried" to say, lets have a look at the following code and the output we get.  &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="csharp" name="code"&gt;#pragma indent
using System;  
using System.Numerics;  
using System.Diagnostics;  
using System.Console;

namespace FiborialExtrasCs3

    module Program
        // Long Factorial
        public static FactorialInt64(n : int) : long
            def oneLong : long = 1;
            if (n == 1)
                 oneLong;
            else 
                 n * FactorialInt64(n - 1);

        // Double Factorial
        public static FactorialDouble(n : int) : double
            def oneDouble : double = 1;
            if (n == 1)
                oneDouble;
            else 
                 n * FactorialDouble(n - 1);

        // BigInteger Factorial
        public static FactorialBigInteger(n : int) : BigInteger
            if (n == 1)
                 BigInteger(1);
            else 
                 BigInteger(n) * FactorialBigInteger(n - 1);
    
        Main() : void
            def timer : Stopwatch = Stopwatch();  
            mutable facIntResult : long = 0;  
            mutable facDblResult : double = 0;  
            mutable facBigResult : BigInteger = BigInteger(0);
                        
            WriteLine("\nFactorial using Int64");
            // Benchmark Factorial using Int64
            // Overflow Exception!!!
            try
                foreach (i in $[5,10..50])
                    timer.Start();  
                    facIntResult = FactorialInt64(i);  
                    timer.Stop();
                    WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facIntResult);  
            catch
                | ex is OverflowException =&amp;gt;
                    // yummy ^_^  
                    WriteLine("Oops! {0}", ex.Message);
            
            WriteLine("\nFactorial using Double");  
            // Benchmark Factorial using Double  
            foreach (i in $[5,10..50])
                timer.Start();  
                facDblResult = FactorialDouble(i);
                timer.Stop();
                WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facDblResult);  
            
            WriteLine("\nFactorial using BigInteger");  
            // Benchmark Factorial using BigInteger
            foreach (i in $[5,10..50])
                timer.Start();
                facBigResult = FactorialBigInteger(i);
                timer.Stop();
                WriteLine(" ({0}) = {1} : {2}", i, timer.Elapsed, facBigResult);
&lt;/pre&gt;&lt;br /&gt;
NOTE: you need to manually add a reference to the System.Numerics.dll assembly to your project so you can add it to your code.&lt;br /&gt;
&lt;br /&gt;
And the Output is:&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s1600/fiborial_n_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="478" src="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s640/fiborial_n_extras_big_int.PNG" width="640" /&gt;&amp;nbsp;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-GdIEa1Uatg8/TY9wCJl6TbI/AAAAAAAAF5M/AUQ55fdqdSE/s1600/fiborial_n_extras_big_int.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&amp;nbsp;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/CarlosQuintanillasBlog/~4/nXw_hqupRZQ" height="1" width="1"/&gt;</content><link rel="replies" type="application/atom+xml" href="http://carlosqt.blogspot.com/feeds/7518171880813965006/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-nemerle.html#comment-form" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7518171880813965006?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/694679611587040520/posts/default/7518171880813965006?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/CarlosQuintanillasBlog/~3/nXw_hqupRZQ/factorial-and-fibonacci-in-nemerle.html" title="Factorial and Fibonacci in Nemerle" /><author><name>Carlos Quintanilla</name><uri>https://plus.google.com/103812980022168720722</uri><email>noreply@blogger.com</email><gd:image rel="http://schemas.google.com/g/2005#thumbnail" width="32" height="32" src="//lh6.googleusercontent.com/-EKrGt6V_uww/AAAAAAAAAAI/AAAAAAAAAAA/J-FvwrZk95A/s512-c/photo.jpg" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/-RsydOKZ3ajM/TY9vABXaJ2I/AAAAAAAAF5A/Sei1PrF70JE/s72-c/fiborial_n.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://carlosqt.blogspot.com/2011/03/factorial-and-fibonacci-in-nemerle.html</feedburner:origLink></entry></feed>
