Your SlideShare is downloading. ×
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
Englishman in new york =>  scala for java developer
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

Englishman in new york => scala for java developer

404

Published on

How to Java developer could start with Scala quick and easy and why the developer will love Scala

How to Java developer could start with Scala quick and easy and why the developer will love Scala

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

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

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 1 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ENGLISHMAN IN NEWENGLISHMAN IN NEWYORKYORKScala for Java Developer => Personal Experience
  • 2. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 2 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/WHO IS THIS GUY?WHO IS THIS GUY?12+ yeas in Java DevelopmentJEEconf , speakerUA Web Challenge , , , judgeJava Stage ProducerSkype: anton.naumow2011 2012I II III IVHotCodeanton.naumow@gmail.com@antonnaumovua.linkedin.com/in/antonnaumov/http://corwin.calepin.co
  • 3. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 3 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/WHY SCALA?WHY SCALA?Buzz word?Modern technologyRespectNew knowledge and new challenge
  • 4. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 4 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/GETTING STARTEDGETTING STARTEDobject HelloWorld {def main(args: Array[String]) {println("Hello world!")}}
  • 5. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 5 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/GETTING STARTEDGETTING STARTED...def sum(bars: Iterable[Bar]): Long = {bars.filter(_.type == SOME).foldLeft(0L)(_ + _.amount)}...
  • 6. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 6 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/GETTING STARTEDGETTING STARTED
  • 7. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 7 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/TRY ONCE MORETRY ONCE MOREDaniel Spiewak "Scala for Java Refugees"
  • 8. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 8 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/LIGHT SIDELIGHT SIDE
  • 9. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 9 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/OPTIONOPTIONI think its no NullPointerExceptions anymore...Option(getBar("foo"))def bar(index: java.lang.Integer): Option[Int] = {Option(index) match {case value: Some => valuecase None => None}}...
  • 10. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 10 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/TUPPLETUPPLEUp to 22 arguments. No stupid classes. No arrays.No guessing....def bar(pattern: String):(Int, String) = (pattern.length, pattern)...
  • 11. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 11 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/MATCHMATCHIts something like switch... but much better...(number, string) match {case (1, "test") => ...case (_, "another test") => ...case _ => ...}...
  • 12. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 12 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/COLLECTIONSCOLLECTIONSSome magic happens here...final Collection<Integer> coll = Lists.newArrayList(1, 2, 3, 4, 5);...for (final int item : coll) {if (item == 5) {return item;}}return -1;......val coll = Seq(1, 2, 3, 4, 5)...coll.find(_ == 5) match {case Some(item) => itemcase None => ...}...
  • 13. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 13 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/EXCEPTION HANDLINGEXCEPTION HANDLINGSomething like Java 1.9...try {//some code throws exceptionscatch {case e: IllegalAccessException => ...case e: Exception => ...}...
  • 14. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 14 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/TRAITTRAITNo commentstrait First {def convert(input: String): String}trait Second {def out(input: String) => System.out.println(bar(input))}class Third extends First with Second {override def convert(input: String): String => input.toLowerCase()}...val obj = new Thirdobj.out("HeLlO TrAiTs!")
  • 15. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 15 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/MULTITHREADINGMULTITHREADINGSimple. More simple. The simplestIterable[String] seq = Seq("one", "two", "three")seq.par.map { str => str.toUpperCase() }
  • 16. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 16 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/XMLXMLLike a charmval xml =<root><node name="first">Some text</node><node name="second">Some other text</node></root>...val source = XML.load(IOUtils.toInputStream(xml)(source "node" "@name").text match {case "first" => "First node found"case _ => (source "node").text...
  • 17. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 17 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/DARK SIDEDARK SIDE
  • 18. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 18 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/COMPILATION TIMECOMPILATION TIMEScala code compiles about 30% longer than Java code
  • 19. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 19 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/CODE READABILITYCODE READABILITYSomekind like this still mess a pointdef parseResponse(response: String): Map[String, String] = {(for (param <- response.split("&");trimmed = URLDecoder.decode(param.trim, "UTF-8");if (!trimmed.isEmpty) yield {(trimmed.split("=", 2).toList: @unchecked) match {case key :: value :: Nil => key -> valuecase key :: Nil => key -> null}}).toMap
  • 20. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 20 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/OPERATOR OVERRIDING, IMPLICITOPERATOR OVERRIDING, IMPLICITNot obvious language constructions always MAY produce amessAnd always will produce a mess
  • 21. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 21 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/NO BACKWARD COMPATIBILITYNO BACKWARD COMPATIBILITYScala 2.9 code produce an runtime exception running withScala 2.10
  • 22. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 22 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/DIAMOND PROBLEMDIAMOND PROBLEMMultiple inheritance solution is architecture bomb
  • 23. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 23 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/TOP 3 SCALA FEATURESTOP 3 SCALA FEATURESSomething not obvious but very useful
  • 24. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 24 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/MODELMODELclass Fee {public Long getAmount() { return amount; }public void setAmount(final Long amount) { this.amount = amount; }public String getType() { return type; }public void setType(final String type) { this.type = type; }private Long amount;private String type;}
  • 25. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 25 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/COLLECTION FILTERINGCOLLECTION FILTERINGJAVAJAVA...public long sumFeesByType(final Collection<Fee> fees,final String type) {long sum = 0;for (final Fee fee : fees) {if (fee != null && fee.getType().equalsIgnoreCase(type)) {sum += fee.getAmount() == null ? 0L :fee.getAmount()}}return sum;}...
  • 26. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 26 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/COLLECTION FILTERINGCOLLECTION FILTERINGSCALASCALA...def sumFeesByType(fees: util.Collection[Fee], feeType: String) fees.filter(_.getType.eqaualsIgnoreCase(feeType).foldLeft(0L)(_ + _.getAmount)...
  • 27. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 27 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/OPTION AS COLLECTIONOPTION AS COLLECTION...val amount = fees.find(_.getType.equalsIgnoreCase("PROMO")).map(_.getAmount).getOrElse(0L)...
  • 28. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 28 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/VALUE CONVERSIONVALUE CONVERSIONJAVAJAVApublic final class FeeExtension {private FeeExtension() {}public static long getFeeAmount(fee: Fee) {return fee.getAmount() == null ? 0L : fee.getAmount();}}...import FeeExtension.*...final long amount = getFeeAmount(fee);...
  • 29. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 29 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/VALUE CONVERSIONVALUE CONVERSIONSCALA :: IMPLICIT + OBJECTSCALA :: IMPLICIT + OBJECTclass FeeExtension(fee: Fee) {def amount: Long = Option(fee.getAmount) match {case Some(value) => valuecase None => 0L}}object FeeExtension {implicit def extendsFee(fee: Fee) = new FeeExtension(fee)}...import FeeExtension._...val amount = fee.amount...
  • 30. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 30 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/VALUE CONVERSIONVALUE CONVERSIONSCALA ::: PACKAGE OBJECTSCALA ::: PACKAGE OBJECTpackage com.github.sample;package object sample {def amount(fee: Fee) = Option(fee) match {case Some(value) => valuecase None => 0L}...package com.github.sample;...val amount = fee.amount...
  • 31. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 31 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/RESUMERESUMEScala or Not Scala?
  • 32. 5/18/13 5:22 PMEnglishman in New York - Scala for Java DeveloperPage 32 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/THANK YOU!THANK YOU!

×