Your SlideShare is downloading. ×
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Introduction to Scala
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Introduction to Scala


Published on

An introduction to Scala features. See associated code at

An introduction to Scala features. See associated code at

Published in: Business, Technology
1 Comment
  • Get example code at
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. <ul><li>A programming language for the JVM (and .net)
  • 2. Functional / OO hybrid
  • 3. Statically typed
  • 4. Compile to class files
  • 5. Iterpretive Console
  • 6. Flexible syntax </li></ul>What is it?
  • 7. <ul><li>&apos;Scalable Language&apos; </li><ul><li>On the JVM
  • 8. Integrates with existing libraries
  • 9. Integrates readily with other systems (in code XML &amp; JSON support)
  • 10. Flexible syntax – can be like Java or can move to DSLs and higher abstractions. </li></ul></ul>The name
  • 11. <ul><li>Removes Java roadblocks without changing platform or throwing away existing properties </li><ul><li>Tasks that are difficult or tedious in Java can be simplified with minimal investment in time and tools </li></ul><li>Rapid development without losing type safety.
  • 12. Java + new language features: </li><ul><li>Closures, actors, infix operators, case classes, pattern matching, list and map operations, native XML, implicits, defaults, nested elements, no primitives, currying, sequence comprehension, compound types, structural types, function literals … etc </li></ul></ul>Why should we care?
  • 13. <ul><li>Code example - Hello World </li><ul><li>Points of interest: </li><ul><li>Object keyword
  • 14. Def keyword
  • 15. Assignment of code block to function
  • 16. scala.Console
  • 17. Application trait </li></ul></ul></ul>See associated source files at HelloWorld.scala &amp; HelloWorldWithTrait.scala
  • 18. <ul><li>Using the basic building blocks, we can compose code that looks and feels similar to today&apos;s Java. </li><ul><li>Though not source compatible. Can&apos;t compile Java. </li></ul><li>Package, import, class, object, trait, var, val, def
  • 19. Code example: Cat </li><ul><li>Relaxed naming constraints, constructor arg visibility, constructor overload, function definition, implied static typing, val vs var </li></ul></ul>The basic building blocks Cat.scala
  • 20. <ul><li>Can be very terse
  • 21. Return type implies type of function
  • 22. Naming is greatly relaxed.
  • 23. Code sample: Rational </li><ul><li>Symbols as function names -&gt; infix operators, optional &apos;return&apos; keyword, if statements are ternary, DSLs </li></ul></ul>Functions Rational.scala
  • 24. <ul><li>XML is a native datatype
  • 25. Rich XML operations make parsing and creating XML simple.
  • 26. Code sample: NativeXML </li><ul><li>Eclipse plugin slightly broken – parentheses not required, XML direct in code, nested values, iterated lists, xpath-like functions </li></ul></ul>Native XML NativeXML.scala
  • 27. <ul><li>Implicit functions map one type to another
  • 28. Ascribes new functionality to old friends </li><ul><li>e.g. Make the JDBC library user-friendly </li></ul><li>Code sample: UpperCaseAwareString </li><ul><li>RichString already exists
  • 29. Implicit def declaration
  • 30. Multiple impicit defs, but method calls must be unambiguous at compilation </li></ul></ul>Extending other classes – Monkey Patching UpperCaseCharAwareString.scala
  • 31. <ul><li>Compile time checked duck typing
  • 32. Can define types based on functions signatures
  • 33. Code sample: Duck </li><ul><li>Type keyword, multiple method definitions, includes param and return types, can be inlined </li></ul></ul>Structural types – Duck Typing Duck.scala
  • 34. <ul><li>More than interfaces
  • 35. Less than classes
  • 36. Act as markers
  • 37. Can have methods
  • 38. Can have constructors
  • 39. Code sample: Bravia </li><ul><li>Extend abstract or trait, mixins </li></ul></ul>Traits Bravia.scala
  • 40. <ul><li>Define combinations of types in contracts
  • 41. Code sample: Chess </li><ul><li>Compile time type checking for multiple types </li></ul></ul>Compound types chess.Chess.scala
  • 42. <ul><li>Case objects are akin to enums
  • 43. Case classes are parameterisable
  • 44. Pattern Matching is akin to switch statement, but more powerful
  • 45. Code sample: Months </li><ul><li>No new keyword, no params for object - params for class, match &amp; case, _ wildcard, exposed params when matching on classes, also used for exception handling </li></ul></ul>Case objects/classes and pattern matching Months.scala
  • 46. <ul><li>Functions are objects. Everything is!
  • 47. Can access parent scope (closure)
  • 48. Can be defined inline (&apos;function literal&apos;)
  • 49. Code sample: BookReader </li><ul><li>Function as a parameter, function knows and can modify instance values, functions defined inline. </li></ul></ul>Functions are objects too BookReader.scala
  • 50. <ul><li>Any number of enumerations and filters mixed together to form a new list.
  • 51. Enumerations add values, filters remove them.
  • 52. Lightweight notation
  • 53. Code sample: Condiments </li><ul><li>Note generics, note also list creation. </li></ul></ul>Sequence Comprehensions Condiments.scala
  • 54. <ul><li>Functions with many params can be decomposed into a chain of functions.
  • 55. This is supported and used to construct language extensions.
  • 56. Code sample: AutoResourceManagement </li><ul><li>Partial function takes var args of Closable type, chained function takes a function that takes no params and returns nothing (Unit), makes AOP mainly redundant, note foreach and exception syntax. </li></ul></ul>Currying AutoResourceManagement.scala
  • 57. <ul><li> </li><ul><li>Binaries, source, tutorials and doco </li></ul><li>[email_address] - mailing list
  • 58. - Scala Melbourne User Group
  • 59. – Scala for Java devs. </li></ul>Getting started
  • 60. <ul><li>Testing </li><ul><li>
  • 61.
  • 62. </li></ul><li>Building </li><ul><li> </li></ul><li>IDE Support </li><ul><li>Eclipse, NetBeans, IntelliJ </li></ul></ul>Tools