Getting started quickly learn -Scala

Scala QuickStart

Scala Development Tools

IDEA description:

IDEA stands for IntelliJ IDEA, for java language development integrated environment (can also be used for other languages), IntelliJ workers in the industry is recognized as the best java development
one has. JetBrains IDEA is the company's products, the company is headquartered in the capital of the Czech Republic in Prague.

Here Insert Picture Description
java development tools are many, such netbean, eclipse, etc., a single development tool Scala optional small, the main tool developers use IDEA Idea shortcuts Scala's not a lot, so the use of relatively simple IDEA not specifically developed for the Scala IDE but indeed the best tool for the development of Scala, because in our practical work, most development projects, and big data projects inevitably use to Java, it will be mixed Java and Scala programming in two languages. The Idea can well support the development of Java and Scala.

Scala execution flow analysis

Here Insert Picture Description

Scala program development notes (Key)

  1. Scala source files ".scala" extension.
  2. Scala program execution entry is main () function.
  3. Scala language strictly case-sensitive
  4. Scala method consists of a statement, the statement does not require each semicolon (Scala language automatically semicolon after each line), which also reflects the simplicity of Scala.
  5. If more than one statement on the same line, except for the last sentence does not require a semicolon, other statements require a semicolon.

Scala common escape character (escape char)

  1. \ T: a tab stop, to achieve alignment function
  2. \ N: line breaks
  3. \ :One\
  4. " :One"
  5. \ R: a carriage return println ( "hello \ rk");

Scala language output of three ways

  1. By connecting the string + number (similar java).
  2. Usage printf (C-like)% pass through a string value.
  3. $ String by reference (similar to PHP).
val name = "ApacheCN"
val age  = 1
val url  = "www.atguigu.com"
println("name=" + name + " age=" + age + " url=" + url)
printf("name=%s, age=%d, url=%s \n", name, age, url)
println(s"name=$name, age=$age, url=$url")

Associated Scala source view

In the course of using the scala, scala To understand the mechanism underlying needs to see the source, see below and see if the associated source packets Scala
Here Insert Picture Description

Comment (comment)

Introduction:

For the annotation caption interpreter it is comments, which improves code readability; Notes is a programmer must have good programming practice. Their thoughts by commenting sorted out first, then the code to reflect.

Annotation types in Scala

  1. Single-line comments
  2. Multi-line comments
  3. Documentation Comments
  • Single-line comments:
基本格式
格式: //注释文字
应用实例
  • Multiline comments:
基本格式
格式: /*  注释文字 */
应用实例

The right notes and comments Style:

Correct indentation and blank

  1. Use a tab operation, to achieve indent, the overall default move to the right, when left with shift + tab to overall
  2. Or using ctrl + alt + L be formatted [presentation]
  3. Operators of respective sides of a space diet. For example: 2 + 4 * 5.
  4. Line up no more than 80 characters, use the wrap over the display, try to keep the elegant format

Official Scala Programming Guide

Here Insert Picture Description

Released 1401 original articles · won praise 1213 · Views 110,000 +

Guess you like

Origin blog.csdn.net/weixin_42528266/article/details/104392432