SlideShare a Scribd company logo
How to START using




                     Ngoc Dao
This talk is not about Scala syntax

(You can learn 80% of it in 2 days, Sat & Sun)
Source code:
https://github.com/ngocdaothanh/sclart
Why I use Scala
●   Syntax is similar to Ruby (human oriented)
●   Faster than Ruby (= Java, ~C)
●   Can reuse all Java libs (Java has lots of libs!)
●   Easy to program for multicores (like Erlang)
Agenda
1. “scala” and “scalac” commands
2. SBT (Scala Build Tool)
3. Some useful frameworks
Part 1: scala & scalac
Install Scala
1. Download from scala-lang.org
2. Config PATH
  .bash_profile:
  PATH=~/opt/scala-2.9.2/bin:$PATH
~/opt/scala-2.9.2:
Interactive console
●   For trying out code snippets
●   Like “irb” of Ruby
$ scala
Welcome to Scala version 2.9.2
Type :help for more information.

scala> 1 + 2
res0: Int = 3

scala> "hello".length
res1: Int = 5

scala> :q

$
Scripting Scala
●   Can run a script right away, no compile step is
    needed
●   To run, “scala” command is needed; it will
    compile on the fly then run
●   For simple one-file programs
$ cat Hello1.scala
println(1 + 2)
println("hello".length)

$ scala Hello.scala
3
5
Compile Scala
●   Compile .scala file to .class file
●   Can use “scala” or normal “java” command to
    run .class file
●   Simple programs: scalac (like javac)
●   Bigger programs: SBT (see next slides)
$ scalac Hello1.scala
Hello1.scala:1: error: expected
class or object definition
println(1 + 2)
^
Hello1.scala:2: error: expected
class or object definition
println("hello".length)
^
two errors found


        Need to wrap the script with “main”
$ cat Hello2.scala
object Hello2 {
  // Similar to normal Java/C programs
  def main(args: Array[String]) {
    println(1 + 2)
    println("hello".length)
  }
}
Run with “scala” command

$ scalac Hello2.scala

$ ls
Hello2$.class    Hello2.class Hello2.scala

$ scala Hello2
3
5
Run with “java” command


$ java Hello2
Exception in thread "main"
java.lang.NoClassDefFoundError:
scala/ScalaObject

$ java -cp
~/opt/scala-2.9.2/lib/scala-library.jar:.
Hello2
Part 2: SBT
SBT (Scala Build Tool)
●   Dependency library manager
●   Build tool
●   Like “gem” + “rake” of Ruby
●   Like Maven of Java
Install SBT
There are several ways to install:
https://github.com/harrah/xsbt/wiki/Getting-
Started-Setup


I prefer installing SBT manually
Install SBT manually
~/opt/sbt:




sbt:
java -Xmx512M -XX:MaxPermSize=128M 
-jar `dirname $0`/sbt-launch-0.12.0.jar "$@"

.bash_profile:
PATH=~/opt/sbt:$PATH
Project structure
hello
  build.sbt
  src
    main
      scala
        should_be_under_a_package
          Hello2.scala
      java
        (Java source files, if any)
    test
      (Scala/Java test source files, if any)
      scala
      java
  target
    scala-2.9.2
      classes
        (Compiled .class files)
build.sbt
organization := "com.kayac"

name              := "hello"                           Like Gemfile of Ruby

version           := "1.0-SNAPSHOT"

scalaVersion := "2.9.2"

scalacOptions ++= Seq(                       Packaged .jar file:
  "-deprecation",                      hello_2.9.2-1.0-SNAPSHOT.jar
  "-unchecked"
)




       (Management of dependency libraries will be talked at part 3)
SBT tasks
$ sbt tasks

console         Starts the Scala interpreter

compile         Compiles sources
clean           Deletes files produced by the build
run             Runs a main class

package         Produces project jar file
publish         Publishes project jar file to a repository
publish-local   Copies project jar file to ~/.ivy2

