Archive for July, 2009

Null, null, Nil, Nothing, None, and Unit in Scala

Posted on July 12, 2009. Filed under: Scala | Tags: , , , , , , , |

Null- Its a Trait.
null- Its an instance of Null- Similar to Java null.
Nil- Represents an emptry List of anything of zero length. Its not that it refers to nothing but it refers to List which has no contents.
Nothing is a Trait. Its a subtype of everything. But not superclass of anything. There are no instances [...]

Read Full Post | Make a Comment ( 2 so far )

Traits in Scala- Deep Dive

Posted on July 11, 2009. Filed under: Scala | Tags: , , , |

Traits are units of code reuse in Scala. Traits encapsulates methods and field definitions. Their role is similar to that of interfaces in Java- A workaround for Multiple Inheritance. But unlike Interfaces they can have method and field definitions. More features will be explained in the article.
Defining Traits:
A trait definition looks like a class definition [...]

Read Full Post | Make a Comment ( None so far )

How’s Scala different from Java?

Posted on July 5, 2009. Filed under: Scala | Tags: , , |

Scala is statically type like Java but with Type Inferencing support. Which means that the scala compiler analyzes the code deeply to determine what type a particular value is.

In Scala its not required to use semicolons to terminate a statement if the termination is obvious by line ending. If there are more than one statements [...]

Read Full Post | Make a Comment ( None so far )

Control Structures in Scala- A brief overview

Posted on July 3, 2009. Filed under: Scala | Tags: , , , , , , |

If Statements:
Lets consider a first entry example of If statments, without using much of Scala’s features.

if(5+6==10){

println("You are wrong in calculations")

}else{

println("Keep it up")

}

This is a pretty simple and straight forward examples. Now lets add some Scala flavor in the If-Statement. In Scala If-Statements are expressions, which means that the value from If-Statements can be assigned to [...]

Read Full Post | Make a Comment ( None so far )

Tuples- Returning multiple values in Scala

Posted on July 3, 2009. Filed under: Scala | Tags: , , , |

When I was coding in Java I used to build Classes just to return multpile values and also sometimes used pass by reference (by means of using Objects). I really missed a permanent solution :( Scala has a solution for this- It supports something called “Tuples” which is created with the literal syntax of a comma-separated list of the items inside parentheses like (x1,x2,x3 …). The items in the parantheses may not be related to each other in terms of the type, which means that we can have String’s, Int’s and so on. These literal “groupings” are instantiated as scala.TupleN instances, where the N is the number of items in the tuple. The Scala API defines separate TupleN classes for N between 1 and 22, inclusive. Tuples can be assigned to variables, passed as values or return them from the methods.

Read Full Post | Make a Comment ( None so far )

“val” versus “var” Declarations in Scala

Posted on July 2, 2009. Filed under: Scala | Tags: , , , , |

Scala allows programmers to decide whether the variable is immutable or mutable. This can be done by using the keywords “val” and “var”. Continue reading to know more about “val” and “var”.

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...