In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to use Scala". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how to use Scala"!
syntax
Scala is a language that differs lexically from Java. Support for full symbols as naming, and named things, without any restrictions. It can be a method, function, class, trait, object, variable. At the beginning of contact, often confused by these symbols, and then fear. So why does scala support this feature?
Scala is completely object-oriented, unlike Java, which has primitive things.
Scala has no concept of operators, which are methods of objects (classes).
In order to better support domain specific languages (dsl), cooperate with other language features
keyword
When java programmers first contact scala, often feel more intimate, I think there are mainly the following reasons
Also running on JVM
Scala is rich in semantics, Java is relatively poor in semantics;scala can easily use any framework or component of the Java ecosystem
Familiar keywords
Familiarity is the illusion of surface, covering up the difference of essence.
The same keyword, most agree on different names, different usages, such as import
Scala keywords tend to be polysemous, and there are many common keywords that are polysemous. For example,_, in different lexical contexts, can have the following meanings: representing parameters in different positions, all, remove, ignore, etc. Others such as var, va, arrow symbol, with, class
Combination keywords: case class, this.type, sometimes from the perspective of Java language, or even two contradictory keywords to combine. Abstract Overwrite, Final Treat
expression
The expression must not be comparable to or equal to such concepts and characteristics as keywords
But it's also one of the obstacles, and most languages don't support it.
Prefix expression, suffix expression, infix expression under the premise of specific lexical and grammatical context
Prefix expression: -1, and this expression can be used by developers, such as you can! Point(x,y)
Suffix expression: Colon (ending method), such as/: :\in fold. buildSequenceFlow(maybeEnd.getOrElse(begin),rightEnd) +: rightEnd +: flowElements
Here the most deadly is the infix expression, when I saw this language feature, I was full of a lot of incomprehension. Do not understand this language support this feature exactly what?
One parameter method, all symbols are methods.
case class of two construction parameters
High Order Kind of Two Type Parameters
verb noun
In Java, verbs and nouns are distinct, verbs are methods, executable things. A noun is something that the data is executed on.
However, in scala, in addition to functions being first-class citizens, there is also apply object. These are enforceable nouns.
This will have a sense of confusion between hooligans and police, which are sheep, which are sheep? Difficulties even arise when naming things.
Add in other features of scala and it feels like chaos.
functional thinking
Scala supports both imperative object-oriented and declarative functional programming paradigms, but encourages preference for functional features such as val invariant sets.
The essence of the so-called functional formula is the combinability, management and delayed side effects of the functional formula.
Very familiar with Java's command-oriented object-oriented, design patterns know friends, here you need to start from scratch, and your past hard accumulation of knowledge, it is likely to become a shackle for you to learn new things.
Powerful pattern matching
Match in scala makes you feel great match is a tool for data processing, extremely convenient, and a lot of elimination of boilerplate code
But this name does not fully express the full meaning of this function. I understand that this name contains three functions: matching, matching and drawing.
However, due to the limitation of Java Virtual Machine (JVM), the full function of pattern matching is affected to some extent
In addition, pattern matching can be embodied not only by the keyword match case. It can also be used directly in assignment statements and with the for keyword
implicit system
Scala is a unique language feature, just a simple implicit keyword
Three basic semantics: implicit values, implicit views, implicit classes, and implicitly passing a combination of implicit values and implicit views
Implicit trigger conditions, which make implicit both simple and mysterious
Implicit simply exposes the underlying compiler techniques to developers to use, such as
Type conversion in Java
JavaScript: console.info(-"1" + 1), console.info("1" + 1)
Implicit alone is simple and limited. Combination with type systems, type system constraints on types, implicit context-child and view boundaries, implicit fields with precedence, mutual reinforcement
SBT
Maven in scala
Adhering to the characteristics of scala language: difficult to get started, after starting, love
Scala Learning
Scala Overview
It mainly talks about the origin of Scala language, the construction of the environment, and the decompilation structure of the simple scala code corresponding to the *.class file.
Scala variables
var, val, variable definition, Any, AnyRef, AnyVal, automatic conversion, basically similar to Java, but with details.
Operator and flow control
Arithmetic operation, assignment operation, comparison operation, logical operation, bit operation, sequence control, score control, loop control, scala does not have break and continue, scala does not recommend while and do-while
Fundamentals of functional programming Fundamentals of object-oriented programming
Scala function and method definitions, procedures, lazy functions, exceptions, access permissions, BeanProperty, private[this], object creation flow analysis.
Object Oriented Programming-Intermediate (Package, Abstract, Encapsulation, Inheritance, Abstract Class, Anonymous Subclass)
Scala packages exist in the same sense of flexibility as Python, package objects exist in the same sense as the underlying. Several characteristics of object-oriented, abstract-encapsulation-inheritance-polymorphism. primary constructor secondary constructor class component left to right, function invocation right to left.
Object Oriented Programming-Advanced (companion object, trait, self type, implicit)
Scala removed static keywords, trait existence meaning, interface+ abstract, self=>, nested classes, implicit use details.
Data structures-Collections
scala.collection.mutable, scala.collection.immutable(default). Array, ArrayBuffer, Tuple, List, Queue, Map, Set, mainly how to add, delete, and check.
Set Operations-Focus
map, flatMap, reduce, flod, scan, zip, iterator, stream, view, par, strong match pattern matching.
Functional Programming Advanced
Partial function three forms, advanced function, anonymous function =>, parameter inference, closure, currying, control abstraction
recursive thinking
Option This wrapper class exists in the sense that some concepts of recursion have been introduced into tail recursive optimization.
AKKA Web Programming Spark Registration Heartbeat
Introduction of AKKA framework, understanding of ideas, basic knowledge points of network programming, Master and Worker working mode.
Design patterns, generics, etc.
Design patterns, generics, upper and lower bounds, view-bound, context-bound, covariant contravariant invariant
WorkCount will
lines.flatMap(.split(" ")).map((, 1)).groupBy((_._ 1)).map(x => (x._ 1, x.2.size)).toList.sortBy(._ 2))
Scala and data structures
Loose array, queue, linked list, stack, recursion, sort, lookup, hash table, binary tree, binary sort tree, red-black tree, balanced binary tree, etc.
Purpose: Familiarize yourself with Scala programming patterns.
Scala Knowledge Point Small Exercise
Small demo
At this point, I believe that everyone has a deeper understanding of "how to use Scala," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
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.