Programming Kotlin

Familiarize yourself with all of Kotlin’s features with this in-depth guide

Programming Kotlin

Learning
Stephen Samuel, Stefan Bocutiu

Familiarize yourself with all of Kotlin’s features with this in-depth guide
$35.99
$44.99
RRP $35.99
RRP $44.99
eBook
Print + eBook

Instantly access this course right now and get the skills you need in 2017

With unlimited access to a constantly growing library of over 4,000 eBooks and Videos, a subscription to Mapt gives you everything you need to learn new skills. Cancel anytime.

Preview in Mapt

Book Details

ISBN 139781787126367
Paperback420 pages

Book Description

Kotlin has been making waves ever since it was open sourced by JetBrains in 2011; it has been praised by developers across the world and is already being adopted by companies. This book provides a detailed introduction to Kotlin that shows you all its features and will enable you to write Kotlin code to production.

We start with the basics: get you familiar with running Kotlin code, setting up, tools, and instructions that you can use to write basic programs. Next, we cover object oriented code: functions, lambdas, and properties – all while using Kotlin’s new features.

Then, we move on to null safety aspects and type parameterization. We show you how to destructure expressions and even write your own. We also take you through important topics like testing, concurrency, microservices, and a whole lot more. By the end of this book you will be able to compose different services and build your own applications.

Table of Contents

Chapter 1: Getting Started with Kotlin
Using the command line to compile and run Kotlin code
Kotlin runtime
The REPL
Kotlin for scripting
Kotlin with Gradle
Kotlin with Maven
IntelliJ and Kotlin
Eclipse and Kotlin
Mixing Kotlin and Java in a project
Summary
Chapter 2: Kotlin Basics
Vals and vars
Type inference
Basic types
Comments
Packages
Imports
String templates
Ranges
Loops
Exception handling
Instantiating classes
Referential equality and structural equality
This expression
Visibility modifiers
Control flow as expressions
Null syntax
When expression
Type hierarchy
Summary
Chapter 3: Object-Oriented Programming in Kotlin
Classes
Interfaces
Inheritance
Visibility modifiers
Abstract classes
Interface or abstract class
Polymorphism
Overriding rules
Inheritance versus composition
Class delegation
Sealed classes
Summary
Chapter 4: Functions in Kotlin
Defining functions
Single expression functions
Member functions
Local functions
Top-level functions
Named parameters
Default parameters
Extension functions
Operators
Function literals
Tail recursive functions
Varargs
Standard library functions
Generic functions
Pure functions
Java from Kotlin
Kotlin from Java
Summary
Chapter 5: Higher Order Functions and Functional Programming
Higher order functions
Closures
Anonymous functions
Function references
Function-literal receivers
Functions in the JVM
Function composition
Inline functions
Currying and partial application
Memoization
Type alias
Either
Custom DSLs
Validation and error accumulation
Summary
Chapter 6: Properties
Why use properties?
Syntax and variations
Visibility
Late initialization
Delegated properties
Lazy initializations
Lateinit versus lazy
Observables
A non-null property delegate
Properties or methods?
Summary
Chapter 7: Null Safety, Reflection, and Annotations
Nullable types
Smart cast
Safe null access
Elvis operator
Safe casting
Optionals
Reflection
Constructors
Objects and companions
Useful KClass properties
Reflective functions and properties
Annotations
Standard annotations
Runtime annotation discovery
Summary
Chapter 8: Generics
Parameterised functions
Parameterized types
Bounded polymorphism
Type variance
Nothing type
Type projection
Type erasure
Type reification
Recursive type bounds
Algebraic data types
Summary
Chapter 9: Data Classes
Automatic creation of getters and setters
The copy method
toString out of the box
hashCode and equals methods generated for you
Destructed declarations
Destructing types
Data class definition rules
Limitations
Summary
Chapter 10: Collections
Class hierarchy
Arrays
Lists
Maps
Sets
Read-only views
Indexed access
Sequences
Summary
Chapter 11: Testing in Kotlin
Getting started
Choosing a spec
Matchers
Inspectors
Interceptors
Project config
Property testing
Table-driven testing
Tags, conditions, and config
Summary
Chapter 12: Microservices with Kotlin
Definition
Drawbacks
Why microservices?
Lagom
Defining services
Implementing a Lagom service
Summary
Chapter 13: Concurrency
Threads
Deadlocks and livelocks
Executors
Race conditions
Summary

