There are 3 parts in Scala program-
a) Class
definition,
b) Main()
function and
c) Print
statement.
Before writing Scala Programming Language, we need to know basic Scala concepts:
Basic Scala Concepts |
Meaning |
Example |
Class |
a blueprint that defines the states and behaviors
related to it. |
Fields, variables, function objects, methods |
Object |
an instance of a Class. it has states and
behavior. It is created using the new
keyword. |
var obj = new Class(); |
Methods |
a block of code that can perform a certain amount
of tasks. |
def methodName (parameters) : (return Type) |
Fields |
variables defined inside the Class body. states
of Objects. |
Mutable fields (var) and Immutable fields (val). |
Closure |
a function whose value depends on the value of
multiple variables that are declared outside the function. |
val multiplier = (i:Int) => i * 10 |
Traits |
just like
classes they have fields and methods but multiple traits can be used
together(inherited) to increase the functionality of a class. |
trait trait_name { |
Wrapper Class |
used to put primitive data value into an object. |
Byte, Short, Integer, Long, Float, Double,
Character, Boolean |
Identifiers |
are the names given to a class, method, variable
or object to identify them in the program. |
myObject, main, args, value1. etc. (not keywords
/ digits) |
Code block |
multiple lines of code that have only one entry
and one exit point. |
{ } used in methods, class definition, loop
statements and logic. |
Variables |
reference to a memory location where data is
stored. |
val, var & lazy. |
Data Types |
tells the compiler about the type of data that is
used by the programmer. |
Boolean, Integer,
Float, Double, Char, String, Nothing, Any, anyRef, anyVar, etc. |
any' class |
Superclass of all classes in Scala. Root of the class hierarchy. |
Two subclasses they are: 1) anyRef, 2) anyVar |
Nothing |
subtype of all types in Scala. |
Nothing is a subtype of Char, Float, Int. |
Lazy variable |
saves memory when variables declared are not used
while object creation. |
lazy val |
Type interface |
used to make the declaration of data type
optional. |
compilers work to detect the data type. |
Operators |
tell the compiler to perform a specific
operation. |
Plus (+), And (&), Or (I), etc. |
Numeric type |
deals with all types that are stored in Integers
and Decimals. |
Float, Double, Int, Short, Long |
Unit type |
used as a return statement for a function when no
value is to be returned. |
compared
to void data type and is a subclass of anytype trait. |
Option |
container that contains one single value which
can be one of the two distinct values. |
One of the two values is 'none' and others can be
any object valid in the program. |
Basic program |
three parts - the Class definition, Main()
function and the Print statement. |
object MyClass { |
Method parameters |
hose variables which are passed to the method
while calling the method. |
add(a:Int , b:Int) |
Literals |
basic constants value that can be assigned to a
variable. |
var i = 10L; var I = 123.54d |
Expressions |
A line of
code that can be compiled and has some resultant value. These are displayed
on screen using println statements. |
println(45 * 24332); |
Function |
a reusable chunk of code that can perform the
operation on the value passed as a parameter. |
val result = (mark: Float ) |
Block |
multiple statements that are enclosed between
curly braces. |
{ // statement
1 |
SCALA is the short form of Scalable language developed by Martin Odersky (German Computer Scientist) in 2003. Generally, we use Scala language within SPARK framework for good performance to process the large amount of data.
Scala
programming is a general-purpose computer language that supports both Object-oriented
and Functional styles of programming on a larger scale. The functional programming allows it to take advantage of multi-core CPU
architecture whereas the object-oriented programming allows it to you takes
care of interoperability and some code features of objects.
Main topics covered in Data Analytics are
a) Big Data Architecture
b) HADOOP
c) SQOOP
d) HIVE
e) SCALA
f) SPARK
g) HBASE
h) KAFKA
i) AWS
j) AZURE
We deal with Data on day-to-day basis whether be an Individual Social / Personal Data or an Organizational Business data. So, to store the Data, it needs to be processed from time-to-time. This is how Data Processing comes into picture which is of 2 types:
1) Transactional System Data (OLTP)
2) Analytical System Data (OLAP)