Mastering Scala: A Beginner's Guide

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Scala is a multi-paradigm, general-purpose scripting language. It is a completely object-oriented programming (OOP) language that supports the functional programming (FP) technique. Programs written in Scala may be translated into bytecodes and run on the Java Virtual Machine (JVM). Scalable language is referred to as Scala. Runtimes for jаvascript are also accessible. Java and other programming languages like Lisp, Haskell, Pizza, and others have had a significant effect on Scala. Concise and easy to understand, Mastering Scala: A Beginner’s Guide covers a comprehensive understanding of Scala and its components, libraries, and advance concepts to help readers quickly advance with the necessary information. The popularity of Scala among programmers is influenced by a number of variables. The advantages of using Scala are as follows: • Simple to start with: Scala is a high-level programming language that is comparable to well-known ones like Java, C, and C++. Scala learning becomes incredibly easy for everyone as a result. For Java programmerslearning Scala is easier. • Contains the best features: Scala enhances usability, scalability, and productivity by incorporating features from other languages such as C, C++, Java, etc. • Java and Scala are closely integrated: The source code for Scala was written such that its compiler could understand Java classes. Additionally, its compiler is capable of using Java libraries, frameworks, and other tools. Scala programs can run on the JVM after compilation. • Web-based and desktop application development: It offers support for web apps by compiling jаvascript. Similarly, it is possible to compile desktop apps to JVM bytecode. • Utilized by major corporations: The majority of well-known corporations, including Apple, Twitter, Walmart, Google, etc., migrate the majority of their code from other languages to Scala because it is highly scalable and suitable for usage in backend operations. People frequently mistake Scala for a Java extension. But this is not the case. It is just fully compatible with Java. After successful compilation, Scala programs are translated into .class files containing Java Byte Code and may subsequently be launched on JVM. This book provides functional approaches for solving queries using Scala. The fundamental principles of Scala explained here are helpful to beginner and intermediate users interested in learning this highly technical and diverse language. Key Features: Follows a hands-on approach and offers practical lessons and tutorials related to Scala Includes detailed tutorials meant for beginners to Scala Discusses Scala in-depth to help build robust knowledge

Author(s): Sufyan bin Uzayr
Series: master computer science
Publisher: CRC Press
Year: 2023

Language: English
Pages: 352

Cover
Half Title
Series Page
Title Page
Copyright Page
Dedication
Contents
About the Editor
Acknowledgments
Zeba Academy – Mastering Computer Science
CHAPTER 1: Scala Overview
SCALA’S EVOLUTION
VERSIONS OF SCALA
SCALA’S POPULARITY
WHY USE SCALA?
SCALA’S TOP 10 USES
SCALA’S ADVANTAGES OVER JAVA
START WITH SCALA PROGRAMMING
SCALA FEATURES
ADVANTAGES
DISADVANTAGES
APPLICATIONS
AN INTRIGUING FACT ABOUT SCALA
SETTING UP THE SCALA ENVIRONMENT
SCALA INSTALLATION IN LINUX
VERIFYING JAVA PACKAGES
SCALA DOWNLOAD AND INSTALLATION
Scala Download
WHAT CAUSES SCALA TO BE SCALABLE?
HELLO WORLD IN SCALA
HOW TO EXECUTE A SCALA PROGRAM
UNIFORM ACCESS PRINCIPLE IN SCALA
SCALA VS. JAVA
PYTHON VS. SCALA
THE DISTINCTION BETWEEN KOTLIN AND SCALA
REPL IN SCALA
REPL IMPLEMENTATION
SOME ADDITIONAL IMPORTANT REPL CHARACTERISTICS
CHAPTER 2: Scala Basics
KEYWORDS IN SCALA
IDENTIFIERS IN SCALA
JAVA SCALA DEFINING RULES
SCALA IDENTIFIER TYPES
SCALA DATA TYPES
LITERALS IN SCALA
SCALA VARIABLES
MUTABLE VARIABLE
IMMUTABLE VARIABLES
SCALA VARIABLE NAMING RULES
SCALA VARIABLE TYPE INFERENCE
println, printf, and readLine IN SCALA
PATTERN MATCHING IN SCALA
IMPORTANT NOTE
SCALA COMMENTS
SINGLELINE COMMENTS
MULTILINE COMMENTS
DOCUMENTATION COMMENTS
SCALA COMMAND LINE ARGUMENT
SCALA ENUMERATION
VARIABLE SCOPE IN SCALA
FIELDS
METHOD PARAMETERS
LOCAL VARIABLES
RANGES IN SCALA
Operations Performed on Ranges
CHAPTER 3: Scala Control Statements
MAKING DECISIONS (if, if-else, Nested if-else, if-else if) IN SCALA
if Statement
if-else Statement
Nested if-else Statement
if-else if Ladder
LOOPS IN SCALA (while, do..while, for, Nested Loops)
while Loop
Infinite while Loop
do..while Loop
for Loop
Nested Loops
SCALA FOR LOOP
for Loop Using to
for Loop Using until
MULTIPLE VALUES IN for-loop
USING for-loop WITH COLLECTIONS
USING for-loop WITH filters
USING for-loop WITH yield
SCALA while AND do while Loop
while Loop
do while Loop
SCALA BREAK STATEMENT
BREAK IN Nested Loop
LITERALS IN SCALA
LITERALS TYPES
yield KEYWORD IN SCALA
TYPE INFERENCE IN SCALA
SCALA FUNCTION TYPE INFERENCE
CHAPTER 4: Scala OOP Concepts
SCALA CLASS AND OBJECT
Class
Class Declaration
OBJECTS
Defining Objects (Also Called Instantiating a Class)
Creating an Object
Anonymous Object
SCALA INNER CLASS
How to Make a Class within an Object and an Object Inside a Class
SCALA INHERITANCE
HOW TO UTILIZE INHERITANCE IN SCALA
INHERITANCE TYPE
SCALA OPERATORS
ARITHMETIC OPERATORS
RELATIONAL OPERATORS
LOGICAL OPERATORS
ASSIGNMENT OPERATORS
BITWISE OPERATORS
SCALA OPERATORS PRECEDENCE
SCALA ABSTRACT CLASSES
When Should We Use Abstract Class in Scala?
SCALA COMPANION OBJECTS AND SINGLETON
SINGLETON OBJECT
COMPANION OBJECT
SCALA GENERIC CLASSES
SCALA ACCESS MODIFIERS
SCALA CONSTRUCTORS
PRIMARY CONSTRUCTOR
AUXILIARY CONSTRUCTOR
PRIMARY CONSTRUCTOR IN SCALA
AUXILIARY CONSTRUCTOR IN SCALA
IN SCALA, CALLING A SUPERCLASS CONSTRUCTOR
SCALA CLASS EXTENDING
CASECLASS AND CASEOBJECT IN SCALA
CASEOBJECT EXPLANATION
POLYMORPHISM SCALA
VALUE CLASSES IN SCALA
FIELD OVERRIDING IN SCALA
Overriding Rules for the Field
ABSTRACT TYPE MEMBERS IN SCALA
SCALA TYPE CASTING
SCALA OBJECT CASTING
SCALA OBJECT EQUALITY
MULTITHREADING IN SCALA
WHAT EXACTLY ARE THREADS IN SCALA?
Thread Creation by Extending Thread Class
Thread Creation by Extending the Runnable Interface
THREAD LIFE CYCLE IN SCALA
SCALA FINAL
SCALA THIS KEYWORD
CONTROLLING VISIBILITY OF CONSTRUCTOR FIELDS IN SCALA
CHAPTER 5: Scala String and Packages
SCALA STRING
SCALA STRING CREATION
DETERMINE THE LENGTH OF THE STRING
CONCATENATING STRINGS IN SCALA
CREATING FORMAT STRING
STRING INTERPOLATION IN SCALA
STRING INTERPOLATOR TYPES
StringContext IN SCALA
SCALA REGULAR EXPRESSIONS
Scala Regular Expression Syntax
SCALA StringBuilder
The StringBuilder Class Performs Operations
SCALA STRING CONCATENATION
SCALA PACKAGES
PACKAGE DECLARATION
HOW PACKAGE FUNCTIONS
ADDING PACKAGE MEMBERS
USING PACKAGES
PACKAGE OBJECTS IN SCALA
SCALA CHAINED PACKAGE CLAUSES
SCALA FILE HANDLING
CHAPTER 6: Scala Methods
SCALA FUNCTIONS – BASICS
DECLARATION AND DEFINITION OF FUNCTIONS
CALLING A FUNCTION
EXAMPLES OF CURRYING FUNCTIONS IN SCALA
Another Method for Declaring a Currying Function
Partial Application Currying Function
SCALA ANONYMOUS FUNCTIONS
ANONYMOUS PARAMETERIZED FUNCTIONS
Without parameters, anonymous functions
SCALA HIGHER ORDER FUNCTIONS
NAMED ARGUMENTS IN SCALA
FUNCTIONS CALL-BY-NAME IN SCALA
Call-by-Value
Call-by-Name
CLOSURES IN SCALA
NESTED FUNCTIONS IN SCALA
SINGLE NESTED FUNCTION
MULTIPLE NESTED FUNCTION
SCALA PARAMETERLESS METHOD
SCALA RECURSION
TAIL RECURSION
SCALA TAIL RECURSION
PARTIALLY APPLIED FUNCTIONS IN SCALA
SCALA METHOD OVERLOADING
Why Do We Require Method Overloading?
Different Approaches to Overloading Methods
What Happens When the Method Signature and Return Type Are the Same?
SCALA METHOD OVERRIDING
When Should We Use Method Overriding?
Method Overriding Guidelines
OVERRIDING VS OVERLOADING
WHY IS METHOD OVERRIDING REQUIRED?
METHOD INVOCATION IN SCALA
FORMAT AND FORMATTED METHOD IN SCALA
Format Method
Formatted Method
SCALA CONTROLLING METHOD SCOPE
Public Scope
Private Scope
Protected Scope
Object Private/Protected Scope
Package Specific
SCALA REPEATED METHOD PARAMETERS
SCALA PARTIAL FUNCTIONS
Partial Function Definition Methods
SCALA LAMBDA EXPRESSION
Making Use of Lambda Expressions
SCALA VARARGS
SCALA FUNCTION COMPOSITION
IN SCALA, CALL A METHOD ON A SUPERsCLASS
SCALA IMPLICIT CONVERSIONS
CHAPTER 7: Scala Exceptions
EXCEPTION HANDLING IN SCALA
HIERARCHY OF EXCEPTION
SCALA EXCEPTIONS
What Is the Scala Exception?
THROWING EXCEPTIONS
TRY/CATCH CONSTRUCT
THE FINALLY CLAUSE
SCALA THROW KEYWORD
SCALA TRY-CATCH EXCEPTIONS
SCALA FINALLY EXCEPTIONS
CONTROL FLOW IN TRY-FINALLY
TRY-CATCH-FINALLY CLAUSE
SCALA EITHER
Appraisal
Bibliography
Index