SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
JDevDay - Introduction to Scala


                       Saleem Ansari




                    10th March 2013




Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   1 / 35
Outline



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   2 / 35
Topic



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   3 / 35
What is Scala?


What is Scala? The name Scala stands for scalable language. The
language is so named because it was designed to grow with the
demands of its users.

    What makes Scala a Scalable Language ?
           Statically typed language with OOP + FP both.
           Fast and expressive, and peasant to use.
           Excellent type inference.
           Runs on JVM.

    Whats more?
           Scala is compatible with Java
           Scala is concise
           Scala is high level
           Scala is statically typed ( vs dynamically typed )



    Saleem Ansari ()          JDevDay - Introduction to Scala   10th March 2013   4 / 35
What can you do with Scala today?



   Write web applications
          Play Web Framework http://www.playframework.com/
          Lift Web Framework http://liftweb.net/

   Write code that scales to huge amounts of data
          Spark Project http://spark-project.org/
          Scalding https://github.com/twitter/scalding

   Process huge number of concurrent tasks
          Akka http://akka.io/

   Natural Language Processing and Machine Learning
          ScalaNLP http://www.scalanlp.org/

   And anything could do in Java, now more concisely :-)




   Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   5 / 35
Topic



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   6 / 35
Install the Scala Complier




   yum install scala




   Saleem Ansari ()    JDevDay - Introduction to Scala   10th March 2013   7 / 35
Install your faviourite Editor / IDE




    yum install emacs

    OR install Eclipse ( ScalaIDE )




    Saleem Ansari ()    JDevDay - Introduction to Scala   10th March 2013   8 / 35
Scala compiler is




   scalac ( just like javac command )

   scala ( just like java command )

   fsc ( fast scala compiler )




   Saleem Ansari ()     JDevDay - Introduction to Scala   10th March 2013   9 / 35
Topic



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   10 / 35
Hello Scala World


helloworld.scala

object HelloWorld {
  def main(args: Array[String]) = {
    println(Hello Scala World!)
  }
}




    Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   11 / 35
Compile and run Hello Scala World




Output

$ scalac helloworld.scala
$ ls
helloworld.scala
HelloWorld.class
HelloWorld$.class
$ scala HelloWorld
Hello Scala World!




   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   12 / 35
Values and Variables




   An example in Ruby ( or maybe Python ) a dynamically typed
   language
          counter = Counter.new
          counter = AtomicCounter.new
          counter = File.new # this works here!

   Scala's static type system, avoids runtime overhead of dynamic
   types. The method dispatch is fast in a statically typed
   language.
          var counter = new Counter()
          counter = new AtomicCounter() // this has to be a Counter
          counter = new File() // this doesn't work in Scala




   Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   13 / 35
