About the Book
Kotlin is a powerful language, largely thanks to its expressive syntax, intuitive and null-safe type system, and great tooling support. In this book, we cover the essentials of Kotlin, so you can start developing with this amazing programming language. We show nearly everything you need to know in clear and executable code examples.
If you are interested in paperback, you can purchase it here.
- For whom is this book written?
- What will be covered?
- The Kotlin for Developers series
- My story
- Code conventions
What is Kotlin?
- Kotlin platforms
- The Kotlin IDE
- Where do we use Kotlin?
Your first program in Kotlin
- Live templates
- What is under the hood on JVM?
- Packages and importing
- Exercise: Your first program
Basic types, their literals and operations
- Exercise: Basic values operations
Conditional statements: if, when, try, and while
- when-statement with a value
- is check
- Explicit casting
- While and do-while statements
- Exercise: Using when
- Exercise: Pretty time display
- Single-expression functions
- Functions on all levels
- Parameters and arguments
- Vararg parameters
- Named parameter syntax and default arguments
- Function overloading
- Infix syntax
- Function formatting
- Exercise: Person details display
The power of the for-loop
- Break and continue
- Use cases
- Exercise: Range Operations
- Safe calls
- Not-null assertion
- The Elvis operator
- Extensions on nullable types
nullis our friend
- Exercise: User Information Processor
- Member functions
- Classes representing data in Kotlin and Java
- Inner classes
- Exercise: Implementing the Product class
- Overriding elements
- Parents with non-empty constructors
- Super call
- Abstract class
- Exercise: GUI View Hierarchy Simulation
- Transforming to a string
- Objects equality
- Hash code
- Copying objects
- When and how should we use destructuring?
- Data class limitations
- Prefer data classes instead of tuples
- Data class practice
- Object expressions
- Object declaration
- Companion objects
- Data object declarations
- Constant values
- Exercise: Pizza factory
- Throwing exceptions
- Defining exceptions
- Catching exceptions
- A try-catch block used as an expression
- The finally block
- Important exceptions
- The hierarchy of exceptions
- Exercise: Catching exceptions
- Data in enum values
- Enum classes with custom methods
- Exercise: Days of the week enum
Sealed classes and interfaces
Sealed classes and
- Sealed vs enum
- Use cases
- Sealed classes and
- Annotating the primary constructor
- List literals
- Extension functions under the hood
- Extension properties
- Extensions vs members
- Extension functions on object declarations
- Member extension functions
- Use cases
- Exercise: Conversion and measurement unit creation
- The hierarchy of interfaces
- Mutable vs read-only types
- Creating collections
- Using arrays in practice
- Exercise: Inventory management
- An example of operator overloading
- Arithmetic operators
- The iterator operator
- The equality and inequality operators
- Comparison operators
- The indexed access operator
- Augmented assignments
- Unary prefix operators
- Increment and decrement
- The invoke operator
- Exercise: Money operations
The beauty of Kotlin’s type system
- What is a type?
- Why do we have types?
- The relation between classes and types
- Class vs type in practice
- The relationship between types
- The subtype of all the types: Nothing
- The result type from return and throw
- When is some code not reachable?
- The type of null
- Practice: The closest supertype of types
- Generic functions
- Generic classes
- Generic classes and nullability
- Generic interfaces
- Type parameters and inheritance
- Type erasure
- Generic constraints
- Star projection
- Exercise: Stock
- Final words
- Exercises solutions
The Leanpub 60-day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
80% Royalties. Earn $16 on a $20 book.
We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $12 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.