Upcoming SlideShare
×

# 2.1 Recap From Day One

805 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
805
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
5
0
Likes
0
Embeds 0
No embeds

No notes for slide

### 2.1 Recap From Day One

1. 1. Recap of day 1
2. 2. Variables Scala: val s = “Hello World” var i = 1 Java: public final String s = “Hello World”; public int i = 1;
3. 3. Methods Scala: def add(x: Int, y: Int): Int = { x + y } def add(x: Int, y: Int) = x + y def doSomething(text: String) { } Java: public int add(int x, int y) { return x + y; } public void doSometing(String text) { }
4. 4. Classes and constructors Scala: class Person(val name: String) Java: public class Person { private final String name; public Person(String name) { this.name = name; } public String getName() { return name; } }
5. 5. Tuples Scala: val tuple: Tuple2[Int, String] = (1, “apple”) val quadruple = (2, “orange”, 0.5d, false) Java: Pair<Integer, String> tuple = new Pair<Integer, String>(1, “apple”) ... yeah right... ;-)
6. 6. The Option type val someOption : Option [ String ] = Some ( &quot;value&quot; ) val noOption : Option [ String ] = None
7. 7. First class funtions val numbers = List(1, 2, 3, 4, 5) numbers.filter(i => i > 2) // List(3, 4, 5)
8. 8. Closures val people = List(Person(“Alf”), Person(“Fredrik”)) val name = “Fredrik” people.filter(_.name == name ) // Person(“ Fredrik”)
9. 9. val myObject = ... val res = myObject match { case i : Int if i == 1 => &quot;Found an int which is 1&quot; case s : String => &quot;Found a String&quot; case other => error ( &quot;Unknown &quot; + other ) } Pattern matching
10. 10. Traits trait Ordered[A] { def compare(that: A): Int def < (that: A): Boolean = ( this compare that) < 0 def > (that: A): Boolean = ( this compare that) > 0 def <= (that: A): Boolean = ( this compare that) <= 0 def >= (that: A): Boolean = ( this compare that) >= 0 }
11. 11. Todays schedule <ul><li>Higher order functions
12. 12. Implicit conversions
13. 13. XML support
14. 14. Task: The Quiz game </li></ul>