In this post I will cover comparision between Java and Scala.(Post Updation in Progress).
1. Lesser use of Semicolons.Scala behaves like many scripting languages in treating the end of the line as the end of a statement or an expression.
A snippet of a Helloworld program
println("Hello World !")
2. Not necessary to define a class and a main method.
3. Scala tries to stay to stay close to pure object-oriented programming and therefore does not have constructs like static fields and methods. Every value in Scala is an object and every operation is a method call.
4. Scala uses keywords val and var to indicate a value versus a variable. Values are immutable and are the equivalent of final in Java while variables are mutable. Values and variables defined in the object or class definition context represent properties and are in effect public by default, but can be protected or private just like Java.
5. All the libraries in java are implicitly imported into scala.
6. Arrays are collections unlike in Java.
7. Optional empty parameter lists
Providing that no object or class property have the same name, parenthesis around empty parameter lists are optional. In the above example, the compiler can determine that getTitle invokes getTitle().
8. Scala is a pure object-oriented language and does not support primitives.
9. Multi-line strings
var str = """This
is
a
multi-line
string"""
10. Non-alphanumeric characters in method names Allowed.
11. Inferred return values based on result of last expression in code block.Scala does not require an explicit return in a method, though it is supported.
12. In Scala, pattern matching is not quite as integrated in to the language as it is in Erlang or OCaml where functions themselves have multiple definitions and the one invoked is based on how arguments match patterns. Scala provides a match/case construct.
13. Traits are an improvement over Java interfaces in that they can contain implementation code.
trait Foos {
def doFoo(text:String) = printf("{0}: Foo(\"{1}\")\n", this.toString, text)
}
class FooClass extends Foos {
override def toString = "FooClass"
}
14. Another Fantastic Feature is Sequence comprehensions.
Sequence comprehensions (also called "for comprehensions") provide a syntax to iterate over multiple enumerations, apply conditionals.
var someValue;
var anotherCondtion;
for (someValue< 100;
someValue>100 if anotherCondtion) {
println("Hello World")
}
15. Better XML Processing API. Inbuilt support of wrapping XML data in the similar lines as string in Java.
16. Null and Nothingness defined better handled in Scala.
Null and Nothingness
17. Concurrency Control using Actors Library.
This feature was inspired by a similar concept in the functional language, Erlang. Actors are basically concurrent processes that communicate via message passing. Actors support both synchronous and asynchronous message passing.
18.Lazy Evaluation : This feature was new as of Scala version 2.6. It allows an object property not to be evaluated until the value is accessed.
19. Scala includes a concept of Partially Applied Functions which is in way inherited from Haskell. Including a Link which describes these concepts.
Sunday, January 23, 2011
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment