ENGLISH

Kotlin Programming Cookbook: Explore more than 100 recipes that show how to build robust mobile and web applications with Kotlin, Spring Boot, and Android

Book information

Publisher
Packt Publishing
Year
2018
ISBN
1788472144, 9781788472142
Language
english
Format
PDF
Filesize
8 MB (8658659 bytes)
Pages
434\423
Time added
2020-05-23 11:25:13

Description

Discover Android programming and web development by understanding the concepts of Kotlin Programming Key FeaturesPractical solutions to your common programming problems with Kotlin 1.1Leverage the functional power of Kotlin to ease your Android application developmentLearn to use Java code in conjunction with Kotlin Book Description The Android team has announced first-class support for Kotlin 1.1. This acts as an added boost to the language and more and more developers are now looking at Kotlin for their application development. This recipe-based book will be your guide to learning the Kotlin programming language. The recipes in this book build from simple language concepts to more complex applications of the language. After the fundamentals of the language, you will learn how to apply the object-oriented programming features of Kotlin 1.1. Programming with Lambdas will show you how to use the functional power of Kotlin. This book has recipes that will get you started with Android programming with Kotlin 1.1, providing quick solutions to common problems encountered during Android app development. You will also be taken through recipes that will teach you microservice and concurrent programming with Kotlin. Going forward, you will learn to test and secure your applications with Kotlin. Finally, this book supplies recipes that will help you migrate your Java code to Kotlin and will help ensure that it's interoperable with Java. What you will learnUnderstand the basics and object-oriented concepts of Kotlin ProgrammingExplore the full potential of collection frameworks in KotlinWork with SQLite databases in Android, make network calls, and fetch data over a networkUse Kotlin's Anko library for efficient and quick Android developmentUncover some of the best features of Kotlin: Lambdas and DelegatesSet up web service development environments, write servlets, and build RESTful services with KotlinLearn how to write unit tests, integration tests, and instrumentation/acceptance tests.Who This Book Is For This book will appeal to Kotlin developers keen to find solutions for their common programming problems. Java programming knowledge would be an added advantage. Table of ContentsInstallation and working with EnvironmentControl flow Classes and Objects Functions Object oriented programmingCollections Framework Handling File operations in KotlinAnko Commons and Extension function Anko LayoutsDatabases and Dependency Injection Networking and Concurrency Lambdas and DelegatesTestingWeb services with Kotlin Cover Title Page Copyright and Credits Packt Upsell Contributors Table of Contents Preface Chapter 1: Installation and Working with Environment Introduction Creating Kotlin Android project Getting ready How to do it... There's more... How to use Gradle to run Kotlin code Getting ready How to do it... There's more... See also How to run a Kotlin compiled class Getting ready How to do it... How it works... There's more... How to build a self-executable JAR with Gradle and Kotlin Getting ready How to do it... How it works... Reading console input in Kotlin Getting ready How to do it... How it works... Converting Java code to Kotlin and vice versa Getting ready How to do it... How it works... How to write an idiomatic logger in Kotlin Getting ready How to do it... How it works... There's more... See also Escaping for Java identifiers that are keywords in Kotlin Getting ready How to do it... How it works... Disambiguating using the "as" keyword to locally rename the clashing entity Getting ready How to do it... Doing bit manipulations in Kotlin Getting ready How to do it... Or and xor inv shl shr ushr How it works... Parsing String to Long, Double, or Int Getting ready How to do it... Converting String to Long Converting string to Long using string.toLongOrNull() Converting with special radix Parsing string to Long with special radix How it works... There's more... Using String templates in Kotlin How to do it... How it works... There’s more... Chapter 2: Control Flow Introduction Assigning result to an expression using the if keyword Getting ready How to do it... There's more... Using range with the when expression Getting ready How to do it... How it works... There's more... Using when with custom objects Getting ready How to do it... How it works... Using try–catch as an expression Getting ready How to do it... How it works... There's more... How to write a swap function in Kotlin using the also function Getting ready How to do it... How it works... There's more... How to throw a custom exception in Kotlin Getting ready How to do it... How it works... How to make a multiconditional loop in Kotlin Getting ready How to do it... How it works... Chapter 3: Classes and Objects Introduction Initializing body of constructor Getting ready How to do it... Converting one data type into another Getting ready How to do it... How it works... How to type check an object Getting ready How to do it... How it works... There's more... How to work with an abstract class in Kotlin Getting ready How to do it... How it works... How to iterate over a class's properties in Kotlin Getting ready How to do it... How it works... There's more... How to work with inline properties Getting ready How to do it... How it works... How to work with nested class Getting ready How to do it... How it works... There's more... Getting class in Kotlin How to do it... There's more... Working with delegated properties Getting ready How to do it... There's more... Working with enums Getting ready How to do it... There's more... Chapter 4: Functions Introduction Specifying default values in functions Getting ready How to do it... There's more... Using named arguments in functions Getting ready How to do it... Creating the RecyclerView Adapter in Kotlin Getting ready How to do it... How it works... There's more... Creating getter setters in Kotlin Getting ready How to do it... There's more... Passing variable arguments to a function Getting ready How to do it... How it works... There's more... Passing a function as a parameter to another Getting ready How to do it... How it works... Declaring a static function Getting ready How to do it... Using the use keyword in Kotlin Getting ready How to do it... How it works... Working with closures Getting ready How to do it... There's more... Function literals with receivers Getting ready How to do it... Working with anonymous functions Getting ready How to do it... Chapter 5: Object-Oriented Programming Introduction Working with interfaces in Kotlin Getting ready How to do it… There's more… How to implement complicated interfaces with multiple overridden methods in Kotlin Getting ready How to do it… How to extend a class in Kotlin (Inheritance and Extension functions) Getting ready How to do it… Extension functions How it works… There's more… How to work with Generics in Kotlin Getting ready How to do it… There's more… How to implement polymorphism in Kotlin Getting ready How to do it… Restricting class hierarchies Getting ready How to do it… How it works… There's more… Chapter 6: Collections Framework Introduction How to merge two collections Getting ready How to do it… Splitting original collection into pair of collections Getting ready How to do it… How it works… There's more… Sorting a list by specified comparator Getting ready How to do it… How it works… Sorting in descending order Getting ready How to do it… How it works… Parsing a JSON response using Gson Getting ready How to do it… There's more… How to filter and map using lambda expressions Getting ready How to do it… How to sort a list of objects and keep null objects at the end Getting ready How to do it… How it works… How to implement a lazy list in Kotlin Getting ready How to do it… How it works… How to pad a string in Kotlin Getting ready How to do it… How it works… How to flatten an array or map Getting ready How to do it… How it works… How to sort collection by multiple fields in Kotlin Getting ready How to do it… How it works… How to use limit in Kotlin list Getting ready How to do it… How to create a 2D array in Kotlin Getting ready How to do it… There's more… How to skip the first "n" entries in Kotlin Getting ready How to do it… How it works… Chapter 7: Handling File Operations in Kotlin Introduction Reading from files using InputReader Getting ready How to do it… How it works… There's more… Reading all lines in a file using InputReader Getting ready How to do it… How it works… Reading line by line using InputReader Getting ready How to do it… How it works… Reading from files using BufferedReader Getting ready How to do it… How it works… Reading all lines in a file using BufferedReader Getting ready How to do it… How it works… Reading line by line using bufferedReader Getting ready How to do it… How it works… There's more… Reading string and JSON over network Getting ready How to do it… How it works… Chapter 8: Anko Commons and Extension Function Introduction Setting up Anko with Gradle Getting ready How to do it… Extending Android framework using extension function Getting ready How to do it… How it works… There's more… Using extensions as properties Getting ready How to do it… How it works… There's more… Using intents with Anko Getting ready How to do it… How it works… Making a call intent using Anko Getting ready How to do it… How it works… Sending a text intent using Anko Getting ready How to do it… How it works… Browsing the web browser using Anko Getting ready How to do it… How it works… Sharing some text using intents in Anko Getting ready How to do it… How it works… Sending an email using Anko Getting ready How to do it… How it works… Creating Android dialogs with Anko Getting ready How to do it… Showing an alert dialog with a list of text items Getting ready How to do it… How it works… Using Anko in Views Getting ready How to do it… Logging using Anko Getting ready How to do it… Handling dimensions with Anko Getting ready How to do it… Version checking on Android Getting ready How to do it… How it works… Chapter 9: Anko Layouts Introduction Setting up Anko library for Anko layouts in Gradle Getting ready How to do it… How it works… There's more… Creating user-interface programmatically Getting ready How to do it… How it works… Working with the old code of XML layouts Getting ready How to do it… How it works… There's more… Using the provided AnkoComponent interface Getting ready How to do it… How it works… There's more… Setting theme for Android views in Anko Getting ready How to do it… Setting layout parameters for Anko views Getting ready How to do it… How it works… Adding listeners to Anko views Getting ready How to do it… How it works… There's more… Inserting XML layouts into DSL Getting ready How to do it… Converting XML files into DSL Getting ready How to do it… Showing Snackbar Getting ready How to do it… Showing Toasts Getting started How to do it… Accessing views using synthetic properties Getting ready How to do it… Accessing views of view groups using extension functions Getting ready How to do it… How it works... Chapter 10: Databases and Dependency Injection Introduction Using SQLite database in Kotlin Getting ready How to do it… Creating database tables Getting ready How to do it… Injecting dependencies in Kotlin Getting ready How to do it… How it works… Reading data from database Getting ready How to do it… Converting database cursor into list of objects Getting ready How to do it… Using parseOpt for nullable object Getting ready How to do it… Inserting data into database Getting ready How to do it… Creating singletons in Kotlin Getting ready How to do it… How it works… Using Dagger 2 with Kotlin Getting ready How to do it… Using Butterknife with Kotlin Getting ready How to do it… There's more… Chapter 11: Networking and Concurrency Introduction How to fetch data over network Getting ready How to do it… There's more… How to create data class in Kotlin Getting ready How to do it… There's more… How to copy data class with modifications Getting ready How to do it… There's more… How to parse JSON data from network to data class Getting ready How to do it… How to download a file in Kotlin Getting ready How to do it… How to use RxJava and Retrofit with Kotlin Getting ready How to do it… How to make an endless list using RecyclerView Getting ready How to do it… How it works… How to use Anko to run background tasks with Kotlin in Android Getting ready How to do it… How it works… How to use coroutines to achieve multithreading Getting ready How to do it… There's more… Chapter 12: Lambdas and Delegates Introduction Click listeners using lambdas Getting ready How to do it… How it works… There's more… Using lazy delegate in Kotlin Getting ready How to do it… How it works… Using the observable delegate Getting ready How to do it… There's more… Using vetoable delegate Getting ready How to do it… How it works… There's more… Writing your own delegates Getting ready How to do it… How it works… Using the lateinit modifier Getting ready How to do it… There's more… Working with SharedPreferences Getting ready How to do it… There's more… Creating a chain of multiple lets in Kotlin Getting ready How to do it… Creating global variables Getting ready How to do it… Chapter 13: Testing Introduction Unit testing Kotlin code Getting ready How to do it… How it works… Unit testing with Mockito Getting ready How to do it… There's more… Spy object Mockito limitations Running instrumentation tests Getting ready How to do it… There's more… Writing JUnit rules in Kotlin (@Rule) Getting ready How to do it… How it works… Acceptance tests using Espresso Kotlin Getting ready How to do it… There's more… Writing assertEquals in Kotlin Getting ready How to do it… Chapter 14: Web Services with Kotlin Introduction How to run the application on Tomcat How to do it… Setting up dependencies for building RESTful services Getting ready How to do it… How to create a REST controller Getting ready How to do it… There's more… Creating the Application class for Spring Boot Getting ready How to do it… Other Books You May Enjoy Index