What You Will Learn

  • Use new features to write structured and readable object-oriented code
  • Find out how to use lambdas and higher order functions to write clean, reusable, and simple code
  • Write unit tests and integrate Kotlin tests with Java code in a transitioning code base
  • Write real-world production code in Kotlin in the style of microservices
  • Leverage Kotlin’s extensions to the Java collections library
  • Use destructuring expressions and find out how to write your own
  • Write code that avoids null pointer errors and see how Java-nullable code can integrate with features in a Kotlin codebase
  • Discover how to write functions in Kotlin, see the new features available, and extend existing libraries
  • Learn to write an algebraic data types and figure out when they should be used

Authors

Table of Contents

Chapter 1: Getting Started with Kotlin
Using the command line to compile and run Kotlin code
Kotlin runtime
The REPL
Kotlin for scripting
Kotlin with Gradle
Kotlin with Maven
IntelliJ and Kotlin
Eclipse and Kotlin
Mixing Kotlin and Java in a project
Summary
Chapter 2: Kotlin Basics
Vals and vars
Type inference
Basic types
Comments
Packages
Imports
String templates
Ranges
Loops
Exception handling
Instantiating classes
Referential equality and structural equality
This expression
Visibility modifiers
Control flow as expressions
Null syntax
When expression
Type hierarchy
Summary
Chapter 3: Object-Oriented Programming in Kotlin
Classes
Interfaces
Inheritance
Visibility modifiers
Abstract classes
Interface or abstract class
Polymorphism
Overriding rules
Inheritance versus composition
Class delegation
Sealed classes
Summary
Chapter 4: Functions in Kotlin
Defining functions
Single expression functions
Member functions
Local functions
Top-level functions
Named parameters
Default parameters
Extension functions
Operators
Function literals
Tail recursive functions
Varargs
Standard library functions
Generic functions
Pure functions
Java from Kotlin
Kotlin from Java
Summary
Chapter 5: Higher Order Functions and Functional Programming
Higher order functions
Closures
Anonymous functions
Function references
Function-literal receivers
Functions in the JVM
Function composition
Inline functions
Currying and partial application
Memoization
Type alias
Either
Custom DSLs
Validation and error accumulation
Summary
Chapter 6: Properties
Why use properties?
Syntax and variations
Visibility
Late initialization
Delegated properties
Lazy initializations
Lateinit versus lazy
Observables
A non-null property delegate
Properties or methods?
Summary
Chapter 7: Null Safety, Reflection, and Annotations
Nullable types
Smart cast
Safe null access
Elvis operator
Safe casting
Optionals
Reflection
Constructors
Objects and companions
Useful KClass properties
Reflective functions and properties
Annotations
Standard annotations
Runtime annotation discovery
Summary
Chapter 8: Generics
Parameterised functions
Parameterized types
Bounded polymorphism
Type variance
Nothing type
Type projection
Type erasure
Type reification
Recursive type bounds
Algebraic data types
Summary
Chapter 9: Data Classes
Automatic creation of getters and setters
The copy method
toString out of the box
hashCode and equals methods generated for you
Destructed declarations
Destructing types
Data class definition rules
Limitations
Summary
Chapter 10: Collections
Class hierarchy
Arrays
Lists
Maps
Sets
Read-only views
Indexed access
Sequences
Summary
Chapter 11: Testing in Kotlin
Getting started
Choosing a spec
Matchers
Inspectors
Interceptors
Project config
Property testing
Table-driven testing
Tags, conditions, and config
Summary
Chapter 12: Microservices with Kotlin
Definition
Drawbacks
Why microservices?
Lagom
Defining services
Implementing a Lagom service
Summary
Chapter 13: Concurrency
Threads
Deadlocks and livelocks
Executors
Race conditions
Summary

Book Details

ISBN 139781787126367
Paperback420 pages
Read More

Read More Reviews