test            Executes all tests
test-only       Executes the tests provided as arguments
test-quick      Executes the tests that either failed before
Demo
●   https://github.com/ngocdaothanh/sclart/tree/master/sbt/hello
●   sbt console, run, package etc.
SBT plugins

https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list

Some useful plugins:

* Create Eclipse project file (with library paths):
https://github.com/typesafehub/sbteclipse

* One jar plugins
Install SBT plugins
1. Install plugins at global level
~/.sbt/plugins/build.sbt

Ex:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")




2. Install plugins at project level
project/plugins.sbt

Ex:
https://github.com/ngocdaothanh/xitrum-demos/blob/master/project/plugins.sbt
Demo
●   Use sbt eclipse to create Eclipse project and
    see lib paths
Part3: Some useful frameworks



https://wiki.scala-lang.org/display/SW/Tools+and+Libraries
Xitrum
 ● Combine web server + web framework
 ● https://github.com/ngocdaothanh/xitrum




+------------------+          Scalable: session, realtime data etc.
|     Your app     |
+------------------+
|      Xitrum      |
|+----------------+|
|| Web framework ||      <-- Hazelcast --> Other instances
||----------------||
|| HTTP(S) Server ||
|+----------------+|
+------------------+

                       Fast static file serving: https://gist.github.com/3293596
                       WebSocket
Demo
●   https://github.com/ngocdaothanh/xitrum-demos
●   Routes
●   WebSocket
●   xitrum-package
Akka
●   http://akka.io/
●   Better than Scala's default actor library
●   Has power of Erlang:
    concurrency
    distribution
    failure supervisor
    FSM (Finite State Machine, very good for
    realtime multiplayer games, to manage states
    of game sessions and inter-player interactions)
FSM Demo




https://github.com/ngocdaothanh/code-lock-fsm-akka

More Related Content

What's hot

Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
Marcus Denker
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
Saai Vignesh P
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
Rob Kinyon
 
Web development basics (Part-6)
Web development basics (Part-6)Web development basics (Part-6)
Web development basics (Part-6)
Rajat Pratap Singh
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
Troy Miles
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
Troy Miles
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
mametter
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
Ngoc Dao
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency Approach
Emre Akış
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
scalaconfjp
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
Kyle Drake
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
mametter
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
Bhanuka Uyanage
 
Dynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection Promises
Marcus Denker
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
tod esking
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
Marcus Denker
 

What's hot (20)

Advanced Reflection in Pharo
Advanced Reflection in PharoAdvanced Reflection in Pharo
Advanced Reflection in Pharo
 
JS Event Loop
JS Event LoopJS Event Loop
JS Event Loop
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
Web development basics (Part-6)
Web development basics (Part-6)Web development basics (Part-6)
Web development basics (Part-6)
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
jQuery (intermediate)
jQuery (intermediate)jQuery (intermediate)
jQuery (intermediate)
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
 
A Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and UnderstandingA Type-level Ruby Interpreter for Testing and Understanding
A Type-level Ruby Interpreter for Testing and Understanding
 
JavaScript Good Practices
JavaScript Good PracticesJavaScript Good Practices
JavaScript Good Practices
 
Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Actor model : A Different Concurrency Approach
Actor model : A Different Concurrency ApproachActor model : A Different Concurrency Approach
Actor model : A Different Concurrency Approach
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
 
Hybrid concurrency patterns
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
 
TypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without AnnotationsTypeProf for IDE: Enrich Development Experience without Annotations
TypeProf for IDE: Enrich Development Experience without Annotations
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 
Upgrading to rails3
Upgrading to rails3Upgrading to rails3
Upgrading to rails3
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Dynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection PromisesDynamically Composing Collection Operations through Collection Promises
Dynamically Composing Collection Operations through Collection Promises
 
From Ruby to Scala
From Ruby to ScalaFrom Ruby to Scala
From Ruby to Scala
 
Reflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond SmalltakReflection in Pharo: Beyond Smalltak
Reflection in Pharo: Beyond Smalltak
 

Similar to How to start using Scala

Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
Mike Slinn
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
alexismidon
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
Fabio Fumarola
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
Shih-Hsiang Lin
 
Gradle
GradleGradle
What's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
What's New in LuaRocks - Lua Workshop 2014 - Hisham MuhammadWhat's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
What's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
Hisham Muhammad
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!
MeriamLachkar1
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
Arto Artnik
 
Build application using sbt
Build application using sbtBuild application using sbt
Build application using sbt
sparrowAnalytics.com
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaVasil Remeniuk
 
Simple build tool
Simple build toolSimple build tool
Simple build tool
Knoldus Inc.
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
Eugene Yokota
 
SBT Concepts, part 2
SBT Concepts, part 2SBT Concepts, part 2
SBT Concepts, part 2
Renat Bekbolatov
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
Ryan Cuprak
 
Postgres the hardway
Postgres the hardwayPostgres the hardway
Postgres the hardway
Dave Pitts
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Tino Isnich
 

Similar to How to start using Scala (20)

Sbt, idea and eclipse
Sbt, idea and eclipseSbt, idea and eclipse
Sbt, idea and eclipse
 
Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012Buildr In Action @devoxx france 2012
Buildr In Action @devoxx france 2012
 
An introduction to maven gradle and sbt
An introduction to maven gradle and sbtAn introduction to maven gradle and sbt
An introduction to maven gradle and sbt
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Introduction to Apache Ant
Introduction to Apache AntIntroduction to Apache Ant
Introduction to Apache Ant
 
Gradle
GradleGradle
Gradle
 
What's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
What's New in LuaRocks - Lua Workshop 2014 - Hisham MuhammadWhat's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
What's New in LuaRocks - Lua Workshop 2014 - Hisham Muhammad
 
Boost your productivity with Scala tooling!
Boost your productivity  with Scala tooling!Boost your productivity  with Scala tooling!
Boost your productivity with Scala tooling!
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Build application using sbt
Build application using sbtBuild application using sbt
Build application using sbt
 
SBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius ValatkaSBT by Aform Research, Saulius Valatka
SBT by Aform Research, Saulius Valatka
 
Simple build tool
Simple build toolSimple build tool
Simple build tool
 
Road to sbt 1.0 paved with server
Road to sbt 1.0   paved with serverRoad to sbt 1.0   paved with server
Road to sbt 1.0 paved with server
 
SBT Concepts, part 2
SBT Concepts, part 2SBT Concepts, part 2
SBT Concepts, part 2
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Postgres the hardway
Postgres the hardwayPostgres the hardway
Postgres the hardway
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01Gradleintroduction 111010130329-phpapp01
Gradleintroduction 111010130329-phpapp01
 
Play framework
Play frameworkPlay framework
Play framework
 

More from Ngoc Dao

BIG DATA サービス と ツール
BIG DATA サービス と ツールBIG DATA サービス と ツール
BIG DATA サービス と ツール
Ngoc Dao
 
How to write a web framework
How to write a web frameworkHow to write a web framework
How to write a web framework
Ngoc Dao
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
Ngoc Dao
 
Xitrum HOWTOs
Xitrum HOWTOsXitrum HOWTOs
Xitrum HOWTOsNgoc Dao
 
Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Ngoc Dao
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS IntroNgoc Dao
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with TsungNgoc Dao
 
Cloud Erlang
Cloud ErlangCloud Erlang
Cloud Erlang
Ngoc Dao
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internalsNgoc Dao
 
Những lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNhững lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần application
Ngoc Dao
 
Erlang Web
Erlang WebErlang Web
Erlang Web
Ngoc Dao
 
Nitrogen Web Framework
Nitrogen Web FrameworkNitrogen Web Framework
Nitrogen Web Framework
Ngoc Dao
 
