万本电子书0元读

万本电子书0元读

顶部广告

Learn Kotlin Programming电子书

售       价:¥

1人正在读 | 0人评论 9.8

作       者:Stephen Samuel

出  版  社:Packt Publishing

出版时间:2019-05-29

字       数:66.5万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Delve into the world of Kotlin and learn to build powerful Android and web applications Key Features * Learn the fundamentals of Kotlin to write high-quality code * Test and debug your applications with the different unit testing frameworks in Kotlin * Explore Kotlin's interesting features such as null safety, reflection, and annotations Book Description Kotlin is a general-purpose programming language used for developing cross-platform applications. Complete with a comprehensive introduction and projects covering the full set of Kotlin programming features, this book will take you through the fundamentals of Kotlin and get you up to speed in no time. Learn Kotlin Programming covers the installation, tools, and how to write basic programs in Kotlin. You'll learn how to implement object-oriented programming in Kotlin and easily reuse your program or parts of it. The book explains DSL construction, serialization, null safety aspects, and type parameterization to help you build robust apps. You'll learn how to destructure expressions and write your own. You'll then get to grips with building scalable apps by exploring advanced topics such as testing, concurrency, microservices, coroutines, and Kotlin DSL builders. Furthermore, you'll be introduced to the kotlinx.serialization framework, which is used to persist objects in JSON, Protobuf, and other formats. By the end of this book, you'll be well versed with all the new features in Kotlin and will be able to build robust applications skillfully. What you will learn * Explore the latest Kotlin features in order to write structured and readable object-oriented code * Get to grips with using lambdas and higher-order functions * Write unit tests and integrate Kotlin with Java code * Create real-world apps in Kotlin in the microservices style * Use Kotlin extensions with the Java collections library * Uncover destructuring expressions and find out how to write your own * Understand how Java-nullable code can be integrated with Kotlin features Who this book is for If you’re a beginner or intermediate programmer who wants to learn Kotlin to build applications, this book is for you. You’ll also find this book useful if you’re a Java developer interested in switching to Kotlin.
目录展开

About Packt

Why subscribe?

Packt.com

Contributors

About the authors

About the reviewers

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

Download the color images

Conventions used

Get in touch

Reviews

Section 1: Fundamental Concepts in Kotlin

Getting Started with Kotlin

Technical requirements

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

Kotlin Basics

val and var

Type inference

Basic types in Kotlin

Numbers

Unsigned integers

Booleans

Chars

Strings

Arrays

Comments

Packages

Imports

Wildcard imports

Import renaming

String templates

Ranges

Loops

Exception handling

Instantiating classes

Referential equality and structural equality

This expression

Scope

Visibility modifiers

Private

Protected

Internal

Control flow as expressions

The null syntax

Smart casts

Explicit casting

The when expression

When (value)

The when without argument

Function return

Type hierarchy

Code contracts

Contracts API

Contracts on a function return value

Contracts on method invocation

Limitations

Summary

Object-Oriented Programming in Kotlin

Classes

Access levels

Nested classes

Data classes

Inline classes

Enum classes

Static methods and companion objects

Interfaces

Inheritance

Visibility modifiers

Abstract classes

Interface or abstract classes

Polymorphism

Overriding rules

Inheritance versus composition

Class delegation

Sealed classes

Summary

Section 2: Practical Concepts in Kotlin

Functions in Kotlin

Defining functions

Single expression functions

Member functions

Local functions

Top-level functions

Named parameters

Default parameters

Extension functions

Extension function precedence

Extension functions on null values

Member extension functions

Overriding member extension functions

Companion object extensions

Multiple return values

Infix functions

Operators

Operator overloading

Basic operators

in/contains

Get/set

Invoke

Comparison

Assignment

Java interop

Function literals

Tail recursive functions

Varargs

Spread operator

Standard library functions

Apply

Let

With

Run

Lazy

Use

Repeat

Require/assert/check

Generic functions

Pure functions

Java from Kotlin

Getters and setters

Single abstract methods

Escaping Kotlin identifiers

Java void methods

Kotlin from Java

Top-level functions

Default parameters

