Skip to content

Latest commit

 

History

History
105 lines (65 loc) · 2.77 KB

README.md

File metadata and controls

105 lines (65 loc) · 2.77 KB

Basic Info

Name: Scala

Creator(s): Martin Odersky

Date: January 20, 2004

Website: scala-lang.org

Intro

Scala is a strong statically typed general-purpose programming language which supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are aimed to address criticisms of Java. Scala source code can be compiled to Java bytecode and run on a Java virtual machine (JVM). Scala provides language interoperability with Java so that libraries written in either language may be referenced directly in Scala or Java code.

Syntax

Variables in Scala can be declared with the keyword var or val followed by the name of the variable, an = sign and the value. You can also optionally specify a data type.

var name = "Jacob"
val num = 42

If/Else statements in Scala are very similar to other languages with brackets around the condition and curly braces around the body.

if (true) {
    println("True!")
} else if (false) {
    println("False!")
} else {
    println("WTF?!")
}

Loops in Scala are very similar to other languages, see one example below.

for (x <- 1 to 10) {
    println("The value of x is: " + x)
}

Functions in Scala are declared using the keyword def and follow a similar syntax to other languages, see one example below.

def addInt(a:Int, b:Int):Int = {

  var sum:Int = a + b

  return sum

}

println(addInt(1, 2))

Classes in Scala are declared using the keyword class and follow a similar syntax to other languages, see one example below.

class Point(xa:Int, ya:Int) {

   var x:Int = xa
   var y:Int = ya

   def move(xb:Int, yb:Int) {

      x = xb
      y = yb

   }

}

var point = new Point(10, 20)

println(point.x)
println(point.y)

point.move(30, 40)

println(point.x)
println(point.y)

Libraries

More Info