Tuesday, October 2, 2018

Scala Basics


What is Scala?

Scala is a general-purpose programming language providing support for functional programming and a strong static type system.



Basic Understanding & Implementation - Scala on Mac

This is my step by step guide to installing Scala macOS Sierra.
Package Manager: Home Brew
Java: Verify that you have java instaled. Couple of ways to verify it:
1 - java -version
openjdk version "1.8.0-adoptopenjdk"
OpenJDK Runtime Environment (build 1.8.0-adoptopenjdk-jenkins_2018_05_19_02_01-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)
2 - which java
/usr/local/bin/java

Installation


$brew update
Updated Homebrew from bd09f934f to 9141b1509.
Updated 3 taps (homebrew/cask-versions, homebrew/core and homebrew/cask).
==> Updated Formulae
jenkins                   convox                      exploitdb                   git-secret                  grpc                        openconnect                 tcl-tk                      youtube-dl
azure-cli                   dartsim                     git-open                    gnatsd                      mackup                      squashfs                    terraform-docs
==> Deleted Formulae


hyper

$ brew install scala
Warning: scala 2.12.8 is already installed and up-to-date


To reinstall 2.12.8, run `brew reinstall scala`

$ brew reinstall scala
==> Reinstalling scala 
==> Downloading https://downloads.lightbend.com/scala/2.12.8/scala-2.12.8.tgz
Already downloaded: /Users/kinshukdutta/Library/Caches/Homebrew/downloads/4ffc2f15737ba9118ee6050ae3b7f1c997a2ff246a51edea3e4a662c85c4cc13--scala-2.12.8.tgz
==> Caveats
To use with IntelliJ, set the Scala home to:
  /usr/local/opt/scala/idea
==> Summary
🍺  /usr/local/Cellar/scala/2.12.8: 43 files, 20.8MB, built in 5 seconds

$ brew install sbt
==> Downloading https://github.com/sbt/sbt/releases/download/v1.2.8/sbt-1.2.8.tgz
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/279553/ae845a00-0be0-11e9-99d2-03a5afa9f1c7?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20190117%2Fus-east-1%2Fs3%2
######################################################################## 100.0%
==> Caveats
You can use $SBT_OPTS to pass additional JVM options to sbt.
Project specific options should be placed in .sbtopts in the root of your project.
Global settings should be placed in /usr/local/etc/sbtopts
==> Summary


🍺  /usr/local/Cellar/sbt/1.2.8: 521 files, 50MB, built in 12 seconds


echo '-J-XX:+CMSClassUnloadingEnabled' >> /usr/local/etc/sbtopts
echo '-J-Xmx4G' >> /usr/local/etc/sbtopts


Scala Plugin for Eclipse

Scala IDE for Eclipse is best installed (and updated) directly from within Eclipse.
This is done by using Help → Install New Software..., add the Add... button in the dialog.
Choose a name for the update site (Scala IDE). Then follow the instructions on screen.

Scala Basics!!


In order to learn the basics of Scala we will be using Scala REPL

The Scala REPL is a An informative tool that logs messages on how our code is interpreted and executed
The scala command will execute a source script by wrapping it in a template and then compiling and executing the resulting program.
In interactive mode, the REPL reads expressions at the prompt, wraps them in an executable template, and then compiles and executes the result.
Previous results are automatically imported into the scope of the current expression as required.
The REPL also provides some command facilities, described below.
An alternative REPL is available in the Ammonite project, which also provides a richer shell evironment.


Values & Variables



Kinshuk Dutta
New York

Scala & Spark for Managing & Analyzing Big Data (Using Machine Learning)

Managing & Analyzing Big Data using Apache Scala & Apache Spark In this blog we will see how to use Scala and Spark to analyze Big D...