Recap of day 1
VariablesScala:                       Java:val s = “Hello World”        public final String s = “Hello World”;var i = 1   ...
MethodsScala:                             Java:def add(x: Int, y: Int): Int = {   public int add(int x, int y) {    x+y   ...
Classes and constructorsScala:                           Java:class Person(val name: String)   public class Person {      ...
TuplesScala:                             Java:val tuple: Tuple2[Int, String] =   Pair<Integer, String> tuple = new        ...
The Option typeval someOption: Option[String] = Some("value")val noOption:   Option[String] = None
First class funtionsval numbers = List(1, 2, 3, 4, 5)numbers.filter(i => i > 2)          // List(3, 4, 5)
Closuresval people = List(Person(“Alf”), Person(“Fredrik”))val name = “Fredrik”people.filter(_.name == name) // Person(“Fr...
Pattern matchingval myObject = ...val res = myObject match {  case i: Int if i == 1 => "Found an int which is 1"  case s: ...
Traitstrait Ordered[A] {  def compare(that: A): Int    def   <    (that:   A):   Boolean   =   (this   compare   that)   <...
Todays scheduleHigher order functionsImplicit conversionsXML supportTask: The Quiz game
Upcoming SlideShare
Loading in...5
×

2.1 recap from-day_one

612

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
612
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "2.1 recap from-day_one"

  1. 1. Recap of day 1
  2. 2. VariablesScala: Java:val s = “Hello World” public final String s = “Hello World”;var i = 1 public int i = 1;
  3. 3. MethodsScala: Java:def add(x: Int, y: Int): Int = { public int add(int x, int y) { x+y return x + y;} }def add(x: Int, y: Int) = x + ydef doSomething(text: String) { public void doSometing(String text) {} }
  4. 4. Classes and constructorsScala: Java:class Person(val name: String) public class Person { private final String name; public Person(String name) { this.name = name; } public String getName() { return name; } }
  5. 5. TuplesScala: Java:val tuple: Tuple2[Int, String] = Pair<Integer, String> tuple = new Pair<Integer, String>(1, “apple”) (1, “apple”)val quadruple = ... yeah right... ;-) (2, “orange”, 0.5d, false)
  6. 6. The Option typeval someOption: Option[String] = Some("value")val noOption: Option[String] = None
  7. 7. First class funtionsval numbers = List(1, 2, 3, 4, 5)numbers.filter(i => i > 2) // List(3, 4, 5)
  8. 8. Closuresval people = List(Person(“Alf”), Person(“Fredrik”))val name = “Fredrik”people.filter(_.name == name) // Person(“Fredrik”)
  9. 9. Pattern matchingval myObject = ...val res = myObject match { case i: Int if i == 1 => "Found an int which is 1" case s: String => "Found a String" case other => error("Unknown " + other)}
  10. 10. Traitstrait 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 scheduleHigher order functionsImplicit conversionsXML supportTask: The Quiz game
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×