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 > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to build Scala development environment under Windows". In daily operation, I believe many people have doubts about how to build Scala development environment under Windows. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to build Scala development environment under Windows". Next, please follow the editor to study!
Chapter 1 Overview of Scala language 1.1 why is Scala language?
1. Spark-- 's new generation of memory-level big data computing framework is an important part of big data.
2. Spark is written in Scala. Therefore, in order to better learn Spark, it is necessary to master the language Scala.
3. Scala, short for Scalable Language, is a programming language with multiple paradigms (paradigm = programming mode [object-oriented / functional programming]).
4. Martin Odersky (Martin Odsky) of Lobsang (EPFL) of Federal Institute of Technology began to design Scala (Skala) in 2001.
5. The rise of Spark drives the development of Scala language!
1.2 short stories about the birth of Scala language
founder Martin Martin Odersky is a compiler and programming enthusiast. After a long period of programming, he hopes to invent a language that will make the basic work of writing programs efficient and easy. So when I came into contact with the JAVA language, I became very interested in JAVA, which is portable, runs on the network, and has garbage collection, so I decided to integrate the characteristics of the functional programming language into JAVA, thus invented two languages (Pizza & Scala). (heavy use of recursion)
jdk5.0 's generics, for loop enhancements, automatic type conversions, and so on, are all new features introduced from Pizza.
jdk8.0 's type inference and Lambda expressions are the features introduced from scala.
Pizza and Scala have greatly promoted the development of the Java programming language. [how to understand it?]
and now the mainstream JVM javac compiler is written by Martin Odsky. And is widely used by JAVA programmers, so the Scala language originated from Java, but promotes the development of Java, they complement each other. The compilers of Jdk5.0 and Jdk8.0 were written by Martin Oddsky, so Martin Odsky is as effective as a Java development team.
is based on the above reasons, so the Scala source code (.scala) will be compiled into Java bytecode (.class), then run on JVM, and can call the existing Java class library to achieve a seamless interface between the two languages, so it will be a little easier for us who have mastered the JAVA language.
Scala is a statically typed programming language that targets the java virtual machine (JVM) and combines the best features of object-oriented and functional programming. (you must know what the type is before running) 1.3.Relational analysis diagrams of Scala, Java and jvm
generally speaking, people who learn Scala will Java, and Scala is based on Java, so we need to figure out the relationship between Scala, Java and JVM, otherwise you will be bewildered by learning Scala.
suggests: if you don't have any basic knowledge of Java, you should learn Java first, or at least JavaSE, and then Scala.
Let's analyze the relationship between Scala and Java and jvm (important!)
2 、
Building Scala development environment under 1.6 Linux
in the actual development, our project is deployed on linux, so we need to build scala environment under Linux. The principle and mechanism of installing Scala under Linux is the same, and the specific steps are as follows:
1. Download the corresponding scala installation software scala-2.11.8.tgz
2. Upload the installation software to the corresponding Linux system (xshell6 and xftp6) through the remote login tool.
3. Create a directory for mkdir / opt/module/scala
4. Decompress: $tar-zvxf / opt/software/scala-2.11.8.tgz-C / opt/module/scala/
5. Configure the environment variable vim / etc/profile
Configure scala's bin directory / opt/module/scala/scala-2.11.8/bin in this file
# SCALA_HOMEexport SCALA_HOME=/opt/module/scala/scala-2.11.8export PATH=$PATH:$SCALA_HOME/bin
6. Make the configuration file effective source / etc/profile
7. Test, command: scala
Description of the basic structure of scala program:
1.8.2 Development steps under linux
The steps are as follows:
1, directly using vim development, a case of traversing the array.
2. Write the Scala code into a file with the extension HelloScala.scala. [code description]
3. Compile the scala file through the scala command to generate a .class bytecode file.
4. You can see the running effect by executing scala HelloScala in the terminal.
5. Note: you can run the HelloScala.scala program directly through the scala HelloScala command.
The code is as follows:
/ * as long as we see object HelloScala later, we should have the following understanding: * 1. Object HelloScala corresponds to a static object MODULE$ of type HelloScala$. * 2. Object HelloScala exists as a singleton in the running of the program. * / object HelloScala {def main (args: Array [String]): Unit = {println ("hello scala")}}
1.8.3 Development steps under IDEA
uses text tools to develop projects, which can well understand the operation principle, but it is not conducive to the development of integrated projects, so we should use Idea in actual development.
The steps are as follows:
1. Create a new Maven project, create a new scala folder under the main directory of the project, and mark the folder as [Source folder] for easy management. Right-click scala-> Mark Directory as-> Sources Root
2. By default, you cannot write scala programs. You need to introduce the scala framework (that is, associate the project with scala) and select the project right-> Add Framework Support. -> check the left Scala-> specify the home directory of the Scala installation-> OK.
3. Right-click on the scala folder, select create a new Scala class, and check Kind as Object, as shown below:
4. Develop a HelloScala.scala program.
5. After running, you can see the output.
1.8.4 write a simulation code using java to simulate the execution process of scala
The code is as follows:
Package com.atguigu.chapter01.Test;/** * it is understandable that the code we wrote in main is put in the mian of HelloScala$, that is, when scala is running at the bottom, the compiler makes a wrapper. * / public class HelloScala {public static void main (String [] paramArrayOfString) {HelloScala$.MODULE$.main (paramArrayOfString);}} final class HelloScala$ {public static final HelloScala$ MODULE$; static {MODULE$ = new HelloScala$ ();} public void main (String [] args) {System.out.println ("hello scala");}}
1.8.5 Scala execution process Analysis
1.8.6 points for attention in Scala Program Development (key points)
Note:
1, Scala source files have the extension ".scala".
The execution entry of 2 and Scala program is the main () function.
3 and Scala languages are strictly case-sensitive.
The 4 and Scala methods are made up of statements that do not need a semicolon after each statement (the Scala language automatically adds a semicolon after each line), which also reflects the simplicity of Scala.
5. If you have multiple statements on the same line, you need a semicolon except for the last statement.
1.9 Scala language escape character\ t: a tab stop to achieve alignment\ n: newline character\: a\ ": a"\ r: a carriage return println ("hello\ rk"); 1.10 three ways of Scala language output
1, the string is concatenated by the + sign (similar to java).
2, printf usage (similar to C) strings pass values through%.
3. The string is referenced by $(similar to PHP).
Sample code:
Package com.atguigu.chapter01object PrintDemo {def main (args: Array [String]): Unit = {val str1: String = "hello" val str2: String = "world" / / connection print println (str1 + str2) val name: String = "tom" val age: Int = 10 val sal: Float = 10.67f val height: Double = 180.75 / / formatted output printf ("name =% s age =% D salary =% .2f height =% .3f " Name, age, sal, height) / / scala supports the use of $output content println (s "personal information is as follows:\ nname $name\ nAge $age\ nsalary $sal\ n") / / if something like ${age + 10} appears in the string Then {} is an expression println (s "personal information is as follows:\ nname ${name}\ nAge ${age + 10}\ nsalary ${sal}\ n")}}
Output result:
Helloworld name = tom age = 10 salary = 10.67 height = 180.750 person information is as follows: name tom age 10 salary 10.67 person information is as follows 2: name tom age 20 salary 10.671.11 Scala source code view relevance
In the process of using scala in , in order to understand the underlying mechanism of scala, you need to look at the source code. Let's see how to associate and view the source code package of scala.
1. Check the source code, select the method or class you want to view, enter Ctrl + B or double-click
When we do not associate the source code, we will see the following figure:
We can click Download... Download the source code automatically, or associate the source code manually.
2. Associate the source code manually
Source package download address: link, modify the source package we downloaded scala-2.11.8.tar.gz package named scala-sources-2.11.8.tar.gz, in order to facilitate identification
Step 1: copy our source package to the scala/lib folder (scala-sources-2.11.8.tar.gz) so that it can be easily managed and then decompressed (because IDEA does not recognize compressed packages in xxx.tar.gz format)
Step 2: just connect, click Attach Sources … Select the scala-sources-2.11.8 folder and associate it. Finally, you can see the source code.
1.12 comment
1.12.1 introduction
The text used by to annotate and explain the interpreter is comments, which improve the readability of the code.
annotations are good programming habits that a programmer must have. Sort out your ideas through comments, and then reflect them in code.
1.12.2 comment types in Scala
1. Single-line comments: format: / / comment text
2. Multiline comments: format: / * comment text * /
3, document comments: the comments can be parsed by the tool scaladoc to generate a set of instructions for the program in the form of a web page file.
1.12.3 documentation annotation case
1. Open the directory where the file is located, and right-click the file-> Show in Explorer
2. Enter scaladoc-d d:/mydoc Comment.scala in the command line window to generate the corresponding documentation.
The sample code is as follows:
Package com.atguigu.chapter01object Comment {def main (args: Array [String]): Unit = {println ("hello world")} / * @ deprecated expired * @ example * enter N1 = 10 N2 = 20 return 30 * @ param N2 * @ return summation * / def sum (N1: Int, N2: Int): Int = {return N1 + N2}}
1.12.4 Code specification for scala
1.12.5 correct comments and annotation style
views the Scala source code.
1.12.6 correct indentation and whitespace
1. Use a tab operation to achieve indentation, move the whole to the right by default, and move the whole to the left using Shift + Tab.
2, or use Ctrl + Alt + L for formatting code.
3. The operator habitually adds a space on each side. For example: 2 + 4 * 5.
4. The maximum length of one line is no more than 80 characters. Please use newline display if more than one line, and try your best to keep the format elegant.
1.12.7 official programming Guide for Scala
API download address: scala-api
At this point, the study on "how to build a Scala development environment under Windows" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.