Kotlin
Java

Imports and Libraries
Kotlin

Created By: Geoffrey Challen
/ Updated: 2021-09-13

Today may be the most important lesson of the entire semester! All kinds of other people are creating and freely sharing useful code that you can use. And today you'll learn how to build on top of those contributions. Don't try to do it yourself! You are not alone...

Objects Beyond String

So far our understanding of Kotlin objects has focused on Strings. We've seen how to create them:

And how to access useful String methods, like length, substring, and split. And we've used these methods to solve problems:

Strings are built in to Kotlin, meaning that we don't need to use import statements to access them. But Kotlin allows you to access lots of other kinds of objects that might be useful for solving other kinds of problems! Today's lesson looks at how to access these other objects in your own code and provides some examples of useful objects and libraries.

Java Interoperability

While Kotlin is a relatively new language, it interoperates with a language called Java that was released in 1996. What does that mean? It means that you can use Java code as a Kotlin programmer! (It also means that you can create libraries for Java programmers to use, but we're not going to discuss that just yet.)

This is a real benefit of Kotlin. Rather than starting from scratch, Kotlin can already use decades worth of mature, well-tested, and useful code written in Java. Awesome! Let's find out how.

import and Libraries

Computer science is a remarkably collaborative field. In no other pursuit are millions of people all across the world so freely willing to share their creations!

Because of this, changing the world through your code has never been easier. Let's see how!

As a Kotlin programmer, you can use both the Kotlin standard library and the Java standard library. Let's look at the Kotlin standard library first.

Provide an overview of the Kotlin Standard Library. Make sure to focus on the JVM components.

Next, let's see how we find interesting and useful Java code that is part of the Java standard library.

Provide an overview of the Java Standard Library.

Next, let's see how to actually load those library classes into our project.

Show how to use the import keyword.

Example Libraries

Now let's look at a few useful parts of the Kotlin Standard Library. No claim that these are the most useful parts! They're just a few examples of code that is already out there for you to use!

kotlin.random

Looking to make your Kotlin programs more interesting? Try introducing some randomess! Let's see how.

Provide a documentation overview of kotlin.random.

Provide a code overview of kotlin.random.

kotlin.math

Computers can do math, right? That might be useful! Let's get past +, -, *, and /.

Provide a documentation overview of kotlin.math.

Provide a code overview of kotlin.math.

Collections

One of the most important part of the Kotlin Standard Library is the collections framework. It provides a variety of different ways of store any kind of Kotlin object.

We certainly couldn't do it justice here. But we'll be covering several of these incredibly useful classes over the next few lessons!

Show how to complete the homework problem above. Feel free to cover multiple approaches!

Solution Walkthrough

Show how to complete the homework problem above. Feel free to cover multiple approaches!

Solution Walkthrough