Data Types




   Almost everything is same as Java

   Basic Data Types: ( all integers are signed two's complement )
          Integers:Byte (8bit), Short (16bit), Int (32bit), Long (64bit)
          Char (16 bit unicode character), String (squence of Chars)
          Reals: Float (32bit), Double (64bit)
          Boolean: true / false
   Literal
          basic data types i.e. 1, 0.123, 12L, `a', String
          symbol literal: `identier




   Saleem Ansari ()        JDevDay - Introduction to Scala   10th March 2013   14 / 35
More Concepts




   Data Containers
          Array
          List
          Set
          Map
          Tuple

   Programming Abstraction Tools
          Class
          Object
          Scala App
          Package




   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   15 / 35
Expressions




   Every thing is an expression
          Basic expression: 1+2
          An assignment is an expression
          A function is an expression




   Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   16 / 35
Control Constructs




   if-else

   while

   do-while

   for

   match-case

   try-catch-nally




   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   17 / 35
Topic



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   18 / 35
Matematical Logic


                       Lambda Calculus ( see
                       Wikipedia )




   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   19 / 35
Factorial Function




                  Expressed as mathematical logic




   Saleem Ansari ()        JDevDay - Introduction to Scala   10th March 2013   20 / 35
FP is guided by two main ideas:




   Functions arest-class values
   Functions have no side eects i.e.           they can be replaced with
   their values




   Saleem Ansari ()   JDevDay - Introduction to Scala     10th March 2013   21 / 35
Hallmarks of Functional Programming




   mapping

   ltering

   folding

   reducing




   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   22 / 35
Topic



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   23 / 35
Object Oriented




   Decompose the problem into entities and interactions among
   entities

   Each entity and their interaction is represented using
   class/object
          internal state is the member variables
          interactions are the member functions




   Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   24 / 35
Functions




factorial.scala

def factorial(n:Int): Int =
  if(n=0) 1 else n*factorial(n-1)

    Placeholder syntax

    Partially applied functions

    Closures




    Saleem Ansari ()     JDevDay - Introduction to Scala   10th March 2013   25 / 35
Traits




traits.scala

trait PartTime {
  // trait definition
}




    Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   26 / 35
Classes




classes.scala

class Employee(name: String, age: Int) {
  override def toString = name + ,  + age
}
class Supervisor(name: String, age: Int
  ) extends Employee(name, age) with PartTime
  {
  override def toString = name + ,  + age
}




    Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   27 / 35
Objects




objects.scala

object Employee {
  override def toString = name + ,  + age
}




    Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   28 / 35
Packages



package-example.scala

package in.tuxdna.scala
class Employee(name: String, age: Int) {
  override def toString = name + ,  + age
}

object Main extends App {
  val emp1 = new Employee(Tom, 21)
  println(Employee 1: +emp1)
}
// $ scalac pacakge-example.scala
// Employee 1: Tom, 21

   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   29 / 35
Features to be convered later



   XML Processing

   Actors

   Case Classes

   Properties

   Extistential Types

   Implicits

   Lazy Evaluation

   Parser Combinations

   Monads

   Annotations




   Saleem Ansari ()     JDevDay - Introduction to Scala   10th March 2013   30 / 35
Using Scala as a scripting language



   scala scriptname.scala


employee.scala

class Employee(name: String, age: Int) {
  override def toString = name + ,  + age
}

val emp1 = new Employee(Tom, 21)
println(Employee 1: +emp1)

// $ scala employee.scala
// Employee 1: Tom, 21

   Saleem Ansari ()    JDevDay - Introduction to Scala   10th March 2013   31 / 35
Topic



1   Introduction to Scala


2   Setting up Scala


3   Absolute Scala basics


4   Functional Paradigm in Scala


5   Object Oriented Programming in Scala


6   Where to learn more Scala




     Saleem Ansari ()       JDevDay - Introduction to Scala   10th March 2013   32 / 35
Books

   Scala for the Impatient (free) http://blog.typesafe.com/free-
   pdf-from-typesafe-scala-for-the-impatien-64715



   Programming Scala (free)
   http://ofps.oreilly.com/titles/9780596155957

   Programming in Scala 2nd Ed.
   http://www.amazon.com/Programming-Scala-Comprehensive-
   Step-Step/dp/0981531644


   Functional Programming Principles in Scala ( free online
   course )
          https://www.coursera.org/course/progfun

   Blogs

   Forums
   Saleem Ansari ()      JDevDay - Introduction to Scala   10th March 2013   33 / 35
Questions?




   tuxdna (at) gmail (dot) com




   Saleem Ansari ()   JDevDay - Introduction to Scala   10th March 2013   34 / 35
Thank you!




   twitter.com/tuxdna




   Saleem Ansari ()     JDevDay - Introduction to Scala   10th March 2013   35 / 35

Weitere ähnliche Inhalte

Was ist angesagt?

Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San FranciscoMartin Odersky
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoTaro L. Saito
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of ScalaMartin Odersky
 
Refactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapRefactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapDave Orme
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange openingMartin Odersky
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaDerek Chen-Becker
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scalatod esking
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at TwitterAlex Payne
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slidesMartin Odersky
 

Was ist angesagt? (20)

Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Scala Days San Francisco
Scala Days San FranciscoScala Days San Francisco
Scala Days San Francisco
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, TokyoWeaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
 
The Evolution of Scala
The Evolution of ScalaThe Evolution of Scala
The Evolution of Scala
 
Refactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 RecapRefactoring to Scala DSLs and LiftOff 2009 Recap
Refactoring to Scala DSLs and LiftOff 2009 Recap
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
Scalax
ScalaxScalax
Scalax
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to Scala
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
The Why and How of Scala at Twitter
The Why and How of Scala at TwitterThe Why and How of Scala at Twitter
The Why and How of Scala at Twitter
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Lecture1
Lecture1Lecture1
Lecture1
 
flatMap Oslo presentation slides
flatMap Oslo presentation slidesflatMap Oslo presentation slides
flatMap Oslo presentation slides
 

Andere mochten auch

Introduction to Free and Open Source Software - August 2005
Introduction to Free and Open Source Software - August 2005Introduction to Free and Open Source Software - August 2005
Introduction to Free and Open Source Software - August 2005Saleem Ansari
 
Web Application Development
Web Application DevelopmentWeb Application Development
Web Application DevelopmentSaleem Ansari
 
Introduction to Qt Designer
Introduction to Qt DesignerIntroduction to Qt Designer
Introduction to Qt DesignerSaleem Ansari
 
Lessons I learnt from Linux Asia 2006
Lessons I learnt from Linux Asia 2006Lessons I learnt from Linux Asia 2006
Lessons I learnt from Linux Asia 2006Saleem Ansari
 
Linx Asia 2006 Experience
Linx Asia 2006 ExperienceLinx Asia 2006 Experience
Linx Asia 2006 ExperienceSaleem Ansari
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with ScalaHimanshu Gupta
 

Andere mochten auch (6)

Introduction to Free and Open Source Software - August 2005
Introduction to Free and Open Source Software - August 2005Introduction to Free and Open Source Software - August 2005
Introduction to Free and Open Source Software - August 2005
 
Web Application Development
Web Application DevelopmentWeb Application Development
Web Application Development
 
Introduction to Qt Designer
Introduction to Qt DesignerIntroduction to Qt Designer
Introduction to Qt Designer
 
Lessons I learnt from Linux Asia 2006
Lessons I learnt from Linux Asia 2006Lessons I learnt from Linux Asia 2006
Lessons I learnt from Linux Asia 2006
 
Linx Asia 2006 Experience
Linx Asia 2006 ExperienceLinx Asia 2006 Experience
Linx Asia 2006 Experience
 
Introduction to Spark with Scala
Introduction to Spark with ScalaIntroduction to Spark with Scala
Introduction to Spark with Scala
 

Ähnlich wie Introduction to Scala

Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaDerek Chen-Becker
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Scala overview
Scala overviewScala overview
Scala overviewSteve Min
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinayViplav Jain
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»e-Legion
 
Scala in a wild enterprise
Scala in a wild enterpriseScala in a wild enterprise
Scala in a wild enterpriseRafael Bagmanov
 
Beginning scala 02 15
Beginning scala 02 15Beginning scala 02 15
Beginning scala 02 15lancegatlin
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectŁukasz Dumiszewski
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark Summit
 
Bring the Spark To Your Eyes
Bring the Spark To Your EyesBring the Spark To Your Eyes
Bring the Spark To Your EyesDemi Ben-Ari
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfssusercd195b
 
Scala introduction
Scala introductionScala introduction
Scala introductionzvikapika
 
Scala's evolving ecosystem- Introduction to Scala.js
Scala's evolving ecosystem- Introduction to Scala.jsScala's evolving ecosystem- Introduction to Scala.js
Scala's evolving ecosystem- Introduction to Scala.jsKnoldus Inc.
 
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Roger Huang
 

Ähnlich wie Introduction to Scala (20)

Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Scala overview
Scala overviewScala overview
Scala overview
 
Unit 1 notes.pdf
Unit 1 notes.pdfUnit 1 notes.pdf
Unit 1 notes.pdf
 
Scala final ppt vinay
Scala final ppt vinayScala final ppt vinay
Scala final ppt vinay
 
Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»Rafael Bagmanov «Scala in a wild enterprise»
Rafael Bagmanov «Scala in a wild enterprise»
 
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
 
Scala in a wild enterprise
Scala in a wild enterpriseScala in a wild enterprise
Scala in a wild enterprise
 
Beginning scala 02 15
Beginning scala 02 15Beginning scala 02 15
Beginning scala 02 15
 
Apache Spark
Apache Spark Apache Spark
Apache Spark
 
Programming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire projectProgramming in Spark - Lessons Learned in OpenAire project
Programming in Spark - Lessons Learned in OpenAire project
 
Spark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin OderskySpark - The Ultimate Scala Collections by Martin Odersky
Spark - The Ultimate Scala Collections by Martin Odersky
 
Bring the Spark To Your Eyes
Bring the Spark To Your EyesBring the Spark To Your Eyes
Bring the Spark To Your Eyes
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
All about scala
All about scalaAll about scala
All about scala
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Scala's evolving ecosystem- Introduction to Scala.js
Scala's evolving ecosystem- Introduction to Scala.jsScala's evolving ecosystem- Introduction to Scala.js
Scala's evolving ecosystem- Introduction to Scala.js
 
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
Intro to Apache Spark and Scala, Austin ACM SIGKDD, 7/9/2014
 
Scala 20140715
Scala 20140715Scala 20140715
Scala 20140715
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 

Kürzlich hochgeladen

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
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 FresherRemote DBA Services
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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, Adobeapidays
 
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 Takeoffsammart93
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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.pdfsudhanshuwaghmare1
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Kürzlich hochgeladen (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
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
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
+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...
 
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
 
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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

Introduction to Scala

  • 1. JDevDay - Introduction to Scala Saleem Ansari 10th March 2013 Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 1 / 35
  • 2. Outline 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 2 / 35
  • 3. Topic 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 3 / 35
  • 4. What is Scala? What is Scala? The name Scala stands for scalable language. The language is so named because it was designed to grow with the demands of its users. What makes Scala a Scalable Language ? Statically typed language with OOP + FP both. Fast and expressive, and peasant to use. Excellent type inference. Runs on JVM. Whats more? Scala is compatible with Java Scala is concise Scala is high level Scala is statically typed ( vs dynamically typed ) Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 4 / 35
  • 5. What can you do with Scala today? Write web applications Play Web Framework http://www.playframework.com/ Lift Web Framework http://liftweb.net/ Write code that scales to huge amounts of data Spark Project http://spark-project.org/ Scalding https://github.com/twitter/scalding Process huge number of concurrent tasks Akka http://akka.io/ Natural Language Processing and Machine Learning ScalaNLP http://www.scalanlp.org/ And anything could do in Java, now more concisely :-) Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 5 / 35
  • 6. Topic 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 6 / 35
  • 7. Install the Scala Complier yum install scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 7 / 35
  • 8. Install your faviourite Editor / IDE yum install emacs OR install Eclipse ( ScalaIDE ) Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 8 / 35
  • 9. Scala compiler is scalac ( just like javac command ) scala ( just like java command ) fsc ( fast scala compiler ) Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 9 / 35
  • 10. Topic 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 10 / 35
  • 11. Hello Scala World helloworld.scala object HelloWorld { def main(args: Array[String]) = { println(Hello Scala World!) } } Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 11 / 35
  • 12. Compile and run Hello Scala World Output $ scalac helloworld.scala $ ls helloworld.scala HelloWorld.class HelloWorld$.class $ scala HelloWorld Hello Scala World! Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 12 / 35
  • 13. Values and Variables An example in Ruby ( or maybe Python ) a dynamically typed language counter = Counter.new counter = AtomicCounter.new counter = File.new # this works here! Scala's static type system, avoids runtime overhead of dynamic types. The method dispatch is fast in a statically typed language. var counter = new Counter() counter = new AtomicCounter() // this has to be a Counter counter = new File() // this doesn't work in Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 13 / 35
  • 14. Data Types Almost everything is same as Java Basic Data Types: ( all integers are signed two's complement ) Integers:Byte (8bit), Short (16bit), Int (32bit), Long (64bit) Char (16 bit unicode character), String (squence of Chars) Reals: Float (32bit), Double (64bit) Boolean: true / false Literal basic data types i.e. 1, 0.123, 12L, `a', String symbol literal: `identier Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 14 / 35
  • 15. More Concepts Data Containers Array List Set Map Tuple Programming Abstraction Tools Class Object Scala App Package Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 15 / 35
  • 16. Expressions Every thing is an expression Basic expression: 1+2 An assignment is an expression A function is an expression Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 16 / 35
  • 17. Control Constructs if-else while do-while for match-case try-catch-nally Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 17 / 35
  • 18. Topic 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 18 / 35
  • 19. Matematical Logic Lambda Calculus ( see Wikipedia ) Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 19 / 35
  • 20. Factorial Function Expressed as mathematical logic Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 20 / 35
  • 21. FP is guided by two main ideas: Functions arest-class values Functions have no side eects i.e. they can be replaced with their values Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 21 / 35
  • 22. Hallmarks of Functional Programming mapping ltering folding reducing Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 22 / 35
  • 23. Topic 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 23 / 35
  • 24. Object Oriented Decompose the problem into entities and interactions among entities Each entity and their interaction is represented using class/object internal state is the member variables interactions are the member functions Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 24 / 35
  • 25. Functions factorial.scala def factorial(n:Int): Int = if(n=0) 1 else n*factorial(n-1) Placeholder syntax Partially applied functions Closures Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 25 / 35
  • 26. Traits traits.scala trait PartTime { // trait definition } Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 26 / 35
  • 27. Classes classes.scala class Employee(name: String, age: Int) { override def toString = name + , + age } class Supervisor(name: String, age: Int ) extends Employee(name, age) with PartTime { override def toString = name + , + age } Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 27 / 35
  • 28. Objects objects.scala object Employee { override def toString = name + , + age } Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 28 / 35
  • 29. Packages package-example.scala package in.tuxdna.scala class Employee(name: String, age: Int) { override def toString = name + , + age } object Main extends App { val emp1 = new Employee(Tom, 21) println(Employee 1: +emp1) } // $ scalac pacakge-example.scala // Employee 1: Tom, 21 Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 29 / 35
  • 30. Features to be convered later XML Processing Actors Case Classes Properties Extistential Types Implicits Lazy Evaluation Parser Combinations Monads Annotations Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 30 / 35
  • 31. Using Scala as a scripting language scala scriptname.scala employee.scala class Employee(name: String, age: Int) { override def toString = name + , + age } val emp1 = new Employee(Tom, 21) println(Employee 1: +emp1) // $ scala employee.scala // Employee 1: Tom, 21 Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 31 / 35
  • 32. Topic 1 Introduction to Scala 2 Setting up Scala 3 Absolute Scala basics 4 Functional Paradigm in Scala 5 Object Oriented Programming in Scala 6 Where to learn more Scala Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 32 / 35
  • 33. Books Scala for the Impatient (free) http://blog.typesafe.com/free- pdf-from-typesafe-scala-for-the-impatien-64715 Programming Scala (free) http://ofps.oreilly.com/titles/9780596155957 Programming in Scala 2nd Ed. http://www.amazon.com/Programming-Scala-Comprehensive- Step-Step/dp/0981531644 Functional Programming Principles in Scala ( free online course ) https://www.coursera.org/course/progfun Blogs Forums Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 33 / 35
  • 34. Questions? tuxdna (at) gmail (dot) com Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 34 / 35
  • 35. Thank you! twitter.com/tuxdna Saleem Ansari () JDevDay - Introduction to Scala 10th March 2013 35 / 35