CSC/ECE 517 Fall 2014/ch1a 9 kn: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 36: Line 36:
* <b>Seamless Interoperability with Java</b>
* <b>Seamless Interoperability with Java</b>
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries may be used directly in Scala code, and vice versa.
Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries may be used directly in Scala code, and vice versa.
A simple "Hello World" example in Scala:
<pre>
object HelloWorld extends App {
  println("Hello, World!")
}
</pre>
== Introduction to Java ==
Java is one of the more advanced and popular object-oriented based computer programming language. Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Java applications are typically compiled to byte-code(class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. The presence of Java Byte Code makes the language portable. There were five primary goals in the creation of the Java language:
* It should be "simple, object-oriented and familiar"
* It should be "robust and secure"
* It should be "architecture-neutral and portable"
* It should execute with "high performance"
* It should be "interpreted, threaded, and dynamic"
Syntactically Java is similar to C++ and a “Hello World” program in Java would look as follows:
<pre>
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}
</pre>
== Features of Scala ==

Revision as of 17:54, 17 September 2014

Functional Programming Languages i.e Scala over Object Oriented Languages i.e Java

What is Functional Programming

Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions. In functional programming, programs are executed by evaluating expressions, in contrast with imperative programming where programs are composed of statements which change global state when executed. Functional programming typically avoids using mutable state. Examples of functional Programming languages are:

  • Haskell
  • Scala
  • Erlang

What is Object-oriented Programming

Object-oriented programming (OOP) is a programming language model which is organized around objects rather than "actions" and data rather than logic. A program has always been thought as a logical function that takes input data, processes it and produces the output. Object oriented programming cares about the objects we want to manipulate rather than the logic required to manipulate them. Objects here are usually instances of classes which are used to design applications and computer programs. Object-oriented programming languages have a come a long way starting from Simula all the way to languages like JAVA, Ruby etc. Some of the key features of object oriented programming languages are:

  • Encapsulation
  • Inheritance
  • Polymorphism
  • Reflection
  • Abstraction

Introduction to Scala

Scala is an acronym for “Scalable Language”. It is an object- functional programming and scripting language which fuses functional and object-oriented programming in a practical package. Scala is now being used in a rapidly increasing number of open source projects and companies. It provides the core infrastructure for sites such as Twitter, LinkedIn, Foursquare, Tumblr, and Klout.

Aspects of Scala

The major aspects of Scala are:

  • Object oriented

Scala is a pure-bred object-oriented language. Conceptually, every value is an object and every operation is a method-call. The language supports advanced component architectures through classes and traits. Many traditional design patterns in other languages are already natively supported in SCALA.

  • Functional

Even though its syntax is fairly conventional, Scala is also a full-blown functional language. Many of Scala's design decisions were inspired by criticism over the shortcomings of Java. Scala has full support for functional programming concepts such as currying, pattern matching, algebraic data types, lazy evaluation, tail recursion, immutability, etc.

  • Seamless Interoperability with Java

Scala source code is intended to be compiled to Java bytecode, so that the resulting executable code runs on a Java virtual machine. Java libraries may be used directly in Scala code, and vice versa.

A simple "Hello World" example in Scala:


 object HelloWorld extends App {
   println("Hello, World!")
 }

Introduction to Java

Java is one of the more advanced and popular object-oriented based computer programming language. Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible. Java applications are typically compiled to byte-code(class file) that can run on any Java virtual machine (JVM) regardless of computer architecture. The presence of Java Byte Code makes the language portable. There were five primary goals in the creation of the Java language:

  • It should be "simple, object-oriented and familiar"
  • It should be "robust and secure"
  • It should be "architecture-neutral and portable"
  • It should execute with "high performance"
  • It should be "interpreted, threaded, and dynamic"

Syntactically Java is similar to C++ and a “Hello World” program in Java would look as follows:

class HelloWorldApp {
    public static void main(String[] args) {
         System.out.println("Hello World!"); 
    }
}

Features of Scala