In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to build the environment of Scala". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to build the environment of Scala".
First, the first is to build the environment, there are only three steps
1. Install jdk
2. Download and decompress scala
3. Configure the scala/bin path to the path. After the above work is done, you can experience scala in the command line. Open a command line window and type scala.
Second, val and var, mutable and immutable, the concept of itself is not difficult to understand, but the use of val and var is related to the traditional instruction-to-functional transformation. The shift from imperative to functional is probably one of the most difficult areas for java programmers to learn scala.
Third, with regard to numerical types, there is a difference between int and Integer in java, one is the basic type and the other is the object. In scala, there is no such distinction. Var I: Int = 0. This Int is a class in scala, scala.Int, which defines some operations. For the first time, scala also provides a RichInt, which provides a richer set of operations. To perform this operation, you don't need an explicit type conversion, just use it. For example, 1 to 10 is actually 1.to (10), and this to is actually the method provided by RichInt.
Fourth, with regard to strings, scala also uses java.lang.String, which corresponds to a StringOps, which also provides richer operations and does not require type conversion.
The arithmetic operator, +-* /, looks no different from java, but in fact it is completely different. These things are all methods. For example, 1-2, which is actually 1. + (2), + is a method, defined in Scala.Int. The amount of information here is relatively large. 1. In our own code, we can also use the arithmetic operator as the method name. 2. When you write code later, you don't have to look like obj.method (para). You can make obj method para look like this.
6. Scala does not have static methods, but there are alternatives. Look at the code:
Class ClassAndObject {
Var testvar = 0
}
Object ClassAndObject {
Def main (args: Array [String]) {
Var obj = new ClassAndObject
Obj.testvar = 10
Println (obj.testvar)
Var obj1 = ClassAndObject (20)
Println (obj1.testvar)
}
Def apply (I: Int) = {
Var obj = new ClassAndObject
Obj.testvar = I
Obj
}
}
There is still a lot of information.
1. Class ClassAndObject and object ClassAndObject are called associated classes and associated objects respectively.
2. According to java's way of thinking, static methods can be put into concomitant objects. 3, see main, this is similar to java, with that thing, the code can run.
7. Apply, this thing is very important to make it easier for you to create an object, ClassAndObject (20), which is actually equivalent to ClassAndObject. Apply (20), which you will often see in the future.
Array (1, 2, 3, 4, 5)
BigInt ("20")
BigInt (20)
Thank you for your reading, the above is the content of "how to build the environment of Scala". After the study of this article, I believe you have a deeper understanding of how to build the environment of Scala, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.