SlideShare a Scribd company logo
Quick Scala
Overview
• Pure Object oriented: classes and traits for mixins
• Functional: anonymous fns, higher prder fns, nested fns, currying, Functions
are objects
• Static type, Type inference
• Runs on JVM: scalac, scala
• All types are objects
• Domain specific language (DSL) support, Closures, Concurrency support inspired
by Erlang
Basic Syntax
• Object, Class, Methods, Fields, Closure, Traits
• case-sensitive identifiers, Class names first letter upper case, method name first
letter lower case, program file name same as object name,
• legal identifiers: age, salary, _value, __1_value
• illegal identifiers: $salary, 123abc, -salary
• legal operator identifiers: + ++ ::: <?> :>
• legal mixed identifiers: unary_+, myvar_=
• literal identifier, string enclosed in back ticks: `x` `<clinit>` `yield`
• Optional semicolon if only one statement on a line
• Dynamic invocations:
Data types
• Unit: no value, equivalent to void in
Java
• Null: null o empty reference
• Nothing: Subtype of every other type
• Any, AnyVal, AnyRef
Variables
• Type Inference
• var: mutable variable
• val: immutable variable
• Scope
• Fields
• Method Parameters, always immutable
• Local Variables
Classes and Objects
• Keywords: new, extends,
• Implicit classes, always in the object scope
• Singleton Objects, created with object keyword, No parameters in
primary constructor
Access Modifiers
• private
• protected
• public: public keyword not required
• Scope of Protection: private[professional], private[this]
Operators, if-else, Loops
Functions
• Called method when inside class
• Called procedure if no return parameter
• Partial functions
•
Closures
String
• String Interpolation
• literal ‘s’ allows the usage of variable directly in processing a string
• literal ‘f’ interpolator allows to create a formatted String
• ‘raw’ interpolator is similar to ‘s’ interpolator except that it performs no
escaping of literals within a string.
Arrays
• def apply( x: T, xs: T* ): Array[T]
• Creates an array of T objects, where T can be Unit, Double, Float, Long,
Int, Char, Short, Byte, Boolean.
Collections
• Lists, Sets, Maps, Tuples, Options, Iterators
• Collections may be strict or lazy.
Traits
• A trait encapsulates method and field definitions, which can then
be reused by mixing them into classes.
• Value classes and Universal Traits
•
Pattern Matching
• A pattern match includes a sequence of alternatives, each starting
with the keyword case.
Exception Handling
Extractors
• An extractor in Scala is an object that has a method
called unapply as one of its members. The purpose of that
unapply method is to match a value and take it apart.
Why Scala?
• functions are first-class citizens, functional programming
• Futures to manage concurrency
• Tail recursion
• Traits
• Akka framework, Actors, Scala in Apache Spark pipelines, sbt

More Related Content

What's hot

Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
Soba Arjun
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
Vinod Kumar
 
Datatype
DatatypeDatatype
Datatype
baran19901990
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
teach4uin
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
Akhil Kaushik
 
Xtend Programming Language
Xtend Programming LanguageXtend Programming Language
Xtend Programming Language
Mikhail Barash
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
sasi saseenthiran
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
Buddha Tree
 
Primitive data types in java
Primitive data types in javaPrimitive data types in java
Primitive data types in java
Umamaheshwariv1
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
Rajesh Roky
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
Sireesh K
 
Lecture 1 - Objects and classes
Lecture 1 - Objects and classesLecture 1 - Objects and classes
Lecture 1 - Objects and classes
Syed Afaq Shah MACS CP
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
Akshay soni
 
Type Classes
Type ClassesType Classes
Type Classes
Julien Wetterwald
 
Local variables Instance variables Class/static variables
Local variables Instance variables Class/static variablesLocal variables Instance variables Class/static variables
Local variables Instance variables Class/static variables
Sohanur63
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVA
Hamna_sheikh
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmell
hyunglak kim
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
Knoldus Inc.
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
Michael Heron
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
Martin Odersky
 

What's hot (20)

Java basic datatypes
Java basic datatypesJava basic datatypes
Java basic datatypes
 
Static keyword ppt
Static keyword pptStatic keyword ppt
Static keyword ppt
 
Datatype
DatatypeDatatype
Datatype
 
L9 wrapper classes
L9 wrapper classesL9 wrapper classes
L9 wrapper classes
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Xtend Programming Language
Xtend Programming LanguageXtend Programming Language
Xtend Programming Language
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
 
Primitive data types in java
Primitive data types in javaPrimitive data types in java
Primitive data types in java
 
wrapper classes
wrapper classeswrapper classes
wrapper classes
 
