Skip to content

Instantly share code, notes, and snippets.

@seratch
Last active February 26, 2017 14:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seratch/51565c552874f2c0848a1ad36c456c7b to your computer and use it in GitHub Desktop.
Save seratch/51565c552874f2c0848a1ad36c456c7b to your computer and use it in GitHub Desktop.
Scala Introduction for Java developers

Scala Introduction for Java developers

  • ScalaMatsuri 2017

prerequisites

  • JDK 8+ (if you'd like to use the latest Scala)
  • brew install sbt to install the global sbt launcher script

scala lang version

You can switch the version when starting the JVM.

  • 2.11.x on Java 7
  • 2.11.x on Java 8
  • 2.12.x on Java 8

Scala lang binary version

Binary compatibilities are not kept between the bin versions.

  • 2.9.0
  • 2.9.1
  • 2.9.2
  • 2.10.x
  • 2.11.x
  • 2.12.x
  • 2.13.x

Getting started

IntelliJ Setup Demo

import-1

import-2

# brew install sbt
mkdir -p hello-scala/project
cd hello-scala
echo 'sbt.version=0.13.13' > project/build.properties
echo 'scalaVersion := "2.12.1"' > build.sbt
sbt

Hello World

on the REPL

sbt console
# println("Hello World")

IntelliJ IDEA

run

debug-1

debug-2

  • Run
  • Debug
object Example extends App {
  println("Hello World!")
}

diff java scala

  • package, package object, import renamed package/class/trait
  • Immutable Collection, Option
  • class, trait, object
  • companion object for static things
  • test (ScalaTest, specs2)

Test Demo

echo 'libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.1" % "test"' >> build.sbt

test-1

test-2

test-3

test-4

Other Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment