A few days ago, Lao Zhao published two articlesArticle: Use Scala language (I) on the. NET platform: first taste and use Scala language (I) on the. NET platform: analysis.
After reading this article, I am also interested in Scala. So I started to try.
Installing Scala SDK on Ubuntu 9.10 is very simple:
Ben@
I. Basics
1. VariablesVal identifier: Declares constants. For example, Val answer = 1.VaR flag: declares a variable;
Type inference: Scala deduce the type of a variable based on the expression of the initialization variable;
Val is encouraged;
Note: An error is reported if the variable is declared without initialization.
Explicit type: Scala variables or functions are always written after variables or
Match use case class:
Case classes is used for pattern matching and case expression to specify the class. These are standard classes with special modifications: case. The following is a simple pattern that uses case class matching examples:
Object Test {
def main (args:array[string]) {
Val alice = new Person ("Alice", 25)
Val bob = new Person ("Bob", 32)
Val charlie = new Person ("Charlie", 32)
for (Person
Person Match {
Case person ("Alice") => println ("Hi alice!")
Case person ("Bob
A concise course in Scala
Directory
Variable declaration
Function
Package Package
Data
String
Control process
Pattern matching
Object-oriented
Generic type
Annotations
Implicit
Empty Object Nil,null,null,unit,nothing,none
Scala is a multiple-paradigm (MULTI-PARADIGM) programming language.
Scala source code is compiled into Java bytecode, so it can run on top
Class and constructors:The class is defined as follows:
Class MyClass (A:int, b:int) {
println (a.tostring)
}
In Scala, classes can also have class parameters, class parameters can be used directly in the body of the class, there is no need to define a field and then assign the constructor parameters to the field, but it should be noted that: the class parameter is just a parameter, not a field, if you need to use elsewhere, you must define the f
Clojure was first FP, but because of the JVM, there was a need to make some compromises, including some OO programming methodsScala first is OO, Java syntax is too redundant, a more mediocre language, Scala first do is to simplify, in a more concise way to write Oo, the main use of ' type inference ' can be inferred, you do not have to write, but if only this, it is better to use PythonSo Scala, like its na
Use of 1.Scala ReplInstall Scala and append the bin directory of the Scala installation directory to the PATH environment variable. In this case, you can enter Scala directly under CMD to enter REPLEnter REPL, and you can enter a valid expression in Scala after the command p
Scala Featured Tutorials-case class and pattern matching
Scala Featured Tutorials-case class and pattern matching (1): A simple Demo sample
Scala Featured Tutorials-case class and pattern matching (2): type of pattern (i)
Scala Featured Tutorials-case class and pattern matching (3): type of pattern (ii)
The concepts of classes and methods in Scala are similar, and here are just some of the important concepts of Scala: 1.Public is the default access level for Scala and can be omitted. An important feature of the method parameters in 2.Scala is that they are all Val, not Var (the argument is Val is easier to articulate,
Guide to Statistics network This paper introduces Scala's language characteristics from seven aspects, such as installation, basic data type, operator, function and so on. Not just a Python programmer, anyone with programming experience or a desire to get started can look at it and make a basic understanding of Scala.
With the needs of business and data, we have introduced spark. Spark's support for Python is fine, but it has been developed using
To create a string:
The most straightforward way to create a string is to write a method that:
var greeting = "Hello world!";
Or
var greeting:string = "Hello world!";
Whenever you encounter a string in code, the compiler creates a string object and its value in this example using: "Hello world!", but if you like, you can give the string, because here I have alternately shown in the declaration.
Object Test {
Val greeting:string = "Hello, world!"
def main (args:array[string]) {
printl
This article compares the keywords of Java and ScalaJava keywords
Java has a total of 50Keywords(Keywords), Two of which areReserved Words, Not used yet:GotoAndConst.True,FalseAndNullIt looks like a keyword, but it's actually justLiteral. This article roughly regards true, false, and null as Java keywords and considers Java as a total of 53 keywords. Below is a list of roughly classified Java keywords:
Assert
Boolean, byte, short, Char, Int, long, float, double, void
Package, import, class,
A systematic study of Scala has recently begun. In fact, I used Scala before, for example, when I was using Gatling's performance testing tool, I was exposed to Scala. Gatling itself is written in Scala, and the Gatling performance Test profile itself is a Scala class that i
The main contents of this section
Introduction to Scala I/O operations
Scala Writing Files
Scala Read files
Scala Network I/O
Introduction to Regular expressions
Scala regular-expression combat
1. Introduction to
ArrayLike an array of Java, it is also an immutable arrays, and since both Scala and Java are running in the JVM, both sides can call each other, so the bottom of the Scala array is actually a Java array.
Note: Accessing an array of elements using () instead of [] in Java
Scala>ValA =NewArray[string] (Ten) a:array[string] = Array (NULL,NULL,NULL,NUL
Scala basic Concept +ideRecommended: "Scala Programming"1 Basic ConceptsIn spark development, Scala is considered to be the best-compatible language for current and spark.
Scala run on a standard Java platform that can be used with Java seamless interaction.
"Editor's note" Although Java has won a lot of developers love, but compared to other modern programming languages, its syntax is indeed slightly lengthy. But with Java8, you can write code that is both readable and concise by using lambda expressions directly. The author Hussachai Puripunpinyo's software engineer, who analyzed the differences in performance and expression by comparing Java 8 and Scala, and discussed in depth the differences between t
Because Scala has a more complete Eclipse IDE (Scala IDE for Eclipse), it's easy, fast, and convenient for Dev who doesn't want to migrate from Eclipse to the IEA platform. It is particularly important to compile and package the development of Scala applications under Eclipse. SBT is a build tool similar to MAVEN, which we will use to build the publishing program
methods for traversing collections
1. Iterating through a collection with a foreach Loop
foreach receives a function as a parameter. The defined function should receive an element as an input parameter, and then do not return anything. The type of the input parameter should match the type in the collection. With the execution of foreach, it passes an element to your function every time, until the last element in the collection.
The most common use of foreach is output information:
Prerequisite
In this article, we'll create a mobile application that runs on an Android device. You will need to install the Android SDK; This article uses the V1.5 SDK. Application code will be written in the Scala programming language. If you've never used Scala, then it doesn't matter, because this article will explain the Scala code. However, even if you are
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.