Object and static methods

Erasure naming

Checked exceptions

Summary

Higher-Order Functions and Functional Programming

Higher-order functions

Returning a function

Assigning a function

Closures

Anonymous functions

Function references

Top-level function references

Member and extension function references

Bound references

Function-literal receivers

Functions in the JVM

Bytecode

Function composition

Inline functions

Noinline

Currying and partial application

Currying in action

Adding currying support

Memoization

Implementing memoization

Type alias

Either

Fold

Projection

Further projection functions

Custom DSLs

Infix functions as keywords

Using function receivers in a DSL

Validation and error accumulation

Summary

Properties

Why use properties?

Overriding getters and setters

Visibility

Late initialization

Delegated properties

Lazy initializations

Lateinit versus lazy

Observables

A non-null property delegate

Properties or methods?

Summary

Null Safety, Reflection, and Annotations

Nullable types

Smart cast

Safe null access

Force operator

Elvis operator

Safe casting

Optional

Creating and returning an Optional

Using an Optional

Reflection

KClass

Instantiation using reflection

Constructors

Instantiation with callBy

Objects and companions

Useful KClass properties

Reflective functions and properties

Invoking a function reflectively

Declared and undeclared

Annotations

Annotation parameters

Standard annotations

@JvmName

@JvmStatic

@Throws

@JvmOverloads

Runtime annotation discovery

Summary

Generics

Parameterized functions

Parameterized types

Bounded polymorphism

Upper bounds

Multiple bounds

Type variance

Invariance

Covariance

Covariant return

Contravariance

Variance overview

Nothing type

Type projection

Type erasure

Type reification

Recursive type bounds

Algebraic data types

Summary

Data Classes

Introduction to data classes

Automatic creation of getters and setters

The copy method

toString out of the box

The hashCode and equals methods generated for you

Destructed declarations

Destructing types

Data class definition rules

Limitations

Summary

Collections

Class hierarchy

Arrays

Lists

Maps

Sets

Read-only views

Indexed access

Sequences

Summary

Testing in Kotlin

Getting started

Choosing a spec

Matchers

String matchers

Collection matchers

Floating point matchers

Expecting exceptions

Combining matchers

Custom matchers

Inspectors

Interceptors

The test case interceptor

The spec interceptor

Project config

Property testing

Specifying a generator

A custom generator

Table-driven testing

Testing non-deterministic code

Tags, conditions, and config

Config

Conditions

Tags

One instance

Resources

Summary

Microservices with Kotlin

Definition

Drawbacks

Why microservices?

Lagom

Defining services

Implementing a Lagom service

Summary

Section 3: Advanced Concepts in Kotlin

Concurrency

Threads

Blocking

Creating a thread

Stopping a thread

Thread interrupts

CPU-bound versus I/O-bound

Deadlocks and livelocks

The Dining Philosophers Problem

Executors

Race conditions

Monitors

Locks

Read-write locks

Semaphores

he bounded buffer problem

Concurrent collections

ConcurrentHashMap

A blocking queue

Atomic variables

CountDownLatch

CyclicBarrier

Non-blocking I/O and asynchronous programming

Futures

Summary

Coroutines

Suspending functions

Coroutine builders

Launch builder

runBlocking Builder

Structured concurrency

Nested coroutines

Parent-child relationship

Jobs

Cancellation

Join

Job state

Context and scope

Global scope

Cancellation and failure

Cancellation or failure in a parent

Failure in a child coroutine

Supervisor scope

Async

Coroutine dispatchers

Dispatcher inheritance

Wrapping Java executors

With context

Error handling

Summary

Application of Coroutines

Channels

Rendezvous channels

Closing a channel

Producers

Conflated channels

Ticker channels

select expression

Using select for channels

Using select for deferred

Debugging coroutines

Coroutines in action

Concurrent HTTP requests

Blocking IO with coroutines

Using callbacks with coroutines

Summary

Kotlin Serialization

Setup

Json serialization and deserialization

How it works

Protobuf serialization and deserialization

Annotations

Rules

Summary

Other Books You May Enjoy

Leave a review - let other readers know what you think

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部