SlideShare a Scribd company logo
scala> “Hello Scala”

Scala stands for “scalable language.” The
          language is so named
because it was designed to grow with the
          demands of its users.
History
●   The design of Scala started in 2001 at the (EPFL) by Martin
    Odersky, Odersky had previously worked on Generic Java
    and javac, Sun's Java compiler
●   Scala was released late 2003/early 2004 on the Java
    platform
●   Recent Scala release 2.10.0
●   On 12 May 2011, Odersky and collaborators launched
    Typesafe Inc., a company to provide commercial support,
    training, and services for Scala
Scala Adopters
●   Twitter
●   FourSqaure
●   LinkedIn
●   Sony
●   OPOWER
●   Siemens
Features
●   Scala is OO
●   Scala is Functional
●   Strongly Typed – even more so than Java
●   Type Invariance
●   Implicits – Analogous to Ruby's open classes
●   Duck Typing – anything that quacks is a duck
●   String Interpolation
Hello Scala
object Greeting {
    def main(args: Array[String]) {
        println("Hello World !!!")
    }
}
●       Look maa no semicolon
●       Object ?
Variables
object Greeter {
    def main(args:Array[String]) {
        val message = “Hello” // final equivalent
        message = “Bye !!” // won't work
        var num = 2
        num = 3 // will work
    }
}
Classes
●   class Person(val name:String, val id:Int)
●   Is equivalent to Java's
    class Person {
        private String name;
        private Integer id;
        ….
    }
●   val p = new Person(“John”, 1)
Functions
def calculate(msg:String, count:Int) : String =
msg.take(count)
●   def implies a function declaration
●   msg and count are parameters
●   : String implies the return type of the function
●   In Scala everything returns a value
●   Even assignment x = 1 returns a special value called
    Unit (A feature coming from dynamic languages like
    Ruby)
Tuples are DTO's – Ted Neward
●   Returning multiple values from a function
●   def calculate() : Tuple2[Int, String] = (2, "Ted")
●   val v = calculate // Scala convention no parenthesis
●   Accessing each of the values
    –   v._1 : refers to the first return value
    –   v._2 : refers to the second value
●   Scala has had a big impact from dynamic languages
    like Ruby
Collections
●   List(1,2,3) // no need to pass the type info
●   Set(1,2,2)
●   Map(1-> ”One”, 2-> ”Two”, 3-> ”Three”)
●   Ranges: 1 to 10 / 1 until 10 by 2
●   Array(1,2,3)
●   Default collections types are immutable
Commonly used methods
●   val l = List(1,2,3)
●   l.head / l.tail
●   l.foreach(println)
●   l.map(_ * 2)
●   l.filter(_ > 1) / l.filter(_ < 2)
●   l.exists(_ < 0)
●   l.reverse
●   l.take / l.drop
●   ….
Higher Order Functions
●   Functions taking functions are called higher
    order functions
●   Cannot pass functions in Java not until
    Lambdas in Java8
●   def foo(f : (String => Boolean)) : String = if (f("Ted")) "Cool" else "Not Cool !!"

●   l.filter / l.foreach / l.map are all examples
●   This is a standard feature of all Scala libraries
Case classes
●   case class Person(name:String, id:Integer)
●   val p = Person(“Martin”, 2) // no new needed
●   It automatically adds getter's, equals and
    hashcode
●   Case classes are used for pattern matching
Pattern Matching
●   Switch with steroids :)
    List(1,2,3) match {
        case Nil => "Empty"
        case x if x.length == 3 => "Blaah ..."
        case _ =>
    }
●   Match also returns a value
●   You can have conditional expressions as well
●   It works for all data types
Excited? Any Questions?
●   Resources
    –   Scala lang
    –   Programming in Scala 2nd Edition
    –   Typesafe Inc.
    –   IDE Support (Intellij & Eclipse Scala IDE)
    –   Pune Scala User Group
●   Follow me on twitter for live Scala feeds :)

More Related Content

PPTX
Introduction to Scala
PDF
Miles Sabin Introduction To Scala For Java Developers
PPTX
Scala basic
PDF
Android course session 5 (Threads & socket)
PPTX
Chapter 2 java
PDF
Scala cheatsheet
PPTX
Programming picaresque
PPTX
Learning core java
Introduction to Scala
Miles Sabin Introduction To Scala For Java Developers
Scala basic
Android course session 5 (Threads & socket)
Chapter 2 java
Scala cheatsheet
Programming picaresque
Learning core java

What's hot (19)

PPT
PPT
Final keyword in java
PPT
Java static keyword
PPTX
Scala, Play 2.0 & Cloud Foundry
PPTX
introduction to c #
PDF
An Introduction to Scala - Blending OO and Functional Paradigms
PDF
Metaprogramming in Ruby
PDF
Demystifying Shapeless
PPTX
6. static keyword
PPTX
An Introduction to Scala
PPT
Oop java
PPTX
Core java complete ppt(note)
PPTX
Practical type mining in Scala
PPT
Java01
PPT
Java intro
PPT
RIBBUN SOFTWARE
PPT
java development companies in Bangalore
PPTX
Quick Scala
PPT
Java core - Detailed Overview
Final keyword in java
Java static keyword
Scala, Play 2.0 & Cloud Foundry
introduction to c #
An Introduction to Scala - Blending OO and Functional Paradigms
Metaprogramming in Ruby
Demystifying Shapeless
6. static keyword
An Introduction to Scala
Oop java
Core java complete ppt(note)
Practical type mining in Scala
Java01
Java intro
RIBBUN SOFTWARE
java development companies in Bangalore
Quick Scala
Java core - Detailed Overview
Ad

