SlideShare une entreprise Scribd logo
1  sur  28
packagenl.devnology.workshop importjava.util._ classLearnALanguage(today: Calendar) extendsDevnology{  defwelcome(participants: List[Participant]) { participants.foreach(p => println("welcome" + p))   }   def facilitators() = {   Facilitator("SoemirnoKartosoewito")  ::    Facilitator("Jan Willem Tulp") :: Nil   } }
What’s the plan? Setup development environment (Eclipse + Scalaplugin) Form pair-programming pairs Explanation of basic concepts and syntax Labs, labs, labs... ... and of course: share knowledge!
Euh...Scala? Scala runs on JVM and .Net VM integrates 100% with existing libraries hybrid language: both functional and OO statically typed “everything is an object” ...Immutability, Currying, Tuples, Closures, Higher Order Functions, etc....
Scala in the enterprise
Run Scala as... Interactive / REPL (Read Eval Print Loop): the scala command starts an interactive shell As script Compiled: scalac command compiles Scala code See: http://www.scala-lang.org/node/166
Variables, Values & Type Inference varmsg = "welcome to ..." // msg is mutable msg += " Devnology"  msg = 3 // compiler error
Variables, Values & Type Inference valmsg = "welcome to ..." // msg is immutable msg += " Devnology" // compiler error val n : Int = 3 // explicit type declaration valname : String = "John"
Functions def min(x: Int, y: Int) = if (x < y) x else y // equivalent: def invert(x: Int) = -x // last statement is return value def invert(x: Int) : Int = { return –x } Unit can be considered as java’s void Watch out! def invert(x: Int) { // will return Unit, = is absent   -x }
Every operation is a function call 1 + 2    is the same as1.+(2) “to” is not a keyword:  for (i <- 0 to 10) print(i) map containsKey ‘a’   is the same as      map.containsKey(‘a’)
Lists valscores = List(1, 2, 3) // immutable valextraScores: List[Int] = 4 :: 5 :: 6 :: Nil // allScores = List(1, 2, 3, 4, 5, 6) // scores = List(1, 2, 3) // extraScores = List(4, 5, 6) valallScores = scores ::: extraScores valevenMoreScores = 7 :: allScores Nil is synonym for empty list
Foreach valscores = List(1, 2, 3) // equivalent scores.foreach((n: Int) => println(n)) scores.foreach(n => println(n)) scores.foreach(println)
For comprehensions valscores = List(1, 2, 3) for (s <- scores) println(s) for (s <- scores if s > 1) println(s)
Arrays valnames = Array("John", "Jane") names(0) = "Richard" // Arrays are mutable val cities = new Array[String](2) cities(0) = "Amsterdam" cities(1) = "Rotterdam" for (i <- 0 to 1) println(cities(i))
Maps valtowns = Map("John" -> "Amsterdam", "Jane" -> "Rotterdam") // default immutable Map var a = towns("John") // returns "Amsterdam" a = towns get "John”// returns Some(Amsterdam) a = towns get "John"get // returns "Amsterdam" var r = towns("Bill") // throws NoSuchElementException r = towns get "Bill”// returns None towns.update("John", "Delft") // returns a new Map
Classes & Constructors class Person(name: String, age: Int) { if (age < 0) thrownewIllegalArgumentException defsayHello() { println("Hello, " + name) } } class Person(name: String, age: Int) { require (age >= 0) defsayHello() { println("Hello, " + name) } }
Classes & Constructors class Person(name: String, age: Int) { def this(name: String) = this(name, 21) // auxiliary def this(age: Int) = this(“John”, age) // auxiliary def this() = this(“John”, 21) // auxiliary }
Classes & Constructors class Person(name: String, age: Int) ... val p = new Person("John", 33) val a = p.age// compiler error p.name = "Richard" // compiler error class Person(var name: String, val age: Int)
Companion Objects // must be declared in same file as Person class object Person { defprintName = println("John") } valp = Person // Singleton is also an object Person.printName// similar to static methods in Java/C#
Traits trait Student { varage = 10;   def greet() = { "Hello teacher!"   }   def study(): String // abstract method }
Extending Traits class FirstGrader extends Student {   override def greet() = { "Hello amazing teacher!"   }   override def study(): String = { “I am studying really hard!"   } }
Trait Mixin // compiler error: abstract function study from trait Student is not implemented valjohn = new Person with Student traitSimpleStudent { def greet() = "Hello amazing teacher!" } // this is ok val john = new Person withSimpleStudent println(john.greet())
Scala Application object Person   def main(args: Array[String]) { // define a main method     for (arg <- args) println("Hello " + arg)   } } // or extend Application trait object Person extends Application {    for (name <- List("John", "Jane"))  println("Hello " + name) }
Pattern Matching valcolor = if (args.length > 0) args(0) else "" valfruit match { case"red"=>"apple" case"orange" =>"orange" case"yellow" =>"banana" case_ => "yuk!" }
Case Classes case class Var(name: String) extendsExpr val v = Var("sum") adds a Factory method with the name of the class all parameters implicitly get a val prefix, so they are maintained as fields “natural” implementation of toString, hashCode and equals big advantage: support pattern matching
Exceptions try { args(0).toFloat } catch {   case ex: NumberFormatException => println("Oops!") }
Tuples valpair = ("John", 28) // Tuple2[String, Int] println(pair._1) println(pair._2) def divProd(x: Int, y:Int) = (x / y, x * y) valdp = divProd(10, 2) println(pair._1) // 5 println(pair._2) // 20
LABS!! Resources: http://www.scala-lang.org/api http://scala-tools.org/scaladocs/scala-library/2.7.1/ http://www.codecommit.com/blog/scala/roundup-scala-for-java-refugees http://blogs.sun.com/sundararajan/entry/scala_for_java_programmers
THANK YOU!

Contenu connexe

Tendances

Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyAnonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyHipot Studio
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in ScalaShai Yallin
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & ArraysHenry Osborne
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaPeter Maas
 
Scala for ruby programmers
Scala for ruby programmersScala for ruby programmers
Scala for ruby programmerstymon Tobolski
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Bozhidar Boshnakov
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type ClassesJohn De Goes
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...anshkhurana01
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class PatternsJohn De Goes
 
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 jvmIsaias Barroso
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...Rodolfo Carvalho
 
Being functional in PHP
Being functional in PHPBeing functional in PHP
Being functional in PHPDavid de Boer
 

Tendances (20)

Scala Intro
Scala IntroScala Intro
Scala Intro
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’PhinneyAnonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
Anonymous Functions in PHP 5.3 - Matthew Weier O’Phinney
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
PHP Functions & Arrays
PHP Functions & ArraysPHP Functions & Arrays
PHP Functions & Arrays
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
Scala for ruby programmers
Scala for ruby programmersScala for ruby programmers
Scala for ruby programmers
 
Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)Object-Oriented Programming with PHP (part 1)
Object-Oriented Programming with PHP (part 1)
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
 
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
Php mysql classes in navi-mumbai,php-mysql course provider-in-navi-mumbai,bes...
 
First-Class Patterns
First-Class PatternsFirst-Class Patterns
First-Class Patterns
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Introduction in php part 2
Introduction in php part 2Introduction in php part 2
Introduction in php part 2
 
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
 
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
O CPAN tem as ferramentas que você precisa para fazer TDD em Perl, o Coding D...
 
Sorting arrays in PHP
Sorting arrays in PHPSorting arrays in PHP
Sorting arrays in PHP
 
Being functional in PHP
Being functional in PHPBeing functional in PHP
Being functional in PHP
 
Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 

En vedette

Cercapaz compendio de_oientaciones para la paz
Cercapaz compendio de_oientaciones para la pazCercapaz compendio de_oientaciones para la paz
Cercapaz compendio de_oientaciones para la pazErick Bravo
 
Great marketing can save the world
Great marketing can save the worldGreat marketing can save the world
Great marketing can save the worldIan Lurie
 
(a hopefully fairly painless introduction to) Linked Open Data
(a hopefully fairly painless introduction to) Linked Open Data(a hopefully fairly painless introduction to) Linked Open Data
(a hopefully fairly painless introduction to) Linked Open DataTim Sherratt
 
Onderzoek onderpresteren 'motiveren leidt tot beter presteren'
Onderzoek onderpresteren 'motiveren leidt tot beter presteren'Onderzoek onderpresteren 'motiveren leidt tot beter presteren'
Onderzoek onderpresteren 'motiveren leidt tot beter presteren'Ingrid Dirksen
 
Eindverslag stage Wellness Center Maassluis
Eindverslag stage Wellness Center MaassluisEindverslag stage Wellness Center Maassluis
Eindverslag stage Wellness Center MaassluisLars Bergwerff
 

En vedette (6)

Cercapaz compendio de_oientaciones para la paz
Cercapaz compendio de_oientaciones para la pazCercapaz compendio de_oientaciones para la paz
Cercapaz compendio de_oientaciones para la paz
 
Handboek KVO
Handboek KVOHandboek KVO
Handboek KVO
 
Great marketing can save the world
Great marketing can save the worldGreat marketing can save the world
Great marketing can save the world
 
(a hopefully fairly painless introduction to) Linked Open Data
(a hopefully fairly painless introduction to) Linked Open Data(a hopefully fairly painless introduction to) Linked Open Data
(a hopefully fairly painless introduction to) Linked Open Data
 
Onderzoek onderpresteren 'motiveren leidt tot beter presteren'
Onderzoek onderpresteren 'motiveren leidt tot beter presteren'Onderzoek onderpresteren 'motiveren leidt tot beter presteren'
Onderzoek onderpresteren 'motiveren leidt tot beter presteren'
 
Eindverslag stage Wellness Center Maassluis
Eindverslag stage Wellness Center MaassluisEindverslag stage Wellness Center Maassluis
Eindverslag stage Wellness Center Maassluis
 

Similaire à Learn Scala in a Day with Devnology Workshop

Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In ScalaSkills Matter
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fuclimatewarrior
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
Scala Quick Introduction
Scala Quick IntroductionScala Quick Introduction
Scala Quick IntroductionDamian Jureczko
 
Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaAyush Mishra
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 

Similaire à Learn Scala in a Day with Devnology Workshop (20)

Scala introduction
Scala introductionScala introduction
Scala introduction
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Python quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung FuPython quickstart for programmers: Python Kung Fu
Python quickstart for programmers: Python Kung Fu
 
Scala 2 + 2 > 4
Scala 2 + 2 > 4Scala 2 + 2 > 4
Scala 2 + 2 > 4
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Scala Quick Introduction
Scala Quick IntroductionScala Quick Introduction
Scala Quick Introduction
 
Knolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in ScalaKnolx Session : Built-In Control Structures in Scala
Knolx Session : Built-In Control Structures in Scala
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 

Dernier

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 

Dernier (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 

Learn Scala in a Day with Devnology Workshop

  • 1. packagenl.devnology.workshop importjava.util._ classLearnALanguage(today: Calendar) extendsDevnology{ defwelcome(participants: List[Participant]) { participants.foreach(p => println("welcome" + p)) } def facilitators() = { Facilitator("SoemirnoKartosoewito") :: Facilitator("Jan Willem Tulp") :: Nil } }
  • 2. What’s the plan? Setup development environment (Eclipse + Scalaplugin) Form pair-programming pairs Explanation of basic concepts and syntax Labs, labs, labs... ... and of course: share knowledge!
  • 3. Euh...Scala? Scala runs on JVM and .Net VM integrates 100% with existing libraries hybrid language: both functional and OO statically typed “everything is an object” ...Immutability, Currying, Tuples, Closures, Higher Order Functions, etc....
  • 4. Scala in the enterprise
  • 5. Run Scala as... Interactive / REPL (Read Eval Print Loop): the scala command starts an interactive shell As script Compiled: scalac command compiles Scala code See: http://www.scala-lang.org/node/166
  • 6. Variables, Values & Type Inference varmsg = "welcome to ..." // msg is mutable msg += " Devnology" msg = 3 // compiler error
  • 7. Variables, Values & Type Inference valmsg = "welcome to ..." // msg is immutable msg += " Devnology" // compiler error val n : Int = 3 // explicit type declaration valname : String = "John"
  • 8. Functions def min(x: Int, y: Int) = if (x < y) x else y // equivalent: def invert(x: Int) = -x // last statement is return value def invert(x: Int) : Int = { return –x } Unit can be considered as java’s void Watch out! def invert(x: Int) { // will return Unit, = is absent -x }
  • 9. Every operation is a function call 1 + 2 is the same as1.+(2) “to” is not a keyword: for (i <- 0 to 10) print(i) map containsKey ‘a’ is the same as map.containsKey(‘a’)
  • 10. Lists valscores = List(1, 2, 3) // immutable valextraScores: List[Int] = 4 :: 5 :: 6 :: Nil // allScores = List(1, 2, 3, 4, 5, 6) // scores = List(1, 2, 3) // extraScores = List(4, 5, 6) valallScores = scores ::: extraScores valevenMoreScores = 7 :: allScores Nil is synonym for empty list
  • 11. Foreach valscores = List(1, 2, 3) // equivalent scores.foreach((n: Int) => println(n)) scores.foreach(n => println(n)) scores.foreach(println)
  • 12. For comprehensions valscores = List(1, 2, 3) for (s <- scores) println(s) for (s <- scores if s > 1) println(s)
  • 13. Arrays valnames = Array("John", "Jane") names(0) = "Richard" // Arrays are mutable val cities = new Array[String](2) cities(0) = "Amsterdam" cities(1) = "Rotterdam" for (i <- 0 to 1) println(cities(i))
  • 14. Maps valtowns = Map("John" -> "Amsterdam", "Jane" -> "Rotterdam") // default immutable Map var a = towns("John") // returns "Amsterdam" a = towns get "John”// returns Some(Amsterdam) a = towns get "John"get // returns "Amsterdam" var r = towns("Bill") // throws NoSuchElementException r = towns get "Bill”// returns None towns.update("John", "Delft") // returns a new Map
  • 15. Classes & Constructors class Person(name: String, age: Int) { if (age < 0) thrownewIllegalArgumentException defsayHello() { println("Hello, " + name) } } class Person(name: String, age: Int) { require (age >= 0) defsayHello() { println("Hello, " + name) } }
  • 16. Classes & Constructors class Person(name: String, age: Int) { def this(name: String) = this(name, 21) // auxiliary def this(age: Int) = this(“John”, age) // auxiliary def this() = this(“John”, 21) // auxiliary }
  • 17. Classes & Constructors class Person(name: String, age: Int) ... val p = new Person("John", 33) val a = p.age// compiler error p.name = "Richard" // compiler error class Person(var name: String, val age: Int)
  • 18. Companion Objects // must be declared in same file as Person class object Person { defprintName = println("John") } valp = Person // Singleton is also an object Person.printName// similar to static methods in Java/C#
  • 19. Traits trait Student { varage = 10; def greet() = { "Hello teacher!" } def study(): String // abstract method }
  • 20. Extending Traits class FirstGrader extends Student { override def greet() = { "Hello amazing teacher!" } override def study(): String = { “I am studying really hard!" } }
  • 21. Trait Mixin // compiler error: abstract function study from trait Student is not implemented valjohn = new Person with Student traitSimpleStudent { def greet() = "Hello amazing teacher!" } // this is ok val john = new Person withSimpleStudent println(john.greet())
  • 22. Scala Application object Person def main(args: Array[String]) { // define a main method for (arg <- args) println("Hello " + arg) } } // or extend Application trait object Person extends Application { for (name <- List("John", "Jane")) println("Hello " + name) }
  • 23. Pattern Matching valcolor = if (args.length > 0) args(0) else "" valfruit match { case"red"=>"apple" case"orange" =>"orange" case"yellow" =>"banana" case_ => "yuk!" }
  • 24. Case Classes case class Var(name: String) extendsExpr val v = Var("sum") adds a Factory method with the name of the class all parameters implicitly get a val prefix, so they are maintained as fields “natural” implementation of toString, hashCode and equals big advantage: support pattern matching
  • 25. Exceptions try { args(0).toFloat } catch { case ex: NumberFormatException => println("Oops!") }
  • 26. Tuples valpair = ("John", 28) // Tuple2[String, Int] println(pair._1) println(pair._2) def divProd(x: Int, y:Int) = (x / y, x * y) valdp = divProd(10, 2) println(pair._1) // 5 println(pair._2) // 20
  • 27. LABS!! Resources: http://www.scala-lang.org/api http://scala-tools.org/scaladocs/scala-library/2.7.1/ http://www.codecommit.com/blog/scala/roundup-scala-for-java-refugees http://blogs.sun.com/sundararajan/entry/scala_for_java_programmers