SlideShare uma empresa Scribd logo
1 de 15
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 :)

Mais conteúdo relacionado

Mais procurados

An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
Brent Lemons
 

Mais procurados (19)

Java
Java Java
Java
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Oop java
Oop javaOop java
Oop java
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in Scala
 
Java01
Java01Java01
Java01
 
Java intro
Java introJava intro
Java intro
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
java development companies in Bangalore
java development companies in Bangalorejava development companies in Bangalore
java development companies in Bangalore
 
Quick Scala
Quick ScalaQuick Scala
Quick Scala
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
 

Semelhante a Introduction To Scala

BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
Yardena Meymann
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 

Semelhante a Introduction To Scala (20)

A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
 
Scala.pdf
Scala.pdfScala.pdf
Scala.pdf
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
 
Scala - core features
Scala - core featuresScala - core features
Scala - core features
 
Short intro to scala and the play framework
Short intro to scala and the play frameworkShort intro to scala and the play framework
Short intro to scala and the play framework
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Railroading into Scala
Railroading into ScalaRailroading into Scala
Railroading into Scala
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 

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 :)