Similar to Introduction To Scala (20)

PDF
A Brief Introduction to Scala for Java Developers
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
PDF
An Introduction to Scala for Java Developers
PDF
Scala at HUJI PL Seminar 2008
PDF
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
PDF
Programming in scala - 1
PDF
Scala.pdf
PDF
Scala for Java Developers
PDF
Functional programming in Scala
PDF
Scala - core features
PDF
Short intro to scala and the play framework
PPTX
ODP
PPT
Scala Talk at FOSDEM 2009
PDF
scalaliftoff2009.pdf
PDF
scalaliftoff2009.pdf
PDF
scalaliftoff2009.pdf
PDF
scalaliftoff2009.pdf
PDF
Railroading into Scala
PPT
Scala uma poderosa linguagem para a jvm
A Brief Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Scala at HUJI PL Seminar 2008
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Programming in scala - 1
Scala.pdf
Scala for Java Developers
Functional programming in Scala
Scala - core features
Short intro to scala and the play framework
Scala Talk at FOSDEM 2009
scalaliftoff2009.pdf
scalaliftoff2009.pdf
scalaliftoff2009.pdf
scalaliftoff2009.pdf
Railroading into Scala
Scala uma poderosa linguagem para a jvm
Ad

Recently uploaded (20)

PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Big Data Technologies - Introduction.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
Approach and Philosophy of On baking technology
Big Data Technologies - Introduction.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
The Rise and Fall of 3GPP – Time for a Sabbatical?
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Empathic Computing: Creating Shared Understanding
Advanced Soft Computing BINUS July 2025.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Reach Out and Touch Someone: Haptics and Empathic Computing

Introduction To Scala

  • 1. scala> “Hello Scala” Scala stands for “scalable language.” The language is so named because it was designed to grow with the demands of its users.
  • 2. History ● The design of Scala started in 2001 at the (EPFL) by Martin Odersky, Odersky had previously worked on Generic Java and javac, Sun's Java compiler ● Scala was released late 2003/early 2004 on the Java platform ● Recent Scala release 2.10.0 ● On 12 May 2011, Odersky and collaborators launched Typesafe Inc., a company to provide commercial support, training, and services for Scala
  • 3. Scala Adopters ● Twitter ● FourSqaure ● LinkedIn ● Sony ● OPOWER ● Siemens
  • 4. Features ● Scala is OO ● Scala is Functional ● Strongly Typed – even more so than Java ● Type Invariance ● Implicits – Analogous to Ruby's open classes ● Duck Typing – anything that quacks is a duck ● String Interpolation
  • 5. Hello Scala object Greeting { def main(args: Array[String]) { println("Hello World !!!") } } ● Look maa no semicolon ● Object ?
  • 6. Variables object Greeter { def main(args:Array[String]) { val message = “Hello” // final equivalent message = “Bye !!” // won't work var num = 2 num = 3 // will work } }
  • 7. Classes ● class Person(val name:String, val id:Int) ● Is equivalent to Java's class Person { private String name; private Integer id; …. } ● val p = new Person(“John”, 1)
  • 8. Functions def calculate(msg:String, count:Int) : String = msg.take(count) ● def implies a function declaration ● msg and count are parameters ● : String implies the return type of the function ● In Scala everything returns a value ● Even assignment x = 1 returns a special value called Unit (A feature coming from dynamic languages like Ruby)
  • 9. Tuples are DTO's – Ted Neward ● Returning multiple values from a function ● def calculate() : Tuple2[Int, String] = (2, "Ted") ● val v = calculate // Scala convention no parenthesis ● Accessing each of the values – v._1 : refers to the first return value – v._2 : refers to the second value ● Scala has had a big impact from dynamic languages like Ruby
  • 10. Collections ● List(1,2,3) // no need to pass the type info ● Set(1,2,2) ● Map(1-> ”One”, 2-> ”Two”, 3-> ”Three”) ● Ranges: 1 to 10 / 1 until 10 by 2 ● Array(1,2,3) ● Default collections types are immutable
  • 11. Commonly used methods ● val l = List(1,2,3) ● l.head / l.tail ● l.foreach(println) ● l.map(_ * 2) ● l.filter(_ > 1) / l.filter(_ < 2) ● l.exists(_ < 0) ● l.reverse ● l.take / l.drop ● ….
  • 12. Higher Order Functions ● Functions taking functions are called higher order functions ● Cannot pass functions in Java not until Lambdas in Java8 ● def foo(f : (String => Boolean)) : String = if (f("Ted")) "Cool" else "Not Cool !!" ● l.filter / l.foreach / l.map are all examples ● This is a standard feature of all Scala libraries
  • 13. Case classes ● case class Person(name:String, id:Integer) ● val p = Person(“Martin”, 2) // no new needed ● It automatically adds getter's, equals and hashcode ● Case classes are used for pattern matching
  • 14. Pattern Matching ● Switch with steroids :) List(1,2,3) match { case Nil => "Empty" case x if x.length == 3 => "Blaah ..." case _ => } ● Match also returns a value ● You can have conditional expressions as well ● It works for all data types
  • 15. Excited? Any Questions? ● Resources – Scala lang – Programming in Scala 2nd Edition – Typesafe Inc. – IDE Support (Intellij & Eclipse Scala IDE) – Pune Scala User Group ● Follow me on twitter for live Scala feeds :)