Similar books

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

Session C11: Ancient Cultural Landscapes in South Europe – their Ecological Setting and Evolution, Session C22: Gardeners from South America, Session S04: Agro-Pastoralism and Early Metallurgy Sessions, Session WS29: The Idea of Enclosure in Recent Iberian Prehistory, Session C88: Rhytmes et causalites des dynamiques de l'anthropisation en Europe entre 6500 ET 500 BC: Hypotheses socio-culturelles et/ou climatiques: Proceedings of the XV UISPP World Congress (Lisbon 4-9 September 2006) / Actes du XV Congrès Mondial (Lisbonne 4-9 Septembre 2006) Vol.36

2010 · PDF

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

THE BRITISH ARMY IN INDIA: ITS PRESERVATION BY AN APPROPRIATE CLOTHING, HOUSING, LOCATING, RECREATIVE EMPLOYMENT, AND HOPEFUL ENCOURAGEMENT OF THE TROOPS. with AN APPENDIX ON INDIA : THE CLIMATE OP ITS HILLS ; THE DEVELOPMENT OF ITS RESODRCBS, INDUSTRY, AND ARTS ; THE ADMINISTRATION OF JUSTICE ; THE BLACK ACT ; THE PROGRESS OF CHRISTIANITY ; THE TRAFFIC IN OPIUM ; THE VALUE OF INDIA ; PERMANENT CAUSES OF DISAFFECTION, AND OF THE RECENT REBELLION ; THE TRADITIONARY POLICY; MISGOVERNMENT BY NATIVE RULERS ; ANNEXATIONS OF THEIR TERRITORY, ETC.

1858 · PDF

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

Idries Shah 27 Books Collection : A Perfumed Scorpion, A Veiled Gazelle, Caravan of Dreams, Darkest England, Destination Mecca, Evenings with Idries Shah, Knowing How to Know, Learning How to Learn, Letters and Lectures of Idries Shah, Neglected aspects of Sufi study, Observations, Oriental Magic, Reflections, Seeker after Truth, Special Illumination, Special Problems in the study of Sufi ideas, Sufi thought and action, Tales of the Dervishes, The Dermis Probe, The Elephant in the Dark, The Englishman Handbook, Idries Shah Antology, The Magic Monastery, The natives are restless, wisdom of the Idiots PDF.

2022 · PDF

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

The travels of Capts. Lewis and Clarke from St. Louis, by way of the Missouri and Columbia rivers, to the Pacific ocean; performed in the years 1804, 1805 & 1806, by order of the government of the United States. Containing delineations of the manners, customs, religion, &c. of the Indians, comp. from various authentic sources, and original documents, and a summary of the Statistical view of the Indian nations, from the official communication of Meriwether Lewis. Illustrated with a map of the country, inhabited by the western tribes of Indians

1809 · PDF