SlideShare una empresa de Scribd logo
1 de 38
Intro to Scala
What is Scala? ,[object Object],[object Object],[object Object]
OO Features
Classes ,[object Object],Default Constructor
Objects ,[object Object],[object Object],[object Object]
Standalone Object Calling the method
Companion Object ,[object Object],[object Object]
Methods Don’t need a return statement.  The last line of the method is  What gets returned.
Imports & Packages Import Statements Scoped Packages
Type System
Type System ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Type System ,[object Object],[object Object],[object Object],[object Object],[object Object]
Type System
Type System Call drawAll on Canvas with a list of circles
Type System ,[object Object],[object Object],Immutable Mutable
Implicits
Implicit Conversion Implicit Conversions provide a nice way to extend libraries and functionality without  changing the original code. Example: Add methods to String
Implicit Conversion Must Import the Object in order to use the  new methods It looks like we are calling the repeat method on the string class!
Implicit Parameters Implicit parameters are used in a functions parameter list to denote that the parameter Is optional.  Declare the parameter to be implicit Label the list as implicit so the compiler knows Which list to use.
Traits
Traits Like an interface with an implementation.  Traits are mixed into classes by using  the keyword  with.  Allowed to have abstract as well as concrete implementation of methods. Version 1
Traits Version 2
Traits It is possible to have multiple traits that have the same method.  This is known  as stackable modifications  By extending Arithmetic we are saying that this is only valid for classes that extend Arithmetic Calls the next compute method in line A hint to the compiler that you are “stacking” traits
Traits Output: 8 Output: 16
Traits If you remember from the last example the result between the two runs were different.  This is because we changed the order of the traits between the two executions.  Ordering of traits makes a difference!  By using something called linearization classes and all of the traits are put into a linear order (right to left).  By putting them in this order, each time you call  super   the next method up the chain is invoked.  2 + 2 = 4 4 * 4 = 16 2  * 2 = 4 4 + 4 = 8
Functional Features
Immutability ,[object Object],[object Object],[object Object],[object Object],[object Object]
Concurrency ,[object Object],[object Object],[object Object]
Concurrency Event Based Actors In event based actors a thread pool is used and each actor is given a thread to  execute.
Concurrency Thread Based Actors With thread based actors, every actor is tied to a thread.
Concurrency Starting an actor and sending a message:
Pattern Matching ,[object Object],[object Object],[object Object],[object Object],[object Object]
Pattern Matching Basic Example: Matching a String or Int Output: “Look a String!” Output: “Look an Int!” Simple instanceof check
Pattern matching Implementing the visitor pattern:
Functions
Functions Partial Function: Passing a function as a parameter: Returning a function from a method:
Other Notable Features
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Más contenido relacionado

La actualidad más candente

Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1Berk Soysal
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialKuntal Bhowmick
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner classsimarsimmygrewal
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data typesSasidharaRaoMarrapu
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyaviratandodariya
 
Demystifying Eta Expansion
Demystifying Eta ExpansionDemystifying Eta Expansion
Demystifying Eta ExpansionKnoldus Inc.
 
Presenter deck icenium hol
Presenter deck   icenium holPresenter deck   icenium hol
Presenter deck icenium holDhananjay Kumar
 
Nairobi JVM meetup : Introduction to akka
Nairobi JVM meetup : Introduction to akkaNairobi JVM meetup : Introduction to akka
Nairobi JVM meetup : Introduction to akkaAD_
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1Todor Kolev
 
lazy evaluation
lazy evaluationlazy evaluation
lazy evaluationRajendran
 
Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Jamshid Hashimi
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#Ali Hassan
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21myrajendra
 

La actualidad más candente (20)

Java Tutorial Lab 1
Java Tutorial Lab 1Java Tutorial Lab 1
Java Tutorial Lab 1
 
Command line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorialCommand line-arguments-in-java-tutorial
Command line-arguments-in-java-tutorial
 
Handling inputs via scanner class
Handling inputs via scanner classHandling inputs via scanner class
Handling inputs via scanner class
 
Pj01 3-java-variable and data types
Pj01 3-java-variable and data typesPj01 3-java-variable and data types
Pj01 3-java-variable and data types
 
java in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariyajava in Aartificial intelligent by virat andodariya
java in Aartificial intelligent by virat andodariya
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Demystifying Eta Expansion
Demystifying Eta ExpansionDemystifying Eta Expansion
Demystifying Eta Expansion
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Presenter deck icenium hol
Presenter deck   icenium holPresenter deck   icenium hol
Presenter deck icenium hol
 
