SlideShare a Scribd company logo
1 of 33
Liftweb Łukasz Kuczera
Scala the next Java ? Łukasz Kuczera
Scala Statically typed with types inferention Object-functional Compiles to Java bytecode And CLI .Net
Historia Pizza GJ EPFL
Pizza
Scala Type Inference Uniform Access Principle Closures Higher Order Functions Pattern Matching Actors Generics Native XML support Abstract control structures Implicit conversions and parameters Advanced for expressions Annotations Combinator parsing Traits Duck typing Null „safety”
„If I where to choose language other than Java it would be  Scala”
„I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created  Groovy”
„Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable”
Scala - Basics class Test { // variable definition var n = 5 // value definition val i = 10 // function definition def printit(x: Any) = println(x) def sum(i: Int, n: Int) = i+n } object Test extends Test { def main(args: Array[String]): Unit = {   	printit(sum(i,n))   } }
Class Parameters - Java publicclass Person { 	private String name; 	privateintage; publicPerson(String name, int age) { 		this.name = name; 		this.age = age; 	} 	public String getName() { 		returnname; 	} 	publicvoid setName(String name) { 		this.name = name; 	} 	publicint getAge() { 		returnage; 	} 	publicvoid setAge(int age) { 		this.age = age; 	} }
Class Parameters - Scala classPerson(var name: String, var age: Int)
Working with arrays Java publicclass Partition { Person[] all; Person[] adults; Person[] minors; 	 {  ArrayList<Person> minorsList = new ArrayList<Person>(); ArrayList<Person> adultsList = new ArrayList<Person>(); for(int i=0; i<all.length; i++ ) { 	(all[i].age<18 ? adultsList: minorsList).add(all[i]); 	 	} 		minors = (Person[]) minorsList.toArray(); 		adults = (Person[]) adultsList.toArray(); } }
Working with arrays Scala val all: Array[Person] val (minors, adults) = all.partition(_.age<18)
Null’s – Java Map<String, String> capitals =  newHashMap<String, String>(); capitals.put("Poland", "Warsaw"); System.out.println(capitals.get("Polska").trim()); Exception in thread "main" java.lang.NullPointerException
Null’s - Scala   val capitals = Map("Poland" -> "Warsaw"); val capitalOption: Option[String] = capitals.get("Polska")   capitalOption match { case Some(value) => println(value) case None => println("Not found") case _ =>   } if(capitalOption.isDefined) println(capitalOption.get)   println(capitalOption getOrElse "Not found")
XML val xml = <a href="http://example.com"> 		    <customTagb="foo"> 		       <deepTagb="bar" /> Custom content   		    </customTag> 	       </a> println(xml "customTag") println(xml  "deepTag") println(xml  "@b") println(xml "customTag" "deepTag" "@b") Outputs: <customTag b="foo"><deepTag b="bar"></deepTag>Custom content</customTag> <deepTag b="bar"></deepTag> foobar bar
XML val xml =<divclass="rsswidget"> <ul> <liclass="rsswidgettitle"><ahref="http://www.quotationspage.com/qotd.html">Quotes of the Day</a></li> <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/C._P._Snow">C. P. Snow</a></li> <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/unknown">unknown</a></li> <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/Frederick">Frederick</a></li> </ul> ... </div> (xml  "@href").slice(1,4).foreach(url =>      println("URL:"+url) val con = new URL(url.toString).openConnection val reader = newBufferedReader(newInputStreamReader(con.getInputStream, "ISO-8859-1")) var line = ""; while(line != null) {       line = reader.readLine if(line != null) println(line)     }     con.getInputStream.close )
Actors Easier concurrency Message passing instead of locks Asynchronus Implemented using Java threads ScalaActors, Akka, Lift - CometActor
Actors class ActorUser { def send(msg: Any) = ScalaActor ! msg } object ScalaActor extends Actor { 	/* The $actor's mailbox. */ // private[actors] val mailbox = new MQueue[Msg]("Reactor") 	def act() { 		receive { 		    case"ping!" => println("pinged!"); case ("ping!", actor: Actor) => actor ! "pong!" 		    case msg => println("unhandled message type:"+msg) 		} 	} }
Guice Minimize mutability Avoid static state @Nullable JSR 308 - @NonNull
Lift Chat Application Using Comet
Build Tools SBT  Maven Gradle JRebel
IDE	 IntelliJ IDEA Netbeans Eclipse
HTTP GET
Ajax
Comet
Links http://days2010.scala-lang.org/node/136 - lots of Scala videos http://twit.tv/floss125 - Lifts Creator interview http://www.youtube.com/watch?v=01rXrI6xelE – Scala creator speak at Google tech talks
Thank You Q&A

More Related Content

What's hot

JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJosé Paumard
 
Spring has got me under it’s SpEL
Spring has got me under it’s SpELSpring has got me under it’s SpEL
Spring has got me under it’s SpELEldad Dor
 
Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Groupbaroquebobcat
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...Fwdays
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Anton Arhipov
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoMuhammad Abdullah
 
A Scala Corrections Library
A Scala Corrections LibraryA Scala Corrections Library
A Scala Corrections LibraryPaul Phillips
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracerrahulrevo
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScriptSimon Willison
 

What's hot (20)

JDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easyJDK8 : parallel programming made (too ?) easy
JDK8 : parallel programming made (too ?) easy
 
Spring has got me under it’s SpEL
Spring has got me under it’s SpELSpring has got me under it’s SpEL
Spring has got me under it’s SpEL
 
Mirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby GroupMirah Talk for Boulder Ruby Group
Mirah Talk for Boulder Ruby Group
 
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur..."How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
"How was it to switch from beautiful Perl to horrible JavaScript", Viktor Tur...
 
Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012Mastering Java Bytecode With ASM - 33rd degree, 2012
Mastering Java Bytecode With ASM - 33rd degree, 2012
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
All about scala
All about scalaAll about scala
All about scala
 
Introduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demoIntroduction to kotlin + spring boot demo
Introduction to kotlin + spring boot demo
 
A Scala Corrections Library
A Scala Corrections LibraryA Scala Corrections Library
A Scala Corrections Library
 
jQuery introduction
jQuery introductionjQuery introduction
jQuery introduction
 
Mastering Java ByteCode
Mastering Java ByteCodeMastering Java ByteCode
Mastering Java ByteCode
 
Building a java tracer
Building a java tracerBuilding a java tracer
Building a java tracer
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
A Re-Introduction to JavaScript
A Re-Introduction to JavaScriptA Re-Introduction to JavaScript
A Re-Introduction to JavaScript
 
Google Guava
Google GuavaGoogle Guava
Google Guava
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
Scala on Android
Scala on AndroidScala on Android
Scala on Android
 

Viewers also liked

The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)Peter Eisentraut
 
Around "Hello World" in 30 Days
Around "Hello World" in 30 DaysAround "Hello World" in 30 Days
Around "Hello World" in 30 DaysDavid Eisinger
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scalafanf42
 
Liftweb
LiftwebLiftweb
LiftwebScalac
 
Testing practicies not only in scala
Testing practicies not only in scalaTesting practicies not only in scala
Testing practicies not only in scalaPaweł Panasewicz
 
MySQL Monitoring Shoot Out
MySQL Monitoring Shoot OutMySQL Monitoring Shoot Out
MySQL Monitoring Shoot OutKris Buytaert
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?Alex Payne
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkRahul Jain
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 

Viewers also liked (17)

The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)The Common Debian Build System (CDBS)
The Common Debian Build System (CDBS)
 
