Getting Started with "C1" Scala

Source: Internet
Author: User


1.scala Interpreter

The installation process is similar to a JDK installation, you need to install the JDK first, and then download and install Scala to configure the PATH environment variable.

2. Run cmd in the win environment using WIN+R, bring up the command window, execute the callout command

①scala Support TAB Command Auto-completion

②scala Support Type automatic decision

C:\users\martin>scalawelcome to Scala version 2.11.4 (Java HotSpot (TM) 64-bit Server VM, Java 1.7.0_6
7).
Type in expressions to has them evaluated.
Type:help for more information.

Scala> 8*5+2res0:int = 42

scala> 0.5*res0res1:double = 21.0

Scala> "Hello," +res1res2:string = hello,21.0

scala> Res2.totochararray tolowercase toString touppercase

scala> res2.toUpperCaseres3:String = hello,21.0

Scala>

3. Declaration of variables and values

①scala supports Val, var two ways of declaring

②val similar to the final definition in Java, for immutable pointing declarations

③scala Support for batch declarations

Scala>Val answer=8*5+2Answer:int = 42scala>0.5*answerRes4:double = 21.0scala>answer = 0

<console>:8:error:reassignment to Val answer = 0 ^scala>var counter = 0Counter:int = 0scala>counter = 5Counter:int = 5

Scala> Val answer=8*5+2
Answer:int = 42

Scala>0.5*answer
Res4:double = 21.0

Scala>answer = 0
<console>:8:error:reassignment to Val
Answer = 0
^
Scala>var counter = 0
Counter:int = 0

Scala>counter = 5
Counter:int = 5


4. Common Types

①scala supports Java-like common basic types in 8, Byte, Char, short, Int, Long, Float, Double, Boolean

②scala does not deliberately distinguish between basic and reference types, all classes, and no wrapper type

5. Operators

Scala Support +-*/% & | ^ >> << ET, note: These operators are actually methods

6. Calling functions and methods

①scala Import Reference Package Imports Scala.math._//wildcard characters _, and Java similar to *

②scala has no static method, and a similar attribute is called a singleton object (Singleton objects). Usually a Scala class has a companion object (Companion objects), and its methods are similar to the Java static methods

Scala> Bigint.probableprime (100,scala.util.random)
Res5:scala.math.BigInt = 799354413129363757440390082331

7.apply method

Methods like function calls are often used in Scala.

For example, "Hello" (4) writing "Hello". Apply (4)

8.DOC Documentation

Doc online Documentation



Getting Started with "C1" Scala

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.