SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Introduction to Scala
August 2014 Meetup
Rahul Jain
@rahuldausa
Agenda
• Introduction to Functional
Programming
• Basics of Scala
• Scala Use-casses
• Examples
• Code Samples/Walk-through
2
Function Programming
• programs are executed by evaluating expressions, in
contrast with imperative programming where
programs are composed of statements which change
global state when executed. Functional programming
typically avoids using mutable state.
• Functional programming requires that functions
are first-class, which means that they are treated like
any other values and can be passed as arguments to
other functions or be returned as a result of a function.
• Being first-class also means that it is possible to define
and manipulate functions from within other functions.
About Scala
• Scala, short for Scalable Language, is a hybrid
functional programming language
• created by Martin Odersky and it was first
released in 2003.
• features of object-oriented and functional
languages
• run on the Java Virtual Machine
• Not a statically typed language
• www.scala-lang.org
Scala IDE
• Eclipse:
– http://scala-ide.org/
• IntelliJIdea :
– http://www.jetbrains.com/idea/features/scala.ht
ml
Scala in the Enterprise
• The Scala programming language is used by many
companies to develop commercial software and
production systems
• For e.g. :
– LinkedIn, EDFT,Twitter, Novell, the
Guardian, Xebia, Xerox, FourSquare, Sony, Siemens, Th
atcham, OPower, GridGain, AppJet, Reaktorand
many others.
• http://www.scala-lang.org/old/node/1658.html
• http://www.quora.com/Startups/What-startups-
or-tech-companies-are-using-Scala
Credit: http://alvinalexander.com/scala/whos-using-scala-akka-play-framework
Popular Frameworks built on Scala
• Akka
• Play framework
• Lift web
• Apache Kafka
• Scalding (from twitter)
• Gizzard (from twitter)
• Kestrel
• and many more…
Data Types
Byte : 8 bit signed value. Range from -128 to 127
Short : 16 bit signed value. Range -32768 to 32767
Int : 32 bit signed value. Range -2147483648 to 2147483647
Long : 64 bit signed value. -9223372036854775808 to 9223372036854775807
Float : 32 bit IEEE 754 single-precision float
Double : 64 bit IEEE 754 double-precision float
Char : 16 bit unsigned Unicode character. Range from U+0000 to U+FFFF
String : A sequence of Chars
Boolean : Either the literal true or the literal false
Unit: Corresponds to no value : void
Null: null or empty reference
Nothing : The subtype of every other type; includes no values
Any: The supertype of any type; any object is of type Any : Java's Object class
AnyRef: The supertype of any reference type
How to Install
Setting up the development
Environment
• http://www.scala-lang.org/download/
• C:>scala -version
Scala code runner version 2.10.4 -- Copyright 2002-2013, LAMP/EPFL
• C:>scala
Welcome to Scala version 2.10.4 (Java HotSpot(TM) Client VM, Java
1.7.0_51).
Type in expressions to have them evaluated.
Type :help for more information.
• scala> println("Hello, Scala!");
Hello, Scala!
Compile and Run
• Compile
– scalac HelloWorld.scala
– C:> scalac HelloWorld.scala
• Run
– C:> scala HelloWorld
– Hello, World!
Sample Program
object Test {
def main(args: Array[String]){
println("hello world");
}
def Hello(args:Array[String]){
println("hello scala");
}
this.Hello(null);
}
Function
object <name> extends App {
def <function_name>(var_name: <var_type>, var_name: <var_type>):
<return_type>= {
}
}
object Sum extends App {
def sumInt(x: Int, y: Int): Int = {
x + y //return the sum of two values
}
println("Sum of 1 and 2: " + sumInt(1, 2))
}
Sum
object Sum extends App {
def sumInt(x: Int, y: Int): Int = {
x + y //return the sum of two values
}
println("Sum of 1 and 2: " + sumInt(1, 2))
}
Unit’s Example
object UnitTest extends App {
def greetMe(): Unit = {
println("Greetings !!!")
}
def greetMeByName(name: String): Unit = {
println("Hey " + name)
}
greetMe // print Greetings !!!
greetMeByName("John") // print Hey John
}
object & class
• class
– A class is a definition, a description. It defines a type in
terms of methods and composition of other types.
• Object
– An object is a singleton -- an instance of a class which is
guaranteed to be unique. For every object in the code, an
anonymous class is created, which inherits from whatever
classes you declared object to implement. This class
cannot be seen from Scala source code -- though you can
get at it through reflection.
• You can think of the "object" keyword creating a
Singleton object of a class, that is defined implicitly.
object & class
e.g.
• object A extends B with C
– This will declare an anonymous class which
extends B with the trait C and create a single
instance of this class named A.
• http://stackoverflow.com/questions/1755345/
scala-difference-between-object-and-class
Scala Keywords (Reserved)
• Can not be used as constant or variable or any other
identifier names.
abstract case catch class
def do else extends
false final finally for
forSome if implicit import
lazy match new null
object override package private
protected return sealed super
this throw trait try
true type val var
while with yield
- : = =>
<- <: <% >:
#@
Scala packages import
• import scala.xml._
– imports the contents of the scala.xml package
• import scala.collection.mutable.HashMap
– You can import a single class and object, for example,
HashMap from the scala.collection.mutable package
• import scala.collection.immutable.{TreeMap, TreeSet}
– You can import more than one class or object from a single
package, for example, TreeMap and TreeSet from the
scala.collection.immutable package:
Multi line Strings
• multi-line string literal is a sequence of
characters enclosed in triple quotes """ ... ""“
• For e.g. :
– """the present string
spans three
lines."""
var vs val
• var refers to a variable that can change value
– mutable variable
– var myVar : String = "Foo"
• val refers to a variable that can not change
value
– Immutable variable
– val myVal : String = "Foo“
– Equivalent to Java’s final
Scala’s Null
• null value is of type scala.Null
• compatible with every reference type.
• denotes a reference value which refers to a
special "null" object.
Scala vs Java
• All types are objects.
• Type inference.
• Nested Functions.
• Functions are objects.
• Domain specific language (DSL) support.
• Traits.
• Closures.
• Concurrency support inspired by Erlang.
Advanced Concepts
• Pattern matching
• Tail recursion
• Large library of list functions
• Functional dictionary class
• Automatic currying
• Concise way to compose functions
• Lazy lists
Questions ?
26
Thanks!
@rahuldausa on twitter and slideshare
http://www.linkedin.com/in/rahuldausa
Interested in Search/Information Retrieval ?
Join us @ http://www.meetup.com/Hyderabad-Apache-Solr-Lucene-Group/
27

Weitere ähnliche Inhalte

Was ist angesagt?

Big Data Processing with Spark and Scala
Big Data Processing with Spark and Scala Big Data Processing with Spark and Scala
Big Data Processing with Spark and Scala Edureka!
 
Flink history, roadmap and vision
Flink history, roadmap and visionFlink history, roadmap and vision
Flink history, roadmap and visionStephan Ewen
 
Loki - like prometheus, but for logs
Loki - like prometheus, but for logsLoki - like prometheus, but for logs
Loki - like prometheus, but for logsJuraj Hantak
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flinkmxmxm
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internalsKostas Tzoumas
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformJean-Paul Azar
 
Serverless integration with Knative and Apache Camel on Kubernetes
Serverless integration with Knative and Apache Camel on KubernetesServerless integration with Knative and Apache Camel on Kubernetes
Serverless integration with Knative and Apache Camel on KubernetesClaus Ibsen
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceDatabricks
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?confluent
 
Введение в maven
Введение в mavenВведение в maven
Введение в mavenDmitry Zinushin
 
Log management with ELK
Log management with ELKLog management with ELK
Log management with ELKGeert Pante
 
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...Edureka!
 
Programming in Spark using PySpark
Programming in Spark using PySpark      Programming in Spark using PySpark
Programming in Spark using PySpark Mostafa
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelClaus Ibsen
 
An Introduction to Apache Kafka
An Introduction to Apache KafkaAn Introduction to Apache Kafka
An Introduction to Apache KafkaAmir Sedighi
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Edureka!
 
Apache Camel v3, Camel K and Camel Quarkus
Apache Camel v3, Camel K and Camel QuarkusApache Camel v3, Camel K and Camel Quarkus
Apache Camel v3, Camel K and Camel QuarkusClaus Ibsen
 

Was ist angesagt? (20)

Big Data Processing with Spark and Scala
Big Data Processing with Spark and Scala Big Data Processing with Spark and Scala
Big Data Processing with Spark and Scala
 
Flink history, roadmap and vision
Flink history, roadmap and visionFlink history, roadmap and vision
Flink history, roadmap and vision
 
Loki - like prometheus, but for logs
Loki - like prometheus, but for logsLoki - like prometheus, but for logs
Loki - like prometheus, but for logs
 
Introduction to Apache Flink
Introduction to Apache FlinkIntroduction to Apache Flink
Introduction to Apache Flink
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platform
 
Serverless integration with Knative and Apache Camel on Kubernetes
Serverless integration with Knative and Apache Camel on KubernetesServerless integration with Knative and Apache Camel on Kubernetes
Serverless integration with Knative and Apache Camel on Kubernetes
 
Introducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data ScienceIntroducing DataFrames in Spark for Large Scale Data Science
Introducing DataFrames in Spark for Large Scale Data Science
 
Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?Kafka Streams: What it is, and how to use it?
Kafka Streams: What it is, and how to use it?
 
Введение в maven
Введение в mavenВведение в maven
Введение в maven
 
Log management with ELK
Log management with ELKLog management with ELK
Log management with ELK
 
Dive into PySpark
Dive into PySparkDive into PySpark
Dive into PySpark
 
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
 
Programming in Spark using PySpark
Programming in Spark using PySpark      Programming in Spark using PySpark
Programming in Spark using PySpark
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
An Introduction to Apache Kafka
An Introduction to Apache KafkaAn Introduction to Apache Kafka
An Introduction to Apache Kafka
 
Quarkus k8s
Quarkus   k8sQuarkus   k8s
Quarkus k8s
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
 
Apache Camel v3, Camel K and Camel Quarkus
Apache Camel v3, Camel K and Camel QuarkusApache Camel v3, Camel K and Camel Quarkus
Apache Camel v3, Camel K and Camel Quarkus
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 

Andere mochten auch

Andere mochten auch (6)

Scala and spark
Scala and sparkScala and spark
Scala and spark
 
Spark workshop
Spark workshopSpark workshop
Spark workshop
 
Apache spark Intro
Apache spark IntroApache spark Intro
Apache spark Intro
 
Scala Intro
Scala IntroScala Intro
Scala Intro
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 

Ähnlich wie Introduction to Scala

Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryPray Desai
 
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabCloudxLab
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed OverviewBuddha Tree
 
Learning core java
Learning core javaLearning core java
Learning core javaAbhay Bharti
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptxVijalJain3
 
chapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxchapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxnafsigenet
 
java02.ppt
java02.pptjava02.ppt
java02.pptMENACE4
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.pptkavitamittal18
 
Java basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programmingJava basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programmingkalirajonline
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.pptNadiSarj2
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.pptJemarManatad1
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.pptSquidTurbo
 

Ähnlich wie Introduction to Scala (20)

Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
 
Java
JavaJava
Java
 
ppt_on_java.pptx
ppt_on_java.pptxppt_on_java.pptx
ppt_on_java.pptx
 
Intro to Scala
 Intro to Scala Intro to Scala
Intro to Scala
 
Java
Java Java
Java
 
Java
JavaJava
Java
 
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLabIntroduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
Introduction to Scala | Big Data Hadoop Spark Tutorial | CloudxLab
 
Java core - Detailed Overview
Java  core - Detailed OverviewJava  core - Detailed Overview
Java core - Detailed Overview
 
Scala-Ls1
Scala-Ls1Scala-Ls1
Scala-Ls1
 
Learning core java
Learning core javaLearning core java
Learning core java
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
chapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptxchapter 1-overview of java programming.pptx
chapter 1-overview of java programming.pptx
 
java02.ppt
java02.pptjava02.ppt
java02.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
Java basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programmingJava basics with datatypes, object oriented programming
Java basics with datatypes, object oriented programming
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 
lecture-a-java-review.ppt
lecture-a-java-review.pptlecture-a-java-review.ppt
lecture-a-java-review.ppt
 

Mehr von Rahul Jain

Flipkart Strategy Analysis and Recommendation
Flipkart Strategy Analysis and RecommendationFlipkart Strategy Analysis and Recommendation
Flipkart Strategy Analysis and RecommendationRahul Jain
 
Emerging technologies /frameworks in Big Data
Emerging technologies /frameworks in Big DataEmerging technologies /frameworks in Big Data
Emerging technologies /frameworks in Big DataRahul Jain
 
Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )Rahul Jain
 
Building a Large Scale SEO/SEM Application with Apache Solr
Building a Large Scale SEO/SEM Application with Apache SolrBuilding a Large Scale SEO/SEM Application with Apache Solr
Building a Large Scale SEO/SEM Application with Apache SolrRahul Jain
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkRahul Jain
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache SparkRahul Jain
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine LearningRahul Jain
 
What is NoSQL and CAP Theorem
What is NoSQL and CAP TheoremWhat is NoSQL and CAP Theorem
What is NoSQL and CAP TheoremRahul Jain
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneRahul Jain
 
Introduction to Apache Lucene/Solr
Introduction to Apache Lucene/SolrIntroduction to Apache Lucene/Solr
Introduction to Apache Lucene/SolrRahul Jain
 
Introduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and UsecasesIntroduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and UsecasesRahul Jain
 
Introduction to Kafka and Zookeeper
Introduction to Kafka and ZookeeperIntroduction to Kafka and Zookeeper
Introduction to Kafka and ZookeeperRahul Jain
 
Hadoop & HDFS for Beginners
Hadoop & HDFS for BeginnersHadoop & HDFS for Beginners
Hadoop & HDFS for BeginnersRahul Jain
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginnersRahul Jain
 

Mehr von Rahul Jain (15)

Flipkart Strategy Analysis and Recommendation
Flipkart Strategy Analysis and RecommendationFlipkart Strategy Analysis and Recommendation
Flipkart Strategy Analysis and Recommendation
 
Emerging technologies /frameworks in Big Data
Emerging technologies /frameworks in Big DataEmerging technologies /frameworks in Big Data
Emerging technologies /frameworks in Big Data
 
Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )Case study of Rujhaan.com (A social news app )
Case study of Rujhaan.com (A social news app )
 
Building a Large Scale SEO/SEM Application with Apache Solr
Building a Large Scale SEO/SEM Application with Apache SolrBuilding a Large Scale SEO/SEM Application with Apache Solr
Building a Large Scale SEO/SEM Application with Apache Solr
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache Spark
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Introduction to Machine Learning
Introduction to Machine LearningIntroduction to Machine Learning
Introduction to Machine Learning
 
What is NoSQL and CAP Theorem
What is NoSQL and CAP TheoremWhat is NoSQL and CAP Theorem
What is NoSQL and CAP Theorem
 
Introduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of LuceneIntroduction to Elasticsearch with basics of Lucene
Introduction to Elasticsearch with basics of Lucene
 
Introduction to Apache Lucene/Solr
Introduction to Apache Lucene/SolrIntroduction to Apache Lucene/Solr
Introduction to Apache Lucene/Solr
 
Introduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and UsecasesIntroduction to Lucene & Solr and Usecases
Introduction to Lucene & Solr and Usecases
 
Introduction to Kafka and Zookeeper
Introduction to Kafka and ZookeeperIntroduction to Kafka and Zookeeper
Introduction to Kafka and Zookeeper
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Hadoop & HDFS for Beginners
Hadoop & HDFS for BeginnersHadoop & HDFS for Beginners
Hadoop & HDFS for Beginners
 
Hibernate tutorial for beginners
Hibernate tutorial for beginnersHibernate tutorial for beginners
Hibernate tutorial for beginners
 

Kürzlich hochgeladen

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Kürzlich hochgeladen (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Introduction to Scala

  • 1. Introduction to Scala August 2014 Meetup Rahul Jain @rahuldausa
  • 2. Agenda • Introduction to Functional Programming • Basics of Scala • Scala Use-casses • Examples • Code Samples/Walk-through 2
  • 3. Function Programming • programs are executed by evaluating expressions, in contrast with imperative programming where programs are composed of statements which change global state when executed. Functional programming typically avoids using mutable state. • Functional programming requires that functions are first-class, which means that they are treated like any other values and can be passed as arguments to other functions or be returned as a result of a function. • Being first-class also means that it is possible to define and manipulate functions from within other functions.
  • 4. About Scala • Scala, short for Scalable Language, is a hybrid functional programming language • created by Martin Odersky and it was first released in 2003. • features of object-oriented and functional languages • run on the Java Virtual Machine • Not a statically typed language • www.scala-lang.org
  • 5. Scala IDE • Eclipse: – http://scala-ide.org/ • IntelliJIdea : – http://www.jetbrains.com/idea/features/scala.ht ml
  • 6. Scala in the Enterprise • The Scala programming language is used by many companies to develop commercial software and production systems • For e.g. : – LinkedIn, EDFT,Twitter, Novell, the Guardian, Xebia, Xerox, FourSquare, Sony, Siemens, Th atcham, OPower, GridGain, AppJet, Reaktorand many others. • http://www.scala-lang.org/old/node/1658.html • http://www.quora.com/Startups/What-startups- or-tech-companies-are-using-Scala
  • 8. Popular Frameworks built on Scala • Akka • Play framework • Lift web • Apache Kafka • Scalding (from twitter) • Gizzard (from twitter) • Kestrel • and many more…
  • 9. Data Types Byte : 8 bit signed value. Range from -128 to 127 Short : 16 bit signed value. Range -32768 to 32767 Int : 32 bit signed value. Range -2147483648 to 2147483647 Long : 64 bit signed value. -9223372036854775808 to 9223372036854775807 Float : 32 bit IEEE 754 single-precision float Double : 64 bit IEEE 754 double-precision float Char : 16 bit unsigned Unicode character. Range from U+0000 to U+FFFF String : A sequence of Chars Boolean : Either the literal true or the literal false Unit: Corresponds to no value : void Null: null or empty reference Nothing : The subtype of every other type; includes no values Any: The supertype of any type; any object is of type Any : Java's Object class AnyRef: The supertype of any reference type
  • 11. Setting up the development Environment • http://www.scala-lang.org/download/ • C:>scala -version Scala code runner version 2.10.4 -- Copyright 2002-2013, LAMP/EPFL • C:>scala Welcome to Scala version 2.10.4 (Java HotSpot(TM) Client VM, Java 1.7.0_51). Type in expressions to have them evaluated. Type :help for more information. • scala> println("Hello, Scala!"); Hello, Scala!
  • 12. Compile and Run • Compile – scalac HelloWorld.scala – C:> scalac HelloWorld.scala • Run – C:> scala HelloWorld – Hello, World!
  • 13. Sample Program object Test { def main(args: Array[String]){ println("hello world"); } def Hello(args:Array[String]){ println("hello scala"); } this.Hello(null); }
  • 14. Function object <name> extends App { def <function_name>(var_name: <var_type>, var_name: <var_type>): <return_type>= { } } object Sum extends App { def sumInt(x: Int, y: Int): Int = { x + y //return the sum of two values } println("Sum of 1 and 2: " + sumInt(1, 2)) }
  • 15. Sum object Sum extends App { def sumInt(x: Int, y: Int): Int = { x + y //return the sum of two values } println("Sum of 1 and 2: " + sumInt(1, 2)) }
  • 16. Unit’s Example object UnitTest extends App { def greetMe(): Unit = { println("Greetings !!!") } def greetMeByName(name: String): Unit = { println("Hey " + name) } greetMe // print Greetings !!! greetMeByName("John") // print Hey John }
  • 17. object & class • class – A class is a definition, a description. It defines a type in terms of methods and composition of other types. • Object – An object is a singleton -- an instance of a class which is guaranteed to be unique. For every object in the code, an anonymous class is created, which inherits from whatever classes you declared object to implement. This class cannot be seen from Scala source code -- though you can get at it through reflection. • You can think of the "object" keyword creating a Singleton object of a class, that is defined implicitly.
  • 18. object & class e.g. • object A extends B with C – This will declare an anonymous class which extends B with the trait C and create a single instance of this class named A. • http://stackoverflow.com/questions/1755345/ scala-difference-between-object-and-class
  • 19. Scala Keywords (Reserved) • Can not be used as constant or variable or any other identifier names. abstract case catch class def do else extends false final finally for forSome if implicit import lazy match new null object override package private protected return sealed super this throw trait try true type val var while with yield - : = => <- <: <% >: #@
  • 20. Scala packages import • import scala.xml._ – imports the contents of the scala.xml package • import scala.collection.mutable.HashMap – You can import a single class and object, for example, HashMap from the scala.collection.mutable package • import scala.collection.immutable.{TreeMap, TreeSet} – You can import more than one class or object from a single package, for example, TreeMap and TreeSet from the scala.collection.immutable package:
  • 21. Multi line Strings • multi-line string literal is a sequence of characters enclosed in triple quotes """ ... ""“ • For e.g. : – """the present string spans three lines."""
  • 22. var vs val • var refers to a variable that can change value – mutable variable – var myVar : String = "Foo" • val refers to a variable that can not change value – Immutable variable – val myVal : String = "Foo“ – Equivalent to Java’s final
  • 23. Scala’s Null • null value is of type scala.Null • compatible with every reference type. • denotes a reference value which refers to a special "null" object.
  • 24. Scala vs Java • All types are objects. • Type inference. • Nested Functions. • Functions are objects. • Domain specific language (DSL) support. • Traits. • Closures. • Concurrency support inspired by Erlang.
  • 25. Advanced Concepts • Pattern matching • Tail recursion • Large library of list functions • Functional dictionary class • Automatic currying • Concise way to compose functions • Lazy lists
  • 27. Thanks! @rahuldausa on twitter and slideshare http://www.linkedin.com/in/rahuldausa Interested in Search/Information Retrieval ? Join us @ http://www.meetup.com/Hyderabad-Apache-Solr-Lucene-Group/ 27