Home Page Icon
Home Page
Table of Contents for
Copyright and Credits
Close
Copyright and Credits
by Igor Kucherenko, Abid Khan
Hands-On Object-Oriented Programming with Kotlin
Title Page
Copyright and Credits
Hands-On Object-Oriented Programming with Kotlin
Dedication
Packt Upsell
Why subscribe?
Packt.com
Contributors
About the authors
About the reviewer
Packt is searching for authors like you
Preface
Who this book is for
What this book covers
To get the most out of this book
Download the example code files
Conventions used
Get in touch
Reviews
Getting Started with Kotlin
Technical requirements
Introduction to Kotlin
Data types in Kotlin
Declaring a variable in Kotlin
The var keyword
The val keyword
Type inference
Type annotation
Number data types
Real data types
Boolean data type
Character data type
Type checking with the is keyword
String variable
Null safety, type casting, Pair, and Triple
Null safety
Safe call operators 
The ?.  Safe call operator  
The ?: Elvis operator
The !! Sure operator
Type casting
Converting from Byte to Float
Converting from Double to Integer
Converting from String to Integer
Smart cast
Unsafe cast
Pair and Triple 
How to declare
How to retrieve values
Flow controls
The if statement
The if and else statements
The if statement with a conditional operator
The if statement with the and (&&) operator
The if statement with the or (||) operator
The if statement with the (!) Not operator
if as an expression
The When expression
Combining cases
Ranges with When
When as an expression
Introduction to loops 
The while loop
Defining the while loop
The do while loop  
The for loop
 Defining the for loop 
The nested for loop
Break statements
The break statement with labeled for loop 
What is a function?
Function declaration
Functions with no parameter and no return type
Function with parameters
Functions with parameters and return types
Function as an expression
Functions with default arguments
Functions with named parameters
Functions and vararg
vararg with other arguments
Package-level functions
How to access a function
Summary
Questions
Further reading
Introduction to Object-Oriented Programming
Technical requirements
Object-oriented programming?
Classes and objects
Attributes and behaviors
Benefits of object-oriented programming
Classes in Kotlin
Properties – first-class citizens
Constructing a class with a constructor
Default constructor
Primary constructor
Primary constructor with the init block
The this keyword 
Secondary constructor
Constructor overloading
Constructor with default parameters
Constructor with named parameters
What are data classes?
The toString() function
The equals() function ==
The copy function
The hashCode() function
Object decomposition
Classes and functions
Function overloading
Summary
Questions
Further reading
The Four Pillars of Object-Oriented Programming
Technical requirements
Encapsulation
Information-hiding
Visibility modifier 
The private modifier
The protected modifier
Implementation-hiding
What is inheritance?
Using the open keyword
Using the super keyword
Class-initialization hierarchy
Abstraction
Abstract classes
Abstract functions
Interfaces
Multiple interfaces
Resolving conflicts between interfaces
Interfaces and polymorphism
Overriding
What is overriding?
The super keyword
The final keyword
Rules for function-overriding
Property-overriding 
Types of inheritance
Single inheritance
Multilevel inheritance
Hierarchical inheritance
Hierarchical multilevel inheritance
The is-a relationship
Polymorphism
How polymorphism works
Dynamic binding
Summary
Questions
Further reading
Classes - Advanced Concepts
Technical requirements
Sealed classes and enumeration
Sealed classes
Sealed classes with the when block
Why do we need sealed classes?  
Enum classes
The enum class with a constructor
The enum class and functions
The enum class and interfaces
Objects and companion objects
The object class with inheritance and interfaces
Companion objects
Companion functions and interfaces
Aggregation, composition, and nested classes
Aggregation
Composition
Nested classes
Inner classes
Class properties
Delegate properties
Built-in delegates
Summary
Questions
Further reading
Data Collection, Iterators, and Filters
Technical requirements
Range
Types of ranges
Declaring a range
The rangeTo function 
The until function
The downTo function
The step function
The contains function
The elementAt function
Range properties
The coerce functions
The coerceIn function
The coerceAtMost(maxValue) function
The coerceAtLeast(minValue) function
Arrays 
Defining arrays
Arrays of a specific type
Index of the array element
The get function
The array and for loop
Array declaration and initialization
The set function
Mutable arrays with immutable elements
Arrays with lambda expressions
Arrays of different elements
The arrayOfNulls function
Copying arrays
Lists in Kotlin
Immutable lists
The listOfNotNull function
List access
Immutable lists and interfaces
Iterable interfaces
Collection interfaces
List interfaces
Mutable lists
The MutableIterable interface
Mutable collection interfaces
Mutable list interfaces
Sets in Kotlin 
Immutable sets
Mutable sets
Map
Immutable maps
Mutable maps
Iterators in Kotlin
Iterators
List iterators
Mutable iterators
Mutable list iterators
Filters and collection functions
The filter function  
The it keyword 
The filterNot function
The filterNotNull function
The filterIsInstance<dataType> function
The slice function
The take function
takeLast
takeWhile
takeLastWhile
The drop function
dropLast
dropWhile
dropWhileLast
The fold function
foldRight 
The reduce function
reduceRight
reduceRightIndexed
Some important functions
foreach
forEachIndexed
onEach
max and maxBy
min and minBy
Summary
Questions
Further reading
Object-Oriented Patterns in Kotlin
Technical requirements
What design patterns are and how they help
Types of design patterns
Creational patterns
Structural patterns
Behavioral patterns
Creational patterns
Builder
Factory method
Abstract factory
Singleton
Structural patterns
Adapter
Decorator
Facade
Proxy
Behavioral patterns
Observer
Strategy
Command 
State
Chain of responsibility
Visitor
Summary
Coroutines - a Lightweight Thread?
Technical requirements
What are coroutines?
Coroutines and threads
Coroutine examples
Exception handling
Resource releasing
Non-cancelable block
Parallel execution
Lazy execution
Channels
Summary
Interoperability
Technical requirements
Calling Java code in Kotlin
Calling static variables and functions
Calling the Java collection in Kotlin
Reserve words in Kotlin  
Java classes in Kotlin 
Calling Kotlin code in Java
Calling the Kotlin function 
Extension functions
Functions with mutable collections
Functions with immutable collections
Functions with the JVM annotation
Calling the Kotlin class
Calling the Kotlin singleton class
Summary
Questions
Further reading
Regular Expression and Serialization in Kotlin
Technical requirements
Introducing regular expression
Kotlin and regular expression
Introducing serialization
Serialization and Kotlin support
Summary
Exception Handling
Technical requirements
What is exception handling?
Checked and unchecked exceptions
 Exception hierarchy
Exceptions in Java
Exceptions in Kotlin
Interoperability
Using the try block as an expression
Writing your own exception
Summary
Questions
Further reading
Testing in Object-Oriented Programming with Kotlin
Technical requirements
Why testing?
Types of testing
Manual testing
Automated testing
Unit testing
The Kotlin test libraries
Installation
Gradle with Groovy
Gradle with the Kotlin script
Maven
Testing examples
Class references
Writing specifications
The given, on, and it blocks
Testing exceptions
The describe and it blocks
Summary
Questions
Further reading
Assessments
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 8
Chapter 10
Chapter 11
Other Books You May Enjoy
Leave a review - let other readers know what you think
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Title Page
Next
Next Chapter
Hands-On Object-Oriented Programming with Kotlin
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset