Sunday, May 19, 2024

    Learn Object-Oriented Language Scala with Video Tutorials

    The word Scala means “scalable” i.e., a programming language that can scale for increasing user and hardware demands and making it effectively “future-proof”.
    Scala is a general purpose Object-Oriented/Functional programming language designed to express common programming patterns in a elegant, and type-safe manner. It also integrates features of object-oriented and functional languages. It is also fully compatible with Java.

    Also many existing companies who depend on Java for their business critical applications are turning to Scala to boost up their development productivity, applications scalability and overall reliability of their companies.

    Scala is widely adopted for some of the popular Social networking sites such as Twitter, LinkedIn and FourSquare. Approximately 100,000 programmers are already using this programming language and it still continues to be attract attention from industry for its elegance and concise pattern. Currently Scala v2.8 is capable of providing some of the amazing scripting features which somehow other programming languages like Java and C++ failed to do. Some of those applicatios are Boost development productivity, application scalability and system reliability.

    As an example, consider this Java code, which determines whether a string contains an upper case character:

    boolean nameHasUpperCase = false; // This is Javafor (int i = 0; i < namehasuppercase =" true;">The imperative style is in evidence here, because the nameHasUpperCase

    variable is reassigned as a side effect of the for loop, which iterates through the characters in the string by indexing. You can achieve the same result more concisely in Java like this:

    boolean nameHasUpperCase = !name.toLowerCase().equals(name);

    This line of Java code exhibits a more functional style, because it transforms immutable data: the name string is transformed to another, different string that is all lower case, then that value is transformed to a boolean result. In addition, the nameHasUpperCase variable is initialized, but at least in this snippet of code, not reassigned. It would be more clearly functional if the variable were final.

    In Scala, you could write code similar to the previous two examples, but the most idiomatic way to write this in Scala is:

    val nameHasUpperCase = name.exists(_.isUpperCase)

    The nameHasUpperCase variable is declared as a val, a variable that can be initialized but not reassigned (similar to a final variable in Java). Even though no explicit type annotations appear in this example, Scala’s type inference mechanism assigns type Boolean to nameHasUpperCase. The exists method iterates through a collection of objects and passes each element in turn to the passed function object. Here, the name string is being treated as a collection of characters, so exists will pass each character of the string to the function. The _.isUpperCase syntax is a function literal in Scala, a shorthand way to write a bit of code that can be passed around and invoked. The underscore stands for the function’s lone parameter. You can think of the underscore, therefore, as a blank that’s filled in each time the function is invoked. If the exists method finds that the function returns true for one of the passed characters—i.e., that one of the characters is upper case—it returns true. Otherwise it returns false.

    Working of Scala :

    Scala runs on the Java platform (i.e. Java Virtual Machine aka JVM) and is compatible with existing Java programs. It also runs on Java Platform, J2ME CLDC. Scala has the same compilation model as Java and C#, so Scala code can call Java libraries or .NET libs.

    Just like Java, Scala compiler generates byte code that is nearly identical to the Java compiler. In fact, you can decompile Scala code to readable Java code. To the JVM, Scala code and Java code are indistinguishable. The only difference is a single extra runtime library, scala-library.jar.

    Learn Scala – Video Tutorials

    Scala Video Part 1

    Scala Video Part 2

    Scala Video Part 3

    Source:Learn Scala with Video Tutorials

    Studied Computer science at Kuk Ngo and graduated in 2012.

    Related Articles



    Please enter your comment!
    Please enter your name here

    Stay Connected

    - Advertisement -spot_img

    Latest Articles