Around "Hello World" in 30 Days
Around "Hello World" in 30 DaysAround "Hello World" in 30 Days
Around "Hello World" in 30 Days
 
Java to scala
Java to scalaJava to scala
Java to scala
 
A Tour Of Scala
A Tour Of ScalaA Tour Of Scala
A Tour Of Scala
 
Scala Sjug 09
Scala Sjug 09Scala Sjug 09
Scala Sjug 09
 
Liftweb
LiftwebLiftweb
Liftweb
 
Testing practicies not only in scala
Testing practicies not only in scalaTesting practicies not only in scala
Testing practicies not only in scala
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
MySQL Monitoring Shoot Out
MySQL Monitoring Shoot OutMySQL Monitoring Shoot Out
MySQL Monitoring Shoot Out
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
MySQL DBA
MySQL DBAMySQL DBA
MySQL DBA
 
Scala
ScalaScala
Scala
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Scala Days NYC 2016
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache Spark
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 

Similar to Scala the Next Java - Concise Introduction to Scala Language Basics

Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaMichael Stal
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. ExperienceMike Fogus
 
Scala for the doubters. Максим Клыга
Scala for the doubters. Максим КлыгаScala for the doubters. Максим Клыга
Scala for the doubters. Максим КлыгаAlina Dolgikh
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalMichael Stal
 
Live coding scala 'the java of the future'
Live coding scala 'the java of the future'Live coding scala 'the java of the future'
Live coding scala 'the java of the future'Xebia Nederland BV
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaDerek Chen-Becker
 
Jugar Introduccion a Scala
Jugar Introduccion a ScalaJugar Introduccion a Scala
Jugar Introduccion a ScalaSocialmetrix
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009Michael Neale
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In ScalaSkills Matter
 
Functional Java 8 - Introduction
Functional Java 8 - IntroductionFunctional Java 8 - Introduction
Functional Java 8 - IntroductionŁukasz Biały
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013slandelle
 

Similar to Scala the Next Java - Concise Introduction to Scala Language Basics (20)

Scala
ScalaScala
Scala
 
Why Scala?
Why Scala?Why Scala?
Why Scala?
 
Qcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scalaQcon2011 functions rockpresentation_scala
Qcon2011 functions rockpresentation_scala
 
Scala
ScalaScala
Scala
 
Naïveté vs. Experience
Naïveté vs. ExperienceNaïveté vs. Experience
Naïveté vs. Experience
 
Scala for the doubters. Максим Клыга
Scala for the doubters. Максим КлыгаScala for the doubters. Максим Клыга
Scala for the doubters. Максим Клыга
 
Scala in Places API
Scala in Places APIScala in Places API
Scala in Places API
 
Oop2010 Scala Presentation Stal
Oop2010 Scala Presentation StalOop2010 Scala Presentation Stal
Oop2010 Scala Presentation Stal
 
Live coding scala 'the java of the future'
Live coding scala 'the java of the future'Live coding scala 'the java of the future'
Live coding scala 'the java of the future'
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
Jugar Introduccion a Scala
Jugar Introduccion a ScalaJugar Introduccion a Scala
Jugar Introduccion a Scala
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009On Scala Slides - OSDC 2009
On Scala Slides - OSDC 2009
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Rewriting Java In Scala
Rewriting Java In ScalaRewriting Java In Scala
Rewriting Java In Scala
 
Functional Java 8 - Introduction
Functional Java 8 - IntroductionFunctional Java 8 - Introduction
Functional Java 8 - Introduction
 
Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013Gatling @ Scala.Io 2013
Gatling @ Scala.Io 2013
 

More from Scalac

Applicative functors by Łukasz Marchewka
Applicative functors by Łukasz MarchewkaApplicative functors by Łukasz Marchewka
Applicative functors by Łukasz MarchewkaScalac
 
AWS Api Gateway by Łukasz Marchewka Scalacc
AWS Api Gateway by Łukasz Marchewka ScalaccAWS Api Gateway by Łukasz Marchewka Scalacc
AWS Api Gateway by Łukasz Marchewka ScalaccScalac
 
Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...
Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...
Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...Scalac
 
React Hooks by Oleksandr Oleksiv Scalac
React Hooks by Oleksandr Oleksiv ScalacReact Hooks by Oleksandr Oleksiv Scalac
React Hooks by Oleksandr Oleksiv ScalacScalac
 
Introduction to Scala by Piotr Wiśniowski Scalac
Introduction to Scala by Piotr Wiśniowski ScalacIntroduction to Scala by Piotr Wiśniowski Scalac
Introduction to Scala by Piotr Wiśniowski ScalacScalac
 
ZIO actors by Mateusz Sokół Scalac
ZIO actors by Mateusz Sokół ScalacZIO actors by Mateusz Sokół Scalac
ZIO actors by Mateusz Sokół ScalacScalac
 
Why functional programming and category theory strongly matters - Piotr Parad...
Why functional programming and category theory strongly matters - Piotr Parad...Why functional programming and category theory strongly matters - Piotr Parad...
Why functional programming and category theory strongly matters - Piotr Parad...Scalac
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Scalac
 
How to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski ScalacHow to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski ScalacScalac
 
Do you have that Spark in your ECTL? by Piotr Sych Scalac
Do you have that Spark in your ECTL? by Piotr Sych ScalacDo you have that Spark in your ECTL? by Piotr Sych Scalac
Do you have that Spark in your ECTL? by Piotr Sych ScalacScalac
 