Nairobi JVM meetup : Introduction to akka
Nairobi JVM meetup : Introduction to akkaNairobi JVM meetup : Introduction to akka
Nairobi JVM meetup : Introduction to akka
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Java findamentals1
Java findamentals1Java findamentals1
Java findamentals1
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
lazy evaluation
lazy evaluationlazy evaluation
lazy evaluation
 
C#4.0 features
C#4.0 featuresC#4.0 features
C#4.0 features
 
Java 8 stream and c# 3.5
Java 8 stream and c# 3.5Java 8 stream and c# 3.5
Java 8 stream and c# 3.5
 
Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2Week 2: Getting Your Hands Dirty – Part 2
Week 2: Getting Your Hands Dirty – Part 2
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
 
Command line arguments.21
Command line arguments.21Command line arguments.21
Command line arguments.21
 

Similar a Intro To Scala

Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameAntony Stubbs
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfDeeptiMalhotra19
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2Todor Kolev
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2Todor Kolev
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentationVan Huong
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...vekariyakashyap
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxBruceLee275640
 

Similar a Intro To Scala (20)

Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Intro to Scala
 Intro to Scala Intro to Scala
Intro to Scala
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Scala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love GameScala Language Intro - Inspired by the Love Game
Scala Language Intro - Inspired by the Love Game
 
Userdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdfUserdefined functions brief explaination.pdf
Userdefined functions brief explaination.pdf
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
Java findamentals2
Java findamentals2Java findamentals2
Java findamentals2
 
PCSTt11 overview of java
PCSTt11 overview of javaPCSTt11 overview of java
PCSTt11 overview of java
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
 
Md08 collection api
Md08 collection apiMd08 collection api
Md08 collection api
 
M C6java3
M C6java3M C6java3
M C6java3
 
Java
JavaJava
Java
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
 
java150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptxjava150929145120-lva1-app6892 (2).pptx
java150929145120-lva1-app6892 (2).pptx
 
Scala tutorial
Scala tutorialScala tutorial
Scala tutorial
 
Scala tutorial
Scala tutorialScala tutorial
Scala tutorial
 
Java
JavaJava
Java
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
 

Intro To Scala

  • 2.
  • 4.
  • 5.
  • 7.
  • 8. Methods Don’t need a return statement. The last line of the method is What gets returned.
  • 9. Imports & Packages Import Statements Scoped Packages
  • 11.
  • 12.
  • 14. Type System Call drawAll on Canvas with a list of circles
  • 15.
  • 17. Implicit Conversion Implicit Conversions provide a nice way to extend libraries and functionality without changing the original code. Example: Add methods to String
  • 18. Implicit Conversion Must Import the Object in order to use the new methods It looks like we are calling the repeat method on the string class!
  • 19. Implicit Parameters Implicit parameters are used in a functions parameter list to denote that the parameter Is optional. Declare the parameter to be implicit Label the list as implicit so the compiler knows Which list to use.
  • 21. Traits Like an interface with an implementation. Traits are mixed into classes by using the keyword with. Allowed to have abstract as well as concrete implementation of methods. Version 1
  • 23. Traits It is possible to have multiple traits that have the same method. This is known as stackable modifications By extending Arithmetic we are saying that this is only valid for classes that extend Arithmetic Calls the next compute method in line A hint to the compiler that you are “stacking” traits
  • 24. Traits Output: 8 Output: 16
  • 25. Traits If you remember from the last example the result between the two runs were different. This is because we changed the order of the traits between the two executions. Ordering of traits makes a difference! By using something called linearization classes and all of the traits are put into a linear order (right to left).  By putting them in this order, each time you call super  the next method up the chain is invoked. 2 + 2 = 4 4 * 4 = 16 2 * 2 = 4 4 + 4 = 8
  • 27.
  • 28.
  • 29. Concurrency Event Based Actors In event based actors a thread pool is used and each actor is given a thread to execute.
  • 30. Concurrency Thread Based Actors With thread based actors, every actor is tied to a thread.
  • 31. Concurrency Starting an actor and sending a message:
  • 32.
  • 33. Pattern Matching Basic Example: Matching a String or Int Output: “Look a String!” Output: “Look an Int!” Simple instanceof check
  • 34. Pattern matching Implementing the visitor pattern:
  • 36. Functions Partial Function: Passing a function as a parameter: Returning a function from a method:
  • 38.