Create a gist now

Instantly share code, notes, and snippets.

@seratch /doc.md
Last active Feb 26, 2017

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