SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (20)

PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
Collections - Lists, Sets
Collections - Lists, Sets Collections - Lists, Sets
Collections - Lists, Sets
 
Golang - Overview of Go (golang) Language
Golang - Overview of Go (golang) LanguageGolang - Overview of Go (golang) Language
Golang - Overview of Go (golang) Language
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
Introduction to Spring Boot
Introduction to Spring BootIntroduction to Spring Boot
Introduction to Spring Boot
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and Answer
 
Flutter
FlutterFlutter
Flutter
 
Introduction to elasticsearch
Introduction to elasticsearchIntroduction to elasticsearch
Introduction to elasticsearch
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java collection
Java collectionJava collection
Java collection
 
Advanced Python : Decorators
Advanced Python : DecoratorsAdvanced Python : Decorators
Advanced Python : Decorators
 
07 java collection
07 java collection07 java collection
07 java collection
 
Styled Components & React.js
Styled Components & React.jsStyled Components & React.js
Styled Components & React.js
 

En vedette (7)

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
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
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
 

Similaire à 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
 

Similaire à 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
 

Plus de 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
 

Plus de 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
 

Dernier

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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