Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

Migrating from Java to Kotlin

Are you a Java developer and have your apps in Java? Are you wondering how you could get started with Kotlin? Worry not, this is your section. Kotlin offers two ways for you:

  • Java-to-Kotlin migration: The IDE that we are using, IntelliJ IDEA, has a tool for converting existing Java files to Kotlin.
  • Interoperability: Kotlin is highly interoperable with Java code, meaning you can have both Java and Kotlin code in the same project. You can continue using your favorite Java libraries in your Kotlin projects.

Let’s see how to migrate a sample Java class to Kotlin using IntelliJ IDEA:

  1. Inside src/main/kotlin, open the Song class, which has a number of Java functions.
  2. Right-click the file and you’ll see the Convert Java to Kotlin option at the bottom. Select this and you’ll be presented the following confirmation dialog:

Figure 1.4 – Confirmation dialog

Figure 1.4 – Confirmation dialog

At times after a conversion, you might need to make some corrections and that’s why we have this dialog. Click Yes to proceed and you’ll see your code is now in Kotlin. This is a useful feature that handles a major part of the conversion to Kotlin and you also learn about the syntax.

Now that we’ve learned how to migrate Java code to Kotlin, in the next section we will cover some of the features of Kotlin that make it useful for Android developers.

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
Banner background image