スポイトができるまで
スポイトができるまでスポイトができるまで
スポイトができるまで
Ngoc Dao
 
Camellia General
Camellia GeneralCamellia General
Camellia GeneralNgoc Dao
 
Nhập môn BDD
Nhập môn BDDNhập môn BDD
Nhập môn BDDNgoc Dao
 
何でRuby
何でRuby何でRuby
何でRuby
Ngoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Ngoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua GSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Ngoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Ngoc Dao
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua HungSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Ngoc Dao
 

More from Ngoc Dao (20)

BIG DATA サービス と ツール
BIG DATA サービス と ツールBIG DATA サービス と ツール
BIG DATA サービス と ツール
 
How to write a web framework
How to write a web frameworkHow to write a web framework
How to write a web framework
 
Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014Xitrum @ Scala Matsuri Tokyo 2014
Xitrum @ Scala Matsuri Tokyo 2014
 
Xitrum HOWTOs
Xitrum HOWTOsXitrum HOWTOs
Xitrum HOWTOs
 
Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013Xitrum @ Scala Conference in Japan 2013
Xitrum @ Scala Conference in Japan 2013
 
SockJS Intro
SockJS IntroSockJS Intro
SockJS Intro
 
Easy distributed load test with Tsung
Easy distributed load test with TsungEasy distributed load test with Tsung
Easy distributed load test with Tsung
 
Cloud Erlang
Cloud ErlangCloud Erlang
Cloud Erlang
 
Xitrum internals
Xitrum internalsXitrum internals
Xitrum internals
 
Những lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần applicationNhững lỗi bảo mật web thường gặp ở phần application
Những lỗi bảo mật web thường gặp ở phần application
 
Erlang Web
Erlang WebErlang Web
Erlang Web
 
Nitrogen Web Framework
Nitrogen Web FrameworkNitrogen Web Framework
Nitrogen Web Framework
 
スポイトができるまで
スポイトができるまでスポイトができるまで
スポイトができるまで
 
Camellia General
Camellia GeneralCamellia General
Camellia General
 
Nhập môn BDD
Nhập môn BDDNhập môn BDD
Nhập môn BDD
 
何でRuby
何でRuby何でRuby
何でRuby
 
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 2 - Phat bieu cua Ngoc
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua GSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua G
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua NgocSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Ngoc
 
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua HungSinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
Sinh hoat CLB tin hoc Komaba lan 1 - Phat bieu cua Hung
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 

