The increasing popularity and availability of multicore processors is creating a whole new set of challenges--although you can enjoy true concurrency, you're now faced with higher contention and synchronization issues. Deploying an existing application on a multicore processor may bring out previously hidden concurrency issues. Java's multi-threading facility by itself isn't enough---it's a very low level abstraction. Instead, you need a paradigm that provides a higher level of abstraction to deal with concurrency. It's time to embrace Functional Programming. Scala is a hybrid Object-Oriented/Functional Programming language on the JVM. Using Scala, you can create traditional imperative programs, intermix them with Java code, and at the same time take advantage of higher levels of abstraction. You can use features that lead to concise, highly expressive code that remove the pain of dealing with concurrency.Programming Scala will show you the fundamentals of functional programming using Scala. Very quickly, you'll learn how this statically typed language can give you dynamic capabilities to create concise, scalable, highly capable concurrent code. Pragmatic programmers always use the right tool for the job. For concurrent programming on the Java VM, Scala is the tool, and Programming Scala by award-winning author Venkat Subramaniam is your guide.
Author(s): Venkat Subramaniam
Edition: 1
Publisher: Pragmatic Bookshelf
Year: 2009
Language: English
Pages: 226
Contents......Page 7
Why Scala?......Page 11
What's Scala?......Page 14
Functional Programming......Page 19
What's in This Book?......Page 22
Acknowledgments......Page 24
Downloading Scala......Page 26
Installing Scala......Page 27
Take Scala for a Ride......Page 28
Scala on the Command Line......Page 30
Running Scala Code as a Script......Page 31
Compiling Scala......Page 32
Scala as Concise Java......Page 34
Scala Classes for Java Primitives......Page 37
Tuples and Multiple Assignments......Page 38
Strings and Multiline Raw Strings......Page 40
Sensible Defaults......Page 41
Operator Overloading......Page 43
Scala Surprises for the Java Eyes......Page 45
Creating Classes......Page 53
Defining Fields, Methods, and Constructors......Page 54
Extending a Class......Page 57
Singleton Object......Page 58
Stand-Alone and Companion Objects......Page 60
static in Scala......Page 61
Sensible Typing......Page 63
Collections and Type Inference......Page 64
The Any Type......Page 66
More About Nothing......Page 67
Option Type......Page 68
Method Return Type Inference......Page 69
Passing Variable Arguments (Varargs)......Page 70
Variance of Parameterized Type......Page 71
Moving from Normal to Higher-Order Functions......Page 75
Function Values......Page 76
Function Values with Multiple Parameters......Page 78
Currying......Page 80
Reusing Function Values......Page 81
Positional Notation for Parameters......Page 83
Execute Around Method Pattern......Page 84
Partially Applied Functions......Page 87
Closures......Page 88
Traits......Page 91
Selective Mixins......Page 94
Decorating with Traits......Page 95
Method Late Binding in Traits......Page 97
Implicit Type Conversions......Page 99
Common Scala Collections......Page 103
Using a Set......Page 104
Using a Map......Page 106
Using a List......Page 108
The for Expression......Page 113
Matching Literals and Constants......Page 116
Matching a Wildcard......Page 117
Matching Tuples and Lists......Page 118
Matching with Types and Guards......Page 119
Pattern Variables and Constants in case Expressions......Page 120
Matching Using case Classes......Page 121
Matching Using Extractors......Page 124
Regular Expressions......Page 128
Regular Expressions as Extractors......Page 129
Promote Immutability......Page 131
Concurrency Using Actor......Page 133
Message Passing......Page 137
The Actor Class......Page 139
The actor Method......Page 141
receive and receiveWithin Methods......Page 144
react and reactWithin Methods......Page 146
loop and loopWhile......Page 151
Controlling Thread of Execution......Page 153
Choosing Among the Receive Methods......Page 154
Using Scala Classes in Scala......Page 156
Using Java Classes in Scala......Page 159
Using Scala Classes in Java......Page 161
Extending Classes......Page 165
Using JUnit......Page 167
Start with a Canary Test......Page 169
Using Runner......Page 170
Asserts......Page 172
Exception Tests......Page 174
Sharing Code Between Tests......Page 176
Functional Style with FunSuite......Page 178
Running ScalaTests Using JUnit......Page 179
Exception Handling......Page 183
Mind the Catch Order......Page 186
Getting Users' Input......Page 187
Reading and Writing Files......Page 188
XML as a First-Class Citizen......Page 190
Reading and Writing XML......Page 193
Getting Stock Prices from the Web......Page 196
Making the Net Asset Application Concurrent......Page 199
Putting a GUI on the Net Asset Application......Page 201
Web Resources......Page 211
Bibliography......Page 213
A......Page 215
C......Page 216
F......Page 217
M......Page 218
O......Page 219
S......Page 220
U......Page 221
Y......Page 222