Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Kotlin for Android 14

You're reading from   Mastering Kotlin for Android 14 Build powerful Android apps from scratch using Jetpack libraries and Jetpack Compose

Arrow left icon
Product type Paperback
Published in Apr 2024
Publisher Packt
ISBN-13 9781837631711
Length 370 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Harun Wangereka Harun Wangereka
Author Profile Icon Harun Wangereka
Harun Wangereka
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Part 1: Building Your App
2. Chapter 1: Get Started with Kotlin Android Development FREE CHAPTER 3. Chapter 2: Creating Your First Android App 4. Chapter 3: Jetpack Compose Layout Basics 5. Chapter 4: Design with Material Design 3 6. Part 2: Using Advanced Features
7. Chapter 5: Architect Your App 8. Chapter 6: Network Calls with Kotlin Coroutines 9. Chapter 7: Navigating within Your App 10. Chapter 8: Persisting Data Locally and Doing Background Work 11. Chapter 9: Runtime Permissions 12. Part 3: Code Analysis and Tests
13. Chapter 10: Debugging Your App 14. Chapter 11: Enhancing Code Quality 15. Chapter 12: Testing Your App 16. Part 4: Publishing Your App
17. Chapter 13: Publishing Your App 18. Chapter 14: Continuous Integration and Continuous Deployment 19. Chapter 15: Improving Your App 20. Index 21. Other Books You May Enjoy

Introduction to Kotlin

Kotlin is a language that runs on the Java Virtual Machine (JVM) developed by JetBrains. It was developed to overcome the following challenges that Java had:

  • Verbosity: Java has a very verbose syntax and this leads to developers writing a lot of boilerplate code even for trivial tasks.
  • Null pointer exceptions: By default, Java allows variables to have null values. This normally results in null pointer exceptions, which has been called the billion-dollar mistake in Java as many applications have been affected by this.
  • Concurency: Java has threads, but managing concurrency and thread safety can be such a hard task at times. This leads to a lot of performance and memory issues that seriously affect applications that need to do work off the main thread.
  • Slow adoption of features: The Java release cycle is slow and it is difficult to use the latest Java version to develop Android apps as there’s a lot to be done to ensure backward compatibility. This means it’s hard for Android developers to easily adopt the new language features and improvements as they’re stuck using older versions.
  • Lack of functional support: Java is not a functional language, which makes it hard for developers to write functional code in Java. It’s hard to employ features such as high-order functions or treat functions as first-class citizens.

Over the years, Kotlin has evolved to be multiplatform and server-side and not serviced, and is used in data science as well. Some of the features where Kotlin has an edge over Java are as follows:

  • Conciseness: The syntax is concise, which in turn reduces the amount of boilerplate code that you write.
  • Null safety: Many Java developers are very familiar with the famous Null Pointer Exception that was a source of many bugs and issues in applications. Kotlin was designed with null safety in mind. Variables that can have null values are indicated when declaring them, and before using these variables, the Kotlin compiler enforces checks for nullability, thereby reducing the number of exceptions and crashes.
  • Coroutines support: Kotlin has built-in support for Kotlin coroutines. Coroutines are lightweight threads that you can use to perform asynchronous operations. It’s easy to understand and use them in your applications.
  • Data classes: Kotlin has a built-in data class construct that makes it easy to define classes that are used primarily to store data. Data classes automatically generate equals(), hashCode(), and toString() methods, reducing the amount of boilerplate code required.
  • Extension functions: Kotlin allows developers to add functions to existing classes without inheriting from them, through extension functions. This makes it easier to add functionality to existing classes and reduces the need for boilerplate code.
  • Smart casting: Kotlin’s smart casting system makes it possible to cast variables without the need for an explicit cast. The compiler automatically detects when a variable can be safely cast and performs the cast automatically.

JetBrains is also the company behind IntelliJ IDEA. The language support in this Integrated Development Environment (IDE) is also great.

Kotlin has evolved over the years to support the following different platforms:

  • Kotlin Multiplatform: This is used to develop applications that target different platforms such as Android, iOS, and web applications
  • Kotlin for server side: This is used to write backend applications and a number of frameworks to support server-side development
  • Kotlin for Android: Google has supported Kotlin as a first-class language for Android development since 2017
  • Kotlin for JavaScript: This provides support for writing Kotlin code that is transpiled to compatible JavaScript libraries
  • Kotlin/Native: This compiles Kotlin code to native binaries and runs without a Java Virtual Machine (JVM)
  • Kotlin for data science: You can use Kotlin to build and explore data pipelines

In summary, Kotlin provides a more modern and concise approach to programming than Java while still maintaining interoperability with existing Java libraries and code. In addition, you can write Kotlin code and target different platforms.

Now that we have got the gist of Kotlin and its various features, let’s move on to the next section where we will understand Kotlin as a programming language and understand Kotlin syntax, types, functions, and classes.

You have been reading a chapter from
Mastering Kotlin for Android 14
Published in: Apr 2024
Publisher: Packt
ISBN-13: 9781837631711
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime