Getting started with Scala programming

table of Contents

Introduction

Features

Quick start

 Perform process analysis

Notes on scala program development (emphasis)

Three ways to output scala language

scala comment


Introduction

Scala is in a java virtual machine ( the JVM ) as the target operating the best characteristics of the environment and the object-oriented and functional programming static bonded together form typed programming language statement.

Features

  1. Scala is a multi-paradigm of formula (multi-paradigm) of programming language statements, Scala support support object-oriented and functional programming
  2. Scala source (.scala) are compiled into Java bytecode (.class) , then run on JVM on, and can call the existing Java class libraries, two languages to achieve seamless of contact.
  3. As a language, Scala is very simple and efficient

Quick start

Integrate scala environment in idea and build scala environment in windows, please check other materials by yourself.

Write the first helloworld program and run:

object hello {
  def main(args: Array[String]): Unit = {
    println("hello world")
  }
}

 Perform process analysis

If compiled with scalac, .class byte code will be generated, otherwise it will not be generated, and the byte code is generated directly in the memory.

Notes on scala program development ( emphasis )

  • Scala source file to ".scala" extension
  • Scala process execution entry sequence is main () function
  • The Scala language is strictly case sensitive.
  • Scala square method consists of a statement, every word after the sentence does not require a semicolon (Scala language will automatically add a semicolon after each line ) , which also reflects the Scala simplicity of.
  • As if more than one statement on the same line, in addition to the last statement does not need to divide numbers, other statements require the semicolon ( try to write a statement on one line ) .

Three ways to output scala language

object hello {
  def main(args: Array[String]): Unit = {
    var name = "zhangsan"
    var age = 18
    println("name: "+name +" age: "+age)
    printf("name: %s age: %d \n",name,age)
    println(s"name: ${name},age: ${age}")
  }
}

Strings are connected by + signs (similar to java )

  println("name:" + name + " age:" + age)

printf usage (similar to the C language) by strings % by value . ( Formatted output )

  printf("name=%s, age=%d \n", name, age)

String interpolation: referenced by $ ( similar to PHP )

  println(s"name=${name}, age=${age}")

scala comment

Single-line comments : // comment text word

Multi-line comments : / * Comment text * /

Document notes: / ** Note text * /

Scala's comments are completely similar to java comments

 

Published 39 original articles · won praise 1 · views 4620

Guess you like

Origin blog.csdn.net/thetimelyrain/article/details/104311211