How to start using Scala

  • 1. How to START using Ngoc Dao
  • 2. This talk is not about Scala syntax (You can learn 80% of it in 2 days, Sat & Sun)
  • 4. Why I use Scala ● Syntax is similar to Ruby (human oriented) ● Faster than Ruby (= Java, ~C) ● Can reuse all Java libs (Java has lots of libs!) ● Easy to program for multicores (like Erlang)
  • 5. Agenda 1. “scala” and “scalac” commands 2. SBT (Scala Build Tool) 3. Some useful frameworks
  • 6. Part 1: scala & scalac
  • 7. Install Scala 1. Download from scala-lang.org 2. Config PATH .bash_profile: PATH=~/opt/scala-2.9.2/bin:$PATH
  • 9. Interactive console ● For trying out code snippets ● Like “irb” of Ruby
  • 10. $ scala Welcome to Scala version 2.9.2 Type :help for more information. scala> 1 + 2 res0: Int = 3 scala> "hello".length res1: Int = 5 scala> :q $
  • 11. Scripting Scala ● Can run a script right away, no compile step is needed ● To run, “scala” command is needed; it will compile on the fly then run ● For simple one-file programs
  • 12. $ cat Hello1.scala println(1 + 2) println("hello".length) $ scala Hello.scala 3 5
  • 13. Compile Scala ● Compile .scala file to .class file ● Can use “scala” or normal “java” command to run .class file ● Simple programs: scalac (like javac) ● Bigger programs: SBT (see next slides)
  • 14. $ scalac Hello1.scala Hello1.scala:1: error: expected class or object definition println(1 + 2) ^ Hello1.scala:2: error: expected class or object definition println("hello".length) ^ two errors found Need to wrap the script with “main”
  • 15. $ cat Hello2.scala object Hello2 { // Similar to normal Java/C programs def main(args: Array[String]) { println(1 + 2) println("hello".length) } }
  • 16. Run with “scala” command $ scalac Hello2.scala $ ls Hello2$.class Hello2.class Hello2.scala $ scala Hello2 3 5
  • 17. Run with “java” command $ java Hello2 Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject $ java -cp ~/opt/scala-2.9.2/lib/scala-library.jar:. Hello2
  • 19. SBT (Scala Build Tool) ● Dependency library manager ● Build tool ● Like “gem” + “rake” of Ruby ● Like Maven of Java
  • 20. Install SBT There are several ways to install: https://github.com/harrah/xsbt/wiki/Getting- Started-Setup I prefer installing SBT manually
  • 21. Install SBT manually ~/opt/sbt: sbt: java -Xmx512M -XX:MaxPermSize=128M -jar `dirname $0`/sbt-launch-0.12.0.jar "$@" .bash_profile: PATH=~/opt/sbt:$PATH
  • 22. Project structure hello build.sbt src main scala should_be_under_a_package Hello2.scala java (Java source files, if any) test (Scala/Java test source files, if any) scala java target scala-2.9.2 classes (Compiled .class files)
  • 23. build.sbt organization := "com.kayac" name := "hello" Like Gemfile of Ruby version := "1.0-SNAPSHOT" scalaVersion := "2.9.2" scalacOptions ++= Seq( Packaged .jar file: "-deprecation", hello_2.9.2-1.0-SNAPSHOT.jar "-unchecked" ) (Management of dependency libraries will be talked at part 3)
  • 24. SBT tasks $ sbt tasks console Starts the Scala interpreter compile Compiles sources clean Deletes files produced by the build run Runs a main class package Produces project jar file publish Publishes project jar file to a repository publish-local Copies project jar file to ~/.ivy2 test Executes all tests test-only Executes the tests provided as arguments test-quick Executes the tests that either failed before
  • 25. Demo ● https://github.com/ngocdaothanh/sclart/tree/master/sbt/hello ● sbt console, run, package etc.
  • 26. SBT plugins https://github.com/harrah/xsbt/wiki/sbt-0.10-plugins-list Some useful plugins: * Create Eclipse project file (with library paths): https://github.com/typesafehub/sbteclipse * One jar plugins
  • 27. Install SBT plugins 1. Install plugins at global level ~/.sbt/plugins/build.sbt Ex: addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0") 2. Install plugins at project level project/plugins.sbt Ex: https://github.com/ngocdaothanh/xitrum-demos/blob/master/project/plugins.sbt
  • 28. Demo ● Use sbt eclipse to create Eclipse project and see lib paths
  • 29. Part3: Some useful frameworks https://wiki.scala-lang.org/display/SW/Tools+and+Libraries
  • 30. Xitrum ● Combine web server + web framework ● https://github.com/ngocdaothanh/xitrum +------------------+ Scalable: session, realtime data etc. | Your app | +------------------+ | Xitrum | |+----------------+| || Web framework || <-- Hazelcast --> Other instances ||----------------|| || HTTP(S) Server || |+----------------+| +------------------+ Fast static file serving: https://gist.github.com/3293596 WebSocket
  • 31. Demo ● https://github.com/ngocdaothanh/xitrum-demos ● Routes ● WebSocket ● xitrum-package
  • 32. Akka ● http://akka.io/ ● Better than Scala's default actor library ● Has power of Erlang: concurrency distribution failure supervisor FSM (Finite State Machine, very good for realtime multiplayer games, to manage states of game sessions and inter-player interactions)