Can we automate the process of backlog prioritizing? by Adam Gadomski Scalac
Can we automate the process of backlog prioritizing? by Adam Gadomski ScalacCan we automate the process of backlog prioritizing? by Adam Gadomski Scalac
Can we automate the process of backlog prioritizing? by Adam Gadomski ScalacScalac
 
How to create the right sales funnel for your business? by Maciej Greń
How to create the right sales funnel for your business? by Maciej GreńHow to create the right sales funnel for your business? by Maciej Greń
How to create the right sales funnel for your business? by Maciej GreńScalac
 
ActorRef[Typed] by Andrzej Kopeć
ActorRef[Typed] by Andrzej KopećActorRef[Typed] by Andrzej Kopeć
ActorRef[Typed] by Andrzej KopećScalac
 

More from Scalac (13)

Applicative functors by Łukasz Marchewka
Applicative functors by Łukasz MarchewkaApplicative functors by Łukasz Marchewka
Applicative functors by Łukasz Marchewka
 
AWS Api Gateway by Łukasz Marchewka Scalacc
AWS Api Gateway by Łukasz Marchewka ScalaccAWS Api Gateway by Łukasz Marchewka Scalacc
AWS Api Gateway by Łukasz Marchewka Scalacc
 
Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...
Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...
Do ECTL not ETL: the art and science of data cleansing in data pipelines by P...
 
React Hooks by Oleksandr Oleksiv Scalac
React Hooks by Oleksandr Oleksiv ScalacReact Hooks by Oleksandr Oleksiv Scalac
React Hooks by Oleksandr Oleksiv Scalac
 
Introduction to Scala by Piotr Wiśniowski Scalac
Introduction to Scala by Piotr Wiśniowski ScalacIntroduction to Scala by Piotr Wiśniowski Scalac
Introduction to Scala by Piotr Wiśniowski Scalac
 
ZIO actors by Mateusz Sokół Scalac
ZIO actors by Mateusz Sokół ScalacZIO actors by Mateusz Sokół Scalac
ZIO actors by Mateusz Sokół Scalac
 
Why functional programming and category theory strongly matters - Piotr Parad...
Why functional programming and category theory strongly matters - Piotr Parad...Why functional programming and category theory strongly matters - Piotr Parad...
Why functional programming and category theory strongly matters - Piotr Parad...
 
Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...Big picture of category theory in scala with deep dive into contravariant and...
Big picture of category theory in scala with deep dive into contravariant and...
 
How to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski ScalacHow to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
How to write automated tests and don’t lose your mind by Dorian Sarnowski Scalac
 
Do you have that Spark in your ECTL? by Piotr Sych Scalac
Do you have that Spark in your ECTL? by Piotr Sych ScalacDo you have that Spark in your ECTL? by Piotr Sych Scalac
Do you have that Spark in your ECTL? by Piotr Sych Scalac
 
Can we automate the process of backlog prioritizing? by Adam Gadomski Scalac
Can we automate the process of backlog prioritizing? by Adam Gadomski ScalacCan we automate the process of backlog prioritizing? by Adam Gadomski Scalac
Can we automate the process of backlog prioritizing? by Adam Gadomski Scalac
 
How to create the right sales funnel for your business? by Maciej Greń
How to create the right sales funnel for your business? by Maciej GreńHow to create the right sales funnel for your business? by Maciej Greń
How to create the right sales funnel for your business? by Maciej Greń
 
ActorRef[Typed] by Andrzej Kopeć
ActorRef[Typed] by Andrzej KopećActorRef[Typed] by Andrzej Kopeć
ActorRef[Typed] by Andrzej Kopeć
 

