Beginning Kotlin: Build Applications with Better Code, Productivity, and Performance Ted Hagos pdf download
Beginning Kotlin: Build Applications with Better Code, Productivity, and Performance Ted Hagos pdf download
https://ebookmass.com/product/beginning-kotlin-build-
applications-with-better-code-productivity-and-performance-ted-
hagos/
https://ebookmass.com/product/frontend-development-with-javafx-and-
kotlin-build-state-of-the-art-kotlin-gui-applications-peter-spath/
https://ebookmass.com/product/programming-kotlin-applications-
building-mobile-and-server-side-applications-with-kotlin-brett-
mclaughlin/
https://ebookmass.com/product/better-humans-better-performance-
driving-leadership-teamwork-and-culture-with-intentionality-peter-j-
rea/
https://ebookmass.com/product/beginning-java-objects-from-concepts-to-
code-3rd-edition-jacquie-barker/
https://ebookmass.com/product/beginning-java-objects-from-concepts-to-
code-3rd-edition-jacquie-barker-2/
Ted Hagos
Beginning Kotlin: Build Applications with Better Code, Productivity,
and Performance
Ted Hagos
Makati, Philippines
Acknowledgments������������������������������������������������������������������������������xv
Introduction��������������������������������������������������������������������������������������xvii
v
Table of Contents
Chapter 3: Functions��������������������������������������������������������������������������55
Declaring Functions��������������������������������������������������������������������������������������������56
Single Expression Functions�������������������������������������������������������������������������61
Default Arguments�����������������������������������������������������������������������������������������62
vi
Table of Contents
Named Parameters����������������������������������������������������������������������������������������63
Variable Number of Arguments���������������������������������������������������������������������64
Extension Functions��������������������������������������������������������������������������������������65
Infix Functions�����������������������������������������������������������������������������������������������68
Operator Overloading������������������������������������������������������������������������������������������71
Key Takeaways����������������������������������������������������������������������������������������������������74
Chapter 4: Types���������������������������������������������������������������������������������77
Interfaces������������������������������������������������������������������������������������������������������������77
Diamond Problem������������������������������������������������������������������������������������������79
Invoking Super Behavior�������������������������������������������������������������������������������81
Classes����������������������������������������������������������������������������������������������������������������83
Constructors��������������������������������������������������������������������������������������������������84
Inheritance����������������������������������������������������������������������������������������������������88
Properties������������������������������������������������������������������������������������������������������93
Data Classes�������������������������������������������������������������������������������������������������������98
Visibility Modifiers���������������������������������������������������������������������������������������������102
Inheritance Modifiers����������������������������������������������������������������������������������������104
Object Declarations�������������������������������������������������������������������������������������������105
Key Takeaways��������������������������������������������������������������������������������������������������106
vii
Table of Contents
Chapter 6: Collections����������������������������������������������������������������������123
Arrays����������������������������������������������������������������������������������������������������������������124
Collections��������������������������������������������������������������������������������������������������������128
Lists�������������������������������������������������������������������������������������������������������������130
Sets�������������������������������������������������������������������������������������������������������������132
Maps������������������������������������������������������������������������������������������������������������133
Collections Traversal������������������������������������������������������������������������������������135
Filter and Map���������������������������������������������������������������������������������������������������137
Key Takeaways��������������������������������������������������������������������������������������������������140
Chapter 7: Generics��������������������������������������������������������������������������141
Why Generics����������������������������������������������������������������������������������������������������141
Terminologies����������������������������������������������������������������������������������������������������143
Using Generics in Functions�����������������������������������������������������������������������������144
Using Generics in Classes���������������������������������������������������������������������������������147
Variance������������������������������������������������������������������������������������������������������������149
Reified Generics������������������������������������������������������������������������������������������������154
Key Takeaways��������������������������������������������������������������������������������������������������158
Chapter 8: Debugging�����������������������������������������������������������������������159
Errors����������������������������������������������������������������������������������������������������������������159
Runtime and Logic Errors����������������������������������������������������������������������������161
Working the Debugger��������������������������������������������������������������������������������������161
Set Breakpoints�������������������������������������������������������������������������������������������164
Run the Program in Debug Mode����������������������������������������������������������������165
Analyze the Program State��������������������������������������������������������������������������166
Other Uses of the Debugger������������������������������������������������������������������������������176
Changing the Program State�����������������������������������������������������������������������177
Key Takeaways��������������������������������������������������������������������������������������������������183
viii
Table of Contents
Index�������������������������������������������������������������������������������������������������225
ix
About the Author
Ted Hagos is the CTO and Data Protection Officer of RenditionDigital
International (RDI), a software development company based out of
Dublin. Before he joined RDI, he had various software development
roles and also spent time as a trainer at IBM Advanced Career Education,
Ateneo ITI, and Asia Pacific College. He spent many years in software
development dating back to Turbo C, Clipper, dBase IV, and Visual
Basic. Eventually, he found Java and spent many years working with it.
Nowadays, he’s busy with Kotlin, full-stack JavaScript, Android, and Spring
applications.
xi
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
About the Technical Reviewer
Manuel Jordan Elera is an autodidactic
developer and researcher who enjoys learning
new technologies for his own experiments and
creating new integrations. Manuel won the
Springy Award 2013 Community Champion
and Spring Champion. In his little free time,
he reads the Bible and composes music on his
guitar. Manuel is known as dr_pompeii. He
has tech-reviewed numerous books, including
Pro Spring MVC with WebFlux (Apress, 2020),
Pro Spring Boot 2 (Apress, 2019), Rapid Java Persistence and Microservices
(Apress, 2019), Java Language Features (Apress, 2018), Spring Boot 2
Recipes (Apress, 2018), and Java APIs, Extensions and Libraries (Apress,
2018). You can read his detailed tutorials on Spring technologies and
contact him through his blog at www.manueljordanelera.blogspot.com.
You can follow Manuel on his Twitter account, @dr_pompeii.
xiii
Acknowledgments
Thanks to Steve Anglin, Mark Powers, Shonmirin, and Manuel Jordan Elera
for making this book possible.
xv
Introduction
Welcome to Beginning Kotlin.
Kotlin may have (initially) gained popularity as a drop-in replacement
for Java for building Android apps, but it’s ubiquitous now. You can use
it to build web apps—both on the front and back end. Kotlin is quickly
gaining popularity in areas that used to be Java strongholds. If you want to
get a head start on Kotlin, this book is an excellent place to start.
Chapter Overviews
Chapter 1 (Introduction to Kotlin) – Brief introduction to the Kotlin
language. You’ll learn a bit about the language's history and some of its
well-known capabilities. The chapter also walks you through the steps on
how to install Kotlin and get started with a quick project.
Chapter 2 (A Quick Tour of Kotlin) – Discusses the language
elements of Kotlin. You’ll learn the syntax with brisk examples. You’ll know
how to declare strings, variables, and constants. You’ll also learn how to
move around using Kotlin’s control structures for looping, branching, and
exception handling.
Chapter 3 (Functions) – There’s a whole chapter dedicated to
functions because Kotlin’s functions have something new up their sleeves.
It has all the trimmings of a modern language like default and named
parameters, infix functions, and operators, and with Kotlin, we can also
create extension functions. Extension functions let you add behavior to an
existing class without inheriting from it and without changing its source.
xvii
Introduction
xviii
Introduction
xix
CHAPTER 1
Introduction to Kotlin
Kotlin is a new language that targets the Java platform; its programs run on
the JVM (Java Virtual Machine), which puts it in the company of languages
like Groovy, Scala, Jython, and Clojure, to name a few.
What we’ll cover:
might remember that the history of the Java language contains references
that it was named after the coffee, rather than the island.
About Kotlin
It’s Simple
fun main() {
val name = "stranger" // Declare your first variable
println("Hi, $name!") // ...and use it!
print("Current count:")
for (i in 0..10) { // Loop over a range
from 0 to 10
print(" $i")
}
}
As you can see from the preceding code—which I lifted from https://
kotlinlang.org—we don’t (always) have to write a class. Top-level
functions can run without wrapping them inside classes.
It’s Asynchronous
import kotlinx.coroutines.*
2
Chapter 1 Introduction to Kotlin
}
}
}
// #5
log(start, "Liftoff!")
}
It’s Object-Oriented
abstract class Person(val name: String) {
abstract fun greet()
}
interface FoodConsumer {
fun eat()
fun pay(amount: Int) = println("Delicious! Here's $amount
bucks!")
}
3
Chapter 1 Introduction to Kotlin
fun main() {
val sam = RestaurantCustomer("Sam", "Mixed salad")
sam.greet() // An implementation of an abstract function
sam.order() // A member function
sam.eat() // An implementation of an interface function
sam.pay(10) // A default implementation in an interface
}
Like Java, it’s object-oriented. So, all those long hours you’ve
invested in Java’s OOP and design pattern won’t go to waste. Kotlin classes,
interfaces, and generics look and behave quite a lot like Java’s. This is
definitely a strength because, unlike other JVM languages like Scala, Kotlin
doesn’t look too foreign. It doesn’t alienate Java programmers. Instead, it
allows them to build on their strengths.
It’s Functional
Kotlin is a functional language. Higher order functions are functions that
operate on other functions, either by taking them in as parameters or by
returning them.
In a functional language (like Kotlin), functions are not just a named
collection of statements. You can use them anywhere you might use a
variable. You can pass functions as an argument to other functions, and you
can even return functions from other functions. This way, coding allows for a
different way of abstraction. Functions are treated as first-class citizens.
4
Chapter 1 Introduction to Kotlin
fun main() {
// Who sent the most messages?
val frequentSender = messages
.groupBy(Message::sender)
.maxByOrNull { (_, messages) -> messages.size }
?.key // #1
println(frequentSender) // [Ma]
5
Visit https://ebookmass.com today to explore
a vast collection of ebooks across various
genres, available in popular formats like
PDF, EPUB, and MOBI, fully compatible with
all devices. Enjoy a seamless reading
experience and effortlessly download high-
quality materials in just a few simple steps.
Plus, don’t miss out on exciting offers that
let you access a wealth of knowledge at the
best prices!
Exploring the Variety of Random
Documents with Different Content
The Project Gutenberg eBook of Index for
Works of Willis George Emerson
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Language: English
## BUELL HAMPTON
## MY PARDNER AND I
ON SOUND MONEY
TABLES OF CONTENTS OF
VOLUMES
CONTENTS
CHAPTER I—Guadalupe
CHAPTER II—Charmed Lives
CHAPTER III—Feminine Attractions
CHAPTER IV—Back to the Soil
CHAPTER V—At La Siesta
CHAPTER VI—The Quarrel
CHAPTER VII—Old Bandit Days
CHAPTER VIII—A Letter from San Quentin
CHAPTER IX—Tia Teresa
CHAPTER X—The Home of the Recluse
CHAPTER XI—A Rejected Suitor
CHAPTER XII—The Sped Bullet
CHAPTER XIII—Accused
CHAPTER XIV—Entanglements
CHAPTER XV—Behind the Bars
CHAPTER XVI—Pierre Luzon Returns
CHAPTER XVII—The Bitter Bit
CHAPTER XVIII—Elusive Riches
CHAPTER XIX—The Jail Delivery
CHAPTER XX—In the Cavern
CHAPTER XXI—A Debt of Honor
CHAPTER XXII—Underqround Wonders
CHAPTER XXIII—The Unexpected Visitor
CHAPTER XXIV—In a Tight Corner
CHAPTER XXV—Love and Revenge
CHAPTER XXVI—A Date is Fixed
CHAPTER XXVII—Among the Old Oaks
CHAPTER XXVIII—The Prize Winner
CHAPTER XXIX—-The Rendezvous
CHAPTER XXX—Don Manuel Appears
CHAPTER XXXI—Shadows of the Past
CHAPTER XXXII—Forebodings
CHAPTER XXXIII—Old Friends
CHAPTER XXXIV—Heart Searchings
CHAPTER XXXV—At Comanche Point
CHAPTER XXXVI—-Outwitted
CHAPTER XXXVII—The Dawn of Comprehension
CHAPTER XXXVIII—Exit Leach Sharkey
CHAPTER XXXIX—The Fight on the Cliff
CHAPTER XL—Revelation
CHAPTER XLI—Beneath the Precipice
CHAPTER XLII—Wedding Bells
BUELL HAMPTON
By Willis George Emerson
CONTENTS
THEME
BUELL HAMPTON
CHAPTER I.—AT LAKE GENEVA
CHAPTER II.—A CHANCE MEETING
CHAPTER III.—A DECLARATION
CHAPTER IV.—THE DEPARTURE
CHAPTER V.—A FRONTIER BANKER
CHAPTER VI.—MAJOR BUELL HAMPTON
CHAPTER VII.—THE CATTLE KING
CHAPTER VIII.—A COMMITTEE OF FIVE
CHAPTER IX.—AN AFTERNOON DRIVE
CHAPTER X.—HOME OF THE HORTONS
CHAPTER XI.—DADDY’. CONSENT
CHAPTER XII.—KANSAS PROHIBITION
CHAPTER XIII.—MAJOR HAMPTON’. LIBRARY
CHAPTER XIV.—THE SONG
CHAPTER XV.—THE RETRACTION
CHAPTER XVI.—THE OLD VIOLIN
CHAPTER XVII.—LENOX AVONDALE’. ARRIVAL
CHAPTER XVIII.—A LOVE SONG
CHAPTER XIX.—AN INVITATION TO JOIN
CHAPTER XX.—A DINNER AT THE HORTONS
CHAPTER XXI.—THE FOOT-RACE
CHAPTER XXII.—THE ELECTION
CHAPTER XXIII.—A FORGED LETTER
CHAPTER XXIV.—REVERSING THE HIGHER COURTS
CHAPTER XXV.—ALMOST A TRAGEDY
CHAPTER XXVI.—REACHING A DECISION
CHAPTER XXVII.—THE HOT WINDS
CHAPTER XXVIII.—“THY WILL BE DONE”
CHAPTER XXIX.—JACK REDFIELD ARRIVES
CHAPTER XXX.—THE QUARREL
CHAPTER XXXI.—THE PASSING OF LORD AVONDALE
CHAPTER XXXII.—THE SILENCING OF GOSSIP
CHAPTER XXXIII.—A RIDE AMONG SUNFLOWERS
CHAPTER XXXIV.—THE PRAIRIE-FIRE
CHAPTER XXXV.—A BUCKING BRONCO
CHAPTER XXXVI.—A STARTLING REVELATION
CHAPTER XXXVII.—TRYING TO REMEMBER
CHAPTER XXXVIII.—TRUTH STRANGER THAN FICTION
CHAPTER XXXIX.—JUDGE LYNN HAS AN IDEA
CHAPTER XL.—THE CATTLE THIEF CAUGHT
CHAPTER XLI.—A ROSICRUCIAN
CHAPTER XLII.—A NEW-MADE GRAVE
CHAPTER XLIII.—UNDER THE QUIET STARS
MY “PARDNER” AND I
By Willis George Emerson
1894
CONTENTS
PREFACE.
PARTIAL LIST OF ILLUSTRATIONS.
CHAPTER I.—VANCE GILDER.
CHAPTER II.—THE OLD MINER.
CHAPTER III.—THE BANNER FORCE.
CHAPTER IV—A SUPPER PARTY.
CHAPTER V.—AN ODD CHARACTER.
CHAPTER VI—THE TOWN BOOMER.
CHAPTER VII.—A VISIT TO WATERVILLE
CHAPTER VIII.—AT THE MINE
CHAPTER IX.—THE STAGE DRIVER.
CHAPTER X.—PROPERTY HAS GONE UP.
CHAPTER XI.—OWNER OF THE PEACOCK MINE.
CHAPTER XII—TROUT FISHING.
CHAPTER XIII.—THE STAGE RIDE.
CHAPTER XIV.—THE TOWN COMPANY’S MEETING.
CHAPTER XV.—MISS VIRGINIA BONIFIELD.
CHAPTER XVI.—THE OLD COLONEL’S DISAPPOINTMENT.
CHAPTER XVII.—An AWAKENING.
CHAPTER XVIII.—VANCE RETURNS TO WATERVILLE.
CHAPTER XIX.—THE INDIGNATION MEETING
CHAPTER XX.—THE STAGE IS ROBBED.
CHAPTER XXI.—REACHING THE 400 FOOT LEVEL.
CHAPTER XXII.—STARTING THE BOOM.
CHAPTER XXIII.—RUFUS GRIM S AMBITION.
CHAPTER XXIV.—THE GOLDEN MAUSOLEUM.
CHAPTER XXV.—CROSS-CUTTING IN THE MINE.
CHAPTER XXVI.—A STARTLING EDITORIAL.
CHAPTER XXVII.—AT LAST!
THE TREASURE OF HIDDEN
VALLEY
By Willis George Emerson
CONTENTS
THE TREASURE OF HIDDEN VALLEY
CHAPTER I—AT THE PARTING OF THE WAYS
CHAPTER II—A MESSAGE FROM THE GRAVE
CHAPTER III—FINANCIAL WOLVES
CHAPTER IV.—THE COLLEGE WIDOW
CHAPTER V.—WESTWARD HO!
CHAPTER VI.—RODERICK MEETS JIM RANKIN
CHAPTER VII—GETTING ACQUAINTED
CHAPTER VIII.—A PHILOSOPHER AMONG THE MOUNTAINS
CHAPTER IX—THE HIDDEN VALLEY
CHAPTER X.—THE FAIR RIDER OF THE RANGE
CHAPTER XI.—WINTER PASSES
CHAPTER XII—THE MAJOR’S FIND
CHAPTER XIV.—THE EVENING PARTY
CHAPTER XV.—BRONCHO-BUSTING
CHAPTER XVI.—THE MYSTERIOUS TOILERS OF THE NIGHT
CHAPTER XVII—A TROUT FISHING EPISODE
CHAPTER XVIII.—A COUNTRY FAIR ON THE FRONTIER
CHAPTER XIX.—A LETTER FROM THE COLLEGE WIDOW
CHAPTER XX.—THE STORE OF GOLD
CHAPTER XXI.—A WARNING
CHAPTER XXII.—THE TRAGEDY AT JACK CREEK
CHAPTER XXIII.—THE FIGHT ON THE ROAD
CHAPTER XXIV—SUMMER DAYS
CHAPTER XXV.—RUNNING FOR STATE SENATOR
CHAPTER XXVI.—UNEXPECTED POLITICAL HARMONY
CHAPTER XXVII.—THE UPLIFTING OF HUMANITY
CHAPTER XXVIII.—JUSTICE FOR THE WORKERS
CHAPTER XXIX.—SLEIGH BELLS
CHAPTER XXX.—WHITLEY ADAMS BLOWS IN
CHAPTER XXXI.—RODERICK’S DISCOVERY
CHAPTER XXXII.—STAKING THE CLAIMS
CHAPTER XXXIII—THE SNOW SLIDE
CHAPTER XXXIV—THE PASSING OF GRANT JONES
CHAPTER XXXV.—A CALL TO SAN FRANCISCO
CHAPTER XXXVI—IN THE CITY THAT NEVER SLEEPS
CHAPTER XXXVII—RODERICK RESCUES GAIL
CHAPTER XXXVIII—THE SEARCH FOR RODERICK
CHAPTER XXXIX—REUNIONS
CHAPTER XL—BUELL HAMPTON’S GOOD-BY
CHAPTER XLI.—UNDER THE BIG PINE
AFTERWORD
*** END OF THE PROJECT GUTENBERG EBOOK INDEX FOR WORKS
OF WILLIS GEORGE EMERSON ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookmasss.com