Scala Learning Note 1

Source: Internet
Author: User

First, REPL

The Scala interpreter reads an expression, evaluates it, prints it out, and then continues to read the next expression. This process is called a read-print-loop, or REPL.

Technically speaking, the Scala program is not an interpreter. What actually happens is that the content you enter is quickly compiled into bytecode, which is then handed to the Java Virtual machine for execution. Because of this, most Scala programmers are more inclined to call it repl.

Ii. value of the claim

The value defined by 2.1val is actually a constant, and you cannot change its contents.

8*2Scala0<console>: one: Error: Reassignment to Val       0              ^

Scala encourages the use of Val

You need to give the value or the type of the variable, declaring the value or variable but not initializing it will cause an error.

When necessary, you can also specify the type

8*2Scala0<console>: one: Error: Reassignment to Val       0              ^

Iii. Common types of Scala

3.1 Basic data types

There are 8 kinds of data types in Scala and Java, but the basic and reference types are not deliberately differentiated in Scala. You can perform a method on a pair of numbers, such as

Scala> 1.toString ()

res1:string = 1

In Scala we don't need a wrapper type, the conversion between the base type and the wrapper type is the work of the Scala compiler.

BigInt and BigDecimal classes for numbers of any size. Behind these classes are Java.math.BigInteger and Java.math.BigDecimal, respectively. They're easier to use, and you can manipulate them with regular math operators.

3.2 String Type

Scala uses the underlying java.lang.String class to represent strings. However, he added hundreds of operations to the string through the Stringops class.

The Intersect method outputs two strings in a common set of characters

" Hello ". Intersect ("World"= Lo

In this expression, the string object is implicitly converted to the Stringops object, and then the Intersect method of the Stringops class is called.

The same Scala also offers Richint, richdouble, Richchar, and more. They provide a quick method that Int,double,char does not have. The 1.toString we used earlier is the method in the Richint class. First 1 were converted to Richint, then the head method was applied.

3.3 Type Conversions

In Scala we use methods rather than coercion type conversions.

99.44,Scala , Cscala "99.44"   99.44

Scala Learning Note 1

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.