Scala the Next Java - Concise Introduction to Scala Language Basics

  • 2. Scala the next Java ? Łukasz Kuczera
  • 3. Scala Statically typed with types inferention Object-functional Compiles to Java bytecode And CLI .Net
  • 6.
  • 7.
  • 8. Scala Type Inference Uniform Access Principle Closures Higher Order Functions Pattern Matching Actors Generics Native XML support Abstract control structures Implicit conversions and parameters Advanced for expressions Annotations Combinator parsing Traits Duck typing Null „safety”
  • 9. „If I where to choose language other than Java it would be Scala”
  • 10. „I can honestly say if someone had shown me the Programming in Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy”
  • 11. „Scala, it must be stated, is the current heir apparent to the Java throne. No other language on the JVM seems as capable of being a "replacement for Java" as Scala, and the momentum behind Scala is now unquestionable”
  • 12.
  • 13. Scala - Basics class Test { // variable definition var n = 5 // value definition val i = 10 // function definition def printit(x: Any) = println(x) def sum(i: Int, n: Int) = i+n } object Test extends Test { def main(args: Array[String]): Unit = { printit(sum(i,n)) } }
  • 14. Class Parameters - Java publicclass Person { private String name; privateintage; publicPerson(String name, int age) { this.name = name; this.age = age; } public String getName() { returnname; } publicvoid setName(String name) { this.name = name; } publicint getAge() { returnage; } publicvoid setAge(int age) { this.age = age; } }
  • 15. Class Parameters - Scala classPerson(var name: String, var age: Int)
  • 16. Working with arrays Java publicclass Partition { Person[] all; Person[] adults; Person[] minors; { ArrayList<Person> minorsList = new ArrayList<Person>(); ArrayList<Person> adultsList = new ArrayList<Person>(); for(int i=0; i<all.length; i++ ) { (all[i].age<18 ? adultsList: minorsList).add(all[i]); } minors = (Person[]) minorsList.toArray(); adults = (Person[]) adultsList.toArray(); } }
  • 17. Working with arrays Scala val all: Array[Person] val (minors, adults) = all.partition(_.age<18)
  • 18. Null’s – Java Map<String, String> capitals = newHashMap<String, String>(); capitals.put("Poland", "Warsaw"); System.out.println(capitals.get("Polska").trim()); Exception in thread "main" java.lang.NullPointerException
  • 19. Null’s - Scala val capitals = Map("Poland" -> "Warsaw"); val capitalOption: Option[String] = capitals.get("Polska") capitalOption match { case Some(value) => println(value) case None => println("Not found") case _ => } if(capitalOption.isDefined) println(capitalOption.get) println(capitalOption getOrElse "Not found")
  • 20. XML val xml = <a href="http://example.com"> <customTagb="foo"> <deepTagb="bar" /> Custom content </customTag> </a> println(xml "customTag") println(xml "deepTag") println(xml "@b") println(xml "customTag" "deepTag" "@b") Outputs: <customTag b="foo"><deepTag b="bar"></deepTag>Custom content</customTag> <deepTag b="bar"></deepTag> foobar bar
  • 21. XML val xml =<divclass="rsswidget"> <ul> <liclass="rsswidgettitle"><ahref="http://www.quotationspage.com/qotd.html">Quotes of the Day</a></li> <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/C._P._Snow">C. P. Snow</a></li> <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/unknown">unknown</a></li> <liclass="rsswidgetitem"><ahref="http://www.quotationspage.com/quotes/Frederick">Frederick</a></li> </ul> ... </div> (xml "@href").slice(1,4).foreach(url => println("URL:"+url) val con = new URL(url.toString).openConnection val reader = newBufferedReader(newInputStreamReader(con.getInputStream, "ISO-8859-1")) var line = ""; while(line != null) { line = reader.readLine if(line != null) println(line) } con.getInputStream.close )
  • 22. Actors Easier concurrency Message passing instead of locks Asynchronus Implemented using Java threads ScalaActors, Akka, Lift - CometActor
  • 23. Actors class ActorUser { def send(msg: Any) = ScalaActor ! msg } object ScalaActor extends Actor { /* The $actor's mailbox. */ // private[actors] val mailbox = new MQueue[Msg]("Reactor") def act() { receive { case"ping!" => println("pinged!"); case ("ping!", actor: Actor) => actor ! "pong!" case msg => println("unhandled message type:"+msg) } } }
  • 24. Guice Minimize mutability Avoid static state @Nullable JSR 308 - @NonNull
  • 25. Lift Chat Application Using Comet
  • 26. Build Tools SBT Maven Gradle JRebel
  • 27. IDE IntelliJ IDEA Netbeans Eclipse
  • 29. Ajax
  • 30. Comet
  • 31.
  • 32. Links http://days2010.scala-lang.org/node/136 - lots of Scala videos http://twit.tv/floss125 - Lifts Creator interview http://www.youtube.com/watch?v=01rXrI6xelE – Scala creator speak at Google tech talks