5variables in c#
5variables in c#5variables in c#
5variables in c#
 
Lecture 1 - Objects and classes
Lecture 1 - Objects and classesLecture 1 - Objects and classes
Lecture 1 - Objects and classes
 
Wrapper class (130240116056)
Wrapper class (130240116056)Wrapper class (130240116056)
Wrapper class (130240116056)
 
Type Classes
Type ClassesType Classes
Type Classes
 
Local variables Instance variables Class/static variables
Local variables Instance variables Class/static variablesLocal variables Instance variables Class/static variables
Local variables Instance variables Class/static variables
 
Datatype introduction- JAVA
Datatype introduction- JAVADatatype introduction- JAVA
Datatype introduction- JAVA
 
Refactoring bad codesmell
Refactoring bad codesmellRefactoring bad codesmell
Refactoring bad codesmell
 
Shapeless- Generic programming for Scala
Shapeless- Generic programming for ScalaShapeless- Generic programming for Scala
Shapeless- Generic programming for Scala
 
2CPP04 - Objects and Classes
2CPP04 - Objects and Classes2CPP04 - Objects and Classes
2CPP04 - Objects and Classes
 
Simplicitly
SimplicitlySimplicitly
Simplicitly
 

Similar to Quick Scala

Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut
 
Learning core java
Learning core javaLearning core java
Learning core java
Abhay Bharti
 
Net framework
Net frameworkNet framework
Net framework
Abhishek Mukherjee
 
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
 
AP computer barron book ppt AP CS A.pptx
AP computer barron book ppt AP CS A.pptxAP computer barron book ppt AP CS A.pptx
AP computer barron book ppt AP CS A.pptx
KoutheeshSellamuthu
 
chapter 5.ppt
chapter 5.pptchapter 5.ppt
chapter 5.ppt
ThedronBerhanu
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
teach4uin
 
Java
JavaJava
Typescript
TypescriptTypescript
Typescript
Nikhil Thomas
 
NSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftNSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to Swift
Andreas Blick
 
Chapter 4.pptx
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptx
RanjanaShevkar
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
16115yogendraSingh
 
Java session3
Java session3Java session3
Java session3
Jigarthacker
 
Python first day
Python first dayPython first day
Python first day
MARISSTELLA2
 
Python first day
Python first dayPython first day
Python first day
farkhand
 
Data Handling and Function
Data Handling and FunctionData Handling and Function
Data Handling and Function
RatnaJava
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
Garuda Trainings
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Viyaan Jhiingade
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
Vasavi College of Engg
 

Similar to Quick Scala (20)

Programming with Python - Week 3
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Net framework
Net frameworkNet framework
Net framework
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
AP computer barron book ppt AP CS A.pptx
AP computer barron book ppt AP CS A.pptxAP computer barron book ppt AP CS A.pptx
AP computer barron book ppt AP CS A.pptx
 
chapter 5.ppt
chapter 5.pptchapter 5.ppt
chapter 5.ppt
 
L2 datatypes and variables
L2 datatypes and variablesL2 datatypes and variables
L2 datatypes and variables
 
Java
JavaJava
Java
 
Typescript
TypescriptTypescript
Typescript
 
NSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to SwiftNSCoder Swift - An Introduction to Swift
NSCoder Swift - An Introduction to Swift
 
Chapter 4.pptx
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptx
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Java session3
Java session3Java session3
Java session3
 
Python first day
Python first dayPython first day
Python first day
 
Python first day
Python first dayPython first day
Python first day
 
Data Handling and Function
Data Handling and FunctionData Handling and Function
Data Handling and Function
 
Fundamental classes in java
Fundamental classes in javaFundamental classes in java
Fundamental classes in java
 
c++ Unit III - PPT.pptx
c++ Unit III - PPT.pptxc++ Unit III - PPT.pptx
c++ Unit III - PPT.pptx
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Unit 2 Principles of Programming Languages
Unit 2 Principles of Programming LanguagesUnit 2 Principles of Programming Languages
Unit 2 Principles of Programming Languages
 

More from Puneet Kumar

Robotics using EV3 Introduction
Robotics using EV3 Introduction Robotics using EV3 Introduction
Robotics using EV3 Introduction
Puneet Kumar
 
Chess1
Chess1Chess1
Chess1
Puneet Kumar
 
Android accessibility
Android accessibilityAndroid accessibility
Android accessibility
Puneet Kumar
 
Nagios
NagiosNagios
Nagios
Puneet Kumar
 
System adm
System admSystem adm
System adm
Puneet Kumar
 
Yoga
YogaYoga
Gwt
GwtGwt
Redis
RedisRedis
Bitcoin
BitcoinBitcoin
Bitcoin
Puneet Kumar
 
Html5 CSS3
Html5 CSS3Html5 CSS3
Html5 CSS3
Puneet Kumar
 

More from Puneet Kumar (10)

Robotics using EV3 Introduction
Robotics using EV3 Introduction Robotics using EV3 Introduction
Robotics using EV3 Introduction
 
Chess1
Chess1Chess1
Chess1
 
Android accessibility
Android accessibilityAndroid accessibility
Android accessibility
 
Nagios
NagiosNagios
Nagios
 
System adm
System admSystem adm
System adm
 
Yoga
YogaYoga
Yoga
 
Gwt
GwtGwt
Gwt
 
Redis
RedisRedis
Redis
 
Bitcoin
BitcoinBitcoin
Bitcoin
 
Html5 CSS3
Html5 CSS3Html5 CSS3
Html5 CSS3
 

Recently uploaded

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

Quick Scala

  • 2. Overview • Pure Object oriented: classes and traits for mixins • Functional: anonymous fns, higher prder fns, nested fns, currying, Functions are objects • Static type, Type inference • Runs on JVM: scalac, scala • All types are objects • Domain specific language (DSL) support, Closures, Concurrency support inspired by Erlang
  • 3. Basic Syntax • Object, Class, Methods, Fields, Closure, Traits • case-sensitive identifiers, Class names first letter upper case, method name first letter lower case, program file name same as object name, • legal identifiers: age, salary, _value, __1_value • illegal identifiers: $salary, 123abc, -salary • legal operator identifiers: + ++ ::: <?> :> • legal mixed identifiers: unary_+, myvar_= • literal identifier, string enclosed in back ticks: `x` `<clinit>` `yield` • Optional semicolon if only one statement on a line • Dynamic invocations:
  • 4. Data types • Unit: no value, equivalent to void in Java • Null: null o empty reference • Nothing: Subtype of every other type • Any, AnyVal, AnyRef
  • 5. Variables • Type Inference • var: mutable variable • val: immutable variable • Scope • Fields • Method Parameters, always immutable • Local Variables
  • 6. Classes and Objects • Keywords: new, extends, • Implicit classes, always in the object scope • Singleton Objects, created with object keyword, No parameters in primary constructor
  • 7. Access Modifiers • private • protected • public: public keyword not required • Scope of Protection: private[professional], private[this]
  • 9. Functions • Called method when inside class • Called procedure if no return parameter • Partial functions •
  • 11. String • String Interpolation • literal ‘s’ allows the usage of variable directly in processing a string • literal ‘f’ interpolator allows to create a formatted String • ‘raw’ interpolator is similar to ‘s’ interpolator except that it performs no escaping of literals within a string.
  • 12. Arrays • def apply( x: T, xs: T* ): Array[T] • Creates an array of T objects, where T can be Unit, Double, Float, Long, Int, Char, Short, Byte, Boolean.
  • 13. Collections • Lists, Sets, Maps, Tuples, Options, Iterators • Collections may be strict or lazy.
  • 14. Traits • A trait encapsulates method and field definitions, which can then be reused by mixing them into classes. • Value classes and Universal Traits •
  • 15. Pattern Matching • A pattern match includes a sequence of alternatives, each starting with the keyword case.
  • 17. Extractors • An extractor in Scala is an object that has a method called unapply as one of its members. The purpose of that unapply method is to match a value and take it apart.
  • 18. Why Scala? • functions are first-class citizens, functional programming • Futures to manage concurrency • Tail recursion • Traits • Akka framework, Actors, Scala in Apache Spark pipelines, sbt

Editor's Notes

  1. object HelloWorld { /* This is my first java program. */ def main(args: Array[String]) { println("Hello, world!") // prints Hello World } } \> scalac HelloWorld.scala \> scala HelloWorld import scala.xml._ import scala.collection.mutable.HashMap import scala.collection.immutable.{TreeMap, TreeSet}
  2. var myVar : String = "Foo" val (myVar1: Int, myVar2: String) = Pair(40, "Foo")
  3. object <object name> { implicit class <class name>(<Variable>: Data type) { def <method>(): Unit = } } object Run { implicit class IntTimes(x: Int) { def times [A](f: =>A): Unit = { def loop(current: Int): Unit = if(current > 0){ f loop(current - 1) } loop(x) } } }
  4. for ( x <- myList ) { println( x ) }
  5. trait Equal { def isEqual(x: Any): Boolean def isNotEqual(x: Any): Boolean = !isEqual(x) }
  6. def matchTest(x: Int): String = x match { case 1 => "one" case 2 => "two" case _ => "many" }