SlideShare a Scribd company logo
1 of 32
Download to read offline
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 1 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
ENGLISHMAN IN NEWENGLISHMAN IN NEW
YORKYORK
Scala for Java Developer => Personal Experience
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 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 Development
JEEconf , speaker
UA Web Challenge , , , judge
Java Stage Producer
Skype: anton.naumow
2011 2012
I II III IV
HotCode
anton.naumow@gmail.com
@antonnaumov
ua.linkedin.com/in/antonnaumov/
http://corwin.calepin.co
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 3 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
WHY SCALA?WHY SCALA?
Buzz word?
Modern technology
Respect
New knowledge and new challenge
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 4 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
GETTING STARTEDGETTING STARTED
object HelloWorld {
def main(args: Array[String]) {
println("Hello world!")
}
}
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 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)
}
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 6 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
GETTING STARTEDGETTING STARTED
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 7 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
TRY ONCE MORETRY ONCE MORE
Daniel Spiewak "Scala for Java Refugees"
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 8 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
LIGHT SIDELIGHT SIDE
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 9 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
OPTIONOPTION
I think its no NullPointerExceptions anymore
...
Option(getBar("foo"))
def bar(index: java.lang.Integer): Option[Int] = {
Option(index) match {
case value: Some => value
case None => None
}
}
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 10 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
TUPPLETUPPLE
Up to 22 arguments. No stupid classes. No arrays.
No guessing.
...
def bar(pattern: String):(Int, String) = (pattern.length, pattern)
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 11 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
MATCHMATCH
It's something like switch... but much better
...
(number, string) match {
case (1, "test") => ...
case (_, "another test") => ...
case _ => ...
}
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 12 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
COLLECTIONSCOLLECTIONS
Some 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) => item
case None => ...
}
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 13 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
EXCEPTION HANDLINGEXCEPTION HANDLING
Something like Java 1.9
...
try {
//some code throws exceptions
catch {
case e: IllegalAccessException => ...
case e: Exception => ...
}
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 14 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
TRAITTRAIT
No comments
trait 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 Third
obj.out("HeLlO TrAiTs!")
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 15 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
MULTITHREADINGMULTITHREADING
Simple. More simple. The simplest
Iterable[String] seq = Seq("one", "two", "three")
seq.par.map { str => str.toUpperCase() }
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 16 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
XMLXML
Like a charm
val 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
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 17 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
DARK SIDEDARK SIDE
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 18 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
COMPILATION TIMECOMPILATION TIME
Scala code compiles about 30% longer than Java code
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 19 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
CODE READABILITYCODE READABILITY
Somekind like this still mess a point
def 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 -> value
case key :: Nil => key -> null
}
}).toMap
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 20 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
OPERATOR OVERRIDING, IMPLICITOPERATOR OVERRIDING, IMPLICIT
Not obvious language constructions always MAY produce a
mess
And always will produce a mess
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 21 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
NO BACKWARD COMPATIBILITYNO BACKWARD COMPATIBILITY
Scala 2.9 code produce an runtime exception running with
Scala 2.10
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 22 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
DIAMOND PROBLEMDIAMOND PROBLEM
Multiple inheritance solution is architecture bomb
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 23 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
TOP 3 SCALA FEATURESTOP 3 SCALA FEATURES
Something not obvious but very useful
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 24 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
MODELMODEL
class 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;
}
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 25 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
COLLECTION FILTERINGCOLLECTION FILTERING
JAVAJAVA
...
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;
}
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 26 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
COLLECTION FILTERINGCOLLECTION FILTERING
SCALASCALA
...
def sumFeesByType(fees: util.Collection[Fee], feeType: String) fees
.filter(_.getType.eqaualsIgnoreCase(feeType)
.foldLeft(0L)(_ + _.getAmount)
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 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)
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 28 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
VALUE CONVERSIONVALUE CONVERSION
JAVAJAVA
public 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);
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 29 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
VALUE CONVERSIONVALUE CONVERSION
SCALA :: IMPLICIT + OBJECTSCALA :: IMPLICIT + OBJECT
class FeeExtension(fee: Fee) {
def amount: Long = Option(fee.getAmount) match {
case Some(value) => value
case None => 0L
}
}
object FeeExtension {
implicit def extendsFee(fee: Fee) = new FeeExtension(fee)
}
...
import FeeExtension._
...
val amount = fee.amount
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 30 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
VALUE CONVERSIONVALUE CONVERSION
SCALA ::: PACKAGE OBJECTSCALA ::: PACKAGE OBJECT
package com.github.sample;
package object sample {
def amount(fee: Fee) = Option(fee) match {
case Some(value) => value
case None => 0L
}
...
package com.github.sample;
...
val amount = fee.amount
...
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 31 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
RESUMERESUME
Scala or Not Scala?
5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer
Page 32 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/
THANK YOU!THANK YOU!

More Related Content

Viewers also liked (7)

Actividades TIC
Actividades TICActividades TIC
Actividades TIC
 
Dev-Time Liferay
Dev-Time  LiferayDev-Time  Liferay
Dev-Time Liferay
 
Pres 21 05-13
Pres 21 05-13Pres 21 05-13
Pres 21 05-13
 
adiccion face
adiccion faceadiccion face
adiccion face
 
Caracteristicas de metabolitos secundarios
Caracteristicas de metabolitos secundariosCaracteristicas de metabolitos secundarios
Caracteristicas de metabolitos secundarios
 
Tarea. unidad 2
Tarea. unidad 2Tarea. unidad 2
Tarea. unidad 2
 
Use maven in_right_way
Use maven in_right_wayUse maven in_right_way
Use maven in_right_way
 

Similar to Englishman in new york => scala for java developer

Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im ÜberblickNext Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Benjamin Schmid
 
Decorating code (Research Paper)
Decorating code (Research Paper)Decorating code (Research Paper)
Decorating code (Research Paper)
Jenna Pederson
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
Hazelcast
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924
yohanbeschi
 

Similar to Englishman in new york => scala for java developer (20)

JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVMJavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
JavaOne 2017: Eclipse OpenJ9: Under the hood of the JVM
 
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17Enhancing Productivity and Insight  A Tour of JDK Tools Progress Beyond Java 17
Enhancing Productivity and Insight A Tour of JDK Tools Progress Beyond Java 17
 
Embrace the JVM
Embrace the JVMEmbrace the JVM
Embrace the JVM
 
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
Highlights from Java 10, 11 and 12 and Future of Java at Javaland 2019 By Vad...
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im ÜberblickNext Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
Next Generation Java - Ceylon, Kotlin, Scala & Fantom im Überblick
 
Decorating code (Research Paper)
Decorating code (Research Paper)Decorating code (Research Paper)
Decorating code (Research Paper)
 
Java 8 Lambda
Java 8 LambdaJava 8 Lambda
Java 8 Lambda
 
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018Adopting GraalVM - Scale by the Bay 2018
Adopting GraalVM - Scale by the Bay 2018
 
Unit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptxUnit No. 1 Introduction to Java.pptx
Unit No. 1 Introduction to Java.pptx
 
XML-Free Programming : Java Server and Client Development without &lt;>
XML-Free Programming : Java Server and Client Development without &lt;>XML-Free Programming : Java Server and Client Development without &lt;>
XML-Free Programming : Java Server and Client Development without &lt;>
 
JavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and FutureJavaScript Modules Past, Present and Future
JavaScript Modules Past, Present and Future
 
Expressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In JavaExpressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In Java
 
State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to come
 
Angular JS in 2017
Angular JS in 2017Angular JS in 2017
Angular JS in 2017
 
In Vogue Dynamic
In Vogue DynamicIn Vogue Dynamic
In Vogue Dynamic
 
Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924Introduction to the Java bytecode - So@t - 20130924
Introduction to the Java bytecode - So@t - 20130924
 
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworksConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
ConSol_IBM_webcast_quarkus_the_blue_hedgehog_of_java_web_frameworks
 

Recently uploaded

Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
Overkill Security
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
The Ultimate Prompt Engineering Guide for Generative AI: Get the Most Out of ...
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
ChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps ProductivityChatGPT and Beyond - Elevating DevOps Productivity
ChatGPT and Beyond - Elevating DevOps Productivity
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 

Englishman in new york => scala for java developer

  • 1. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 1 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ ENGLISHMAN IN NEWENGLISHMAN IN NEW YORKYORK Scala for Java Developer => Personal Experience
  • 2. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 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 Development JEEconf , speaker UA Web Challenge , , , judge Java Stage Producer Skype: anton.naumow 2011 2012 I II III IV HotCode anton.naumow@gmail.com @antonnaumov ua.linkedin.com/in/antonnaumov/ http://corwin.calepin.co
  • 3. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 3 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ WHY SCALA?WHY SCALA? Buzz word? Modern technology Respect New knowledge and new challenge
  • 4. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 4 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ GETTING STARTEDGETTING STARTED object HelloWorld { def main(args: Array[String]) { println("Hello world!") } }
  • 5. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 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 Developer Page 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 Developer Page 7 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ TRY ONCE MORETRY ONCE MORE Daniel Spiewak "Scala for Java Refugees"
  • 8. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 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 Developer Page 9 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ OPTIONOPTION I think its no NullPointerExceptions anymore ... Option(getBar("foo")) def bar(index: java.lang.Integer): Option[Int] = { Option(index) match { case value: Some => value case None => None } } ...
  • 10. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 10 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ TUPPLETUPPLE Up 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 Developer Page 11 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ MATCHMATCH It's 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 Developer Page 12 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ COLLECTIONSCOLLECTIONS Some 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) => item case None => ... } ...
  • 13. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 13 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ EXCEPTION HANDLINGEXCEPTION HANDLING Something like Java 1.9 ... try { //some code throws exceptions catch { case e: IllegalAccessException => ... case e: Exception => ... } ...
  • 14. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 14 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ TRAITTRAIT No comments trait 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 Third obj.out("HeLlO TrAiTs!")
  • 15. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 15 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ MULTITHREADINGMULTITHREADING Simple. More simple. The simplest Iterable[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 Developer Page 16 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ XMLXML Like a charm val 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 Developer Page 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 Developer Page 18 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ COMPILATION TIMECOMPILATION TIME Scala code compiles about 30% longer than Java code
  • 19. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 19 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ CODE READABILITYCODE READABILITY Somekind like this still mess a point def 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 -> value case key :: Nil => key -> null } }).toMap
  • 20. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 20 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ OPERATOR OVERRIDING, IMPLICITOPERATOR OVERRIDING, IMPLICIT Not obvious language constructions always MAY produce a mess And always will produce a mess
  • 21. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 21 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ NO BACKWARD COMPATIBILITYNO BACKWARD COMPATIBILITY Scala 2.9 code produce an runtime exception running with Scala 2.10
  • 22. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 22 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ DIAMOND PROBLEMDIAMOND PROBLEM Multiple inheritance solution is architecture bomb
  • 23. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 23 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ TOP 3 SCALA FEATURESTOP 3 SCALA FEATURES Something not obvious but very useful
  • 24. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 24 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ MODELMODEL class 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 Developer Page 25 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ COLLECTION FILTERINGCOLLECTION FILTERING JAVAJAVA ... 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 Developer Page 26 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ COLLECTION FILTERINGCOLLECTION FILTERING SCALASCALA ... 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 Developer Page 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 Developer Page 28 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ VALUE CONVERSIONVALUE CONVERSION JAVAJAVA public 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 Developer Page 29 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ VALUE CONVERSIONVALUE CONVERSION SCALA :: IMPLICIT + OBJECTSCALA :: IMPLICIT + OBJECT class FeeExtension(fee: Fee) { def amount: Long = Option(fee.getAmount) match { case Some(value) => value case 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 Developer Page 30 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ VALUE CONVERSIONVALUE CONVERSION SCALA ::: PACKAGE OBJECTSCALA ::: PACKAGE OBJECT package com.github.sample; package object sample { def amount(fee: Fee) = Option(fee) match { case Some(value) => value case None => 0L } ... package com.github.sample; ... val amount = fee.amount ...
  • 31. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 31 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ RESUMERESUME Scala or Not Scala?
  • 32. 5/18/13 5:22 PMEnglishman in New York - Scala for Java Developer Page 32 of 32file:///Users/Corwin/Developer/Projects/Personal/slides/englishman-in-new-york/index.html?print-pdf#/ THANK YOU!THANK YOU!