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

What's hot

Java
Java Java
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
Java static keyword
Java static keywordJava static keyword
Java static keyword
Lovely Professional University
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
introduction to c #
introduction to c #introduction to c #
introduction to c #
Sireesh K
 
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
 
Metaprogramming in Ruby
Metaprogramming in RubyMetaprogramming in Ruby
Metaprogramming in Ruby
Nicolò Calcavecchia
 
Demystifying Shapeless
Demystifying Shapeless Demystifying Shapeless
Demystifying Shapeless
Jared Roesch
 
6. static keyword
6. static keyword6. static keyword
6. static keyword
Indu Sharma Bhardwaj
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
Brent Lemons
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in Scala
Rose Toomey
 
Java01
Java01Java01
Java01
Remon Hanna
 
Java intro
Java introJava intro
Java intro
Sonam Sharma
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
mosewoodward24
 
java development companies in Bangalore
java development companies in Bangalorejava development companies in Bangalore
java development companies in Bangalore
Shreya Anand
 
Quick Scala
Quick ScalaQuick Scala
Quick Scala
Puneet Kumar
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
Buddha Tree
 

What's hot (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
 

Similar to Introduction To Scala

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
Miles Sabin
 
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
Miles Sabin
 
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
 
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
CloudxLab
 
Programming in scala - 1
Programming in scala - 1Programming in scala - 1
Programming in scala - 1
Mukesh Kumar
 
Scala.pdf
Scala.pdfScala.pdf
Scala.pdf
ssuser155dbc1
 
Scala for Java Developers
Scala for Java DevelopersScala for Java Developers
Scala for Java Developers
Martin Ockajak
 
Functional programming in Scala
Functional programming in ScalaFunctional programming in Scala
Functional programming in Scala
datamantra
 
Scala - core features
Scala - core featuresScala - core features
Scala - core features
Łukasz Wójcik
 
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
Felipe
 
Scala Intro
Scala IntroScala Intro
Scala ntnu
Scala ntnuScala ntnu
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
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
 
Railroading into Scala
Railroading into ScalaRailroading into Scala
Railroading into Scala
Nehal Shah
 
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
Isaias Barroso
 

Similar to 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
 
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
 
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
 
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
 

Recently uploaded

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
IndexBug
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 

Recently uploaded (20)

HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial IntelligenceAI 101: An Introduction to the Basics and Impact of Artificial Intelligence
AI 101: An Introduction to the Basics and Impact of Artificial Intelligence
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 

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