Want to transition from web development to Android development?

Learning Android development will help you publish your first app. Thanks to Kotlin, it's fun too!

Here's a full Kotlin tutorial just for you awesome JavaScript developers!

🧵👇
Okay, first things first.

Kotlin is a statically-typed, general-purpose, cross-platform language that compiles to byte-code for the JVM.

It was designed to fully interop with Java.

1/15
While being statically-typed, Kotlin does have type inference - something that Java doesn't have.

Overall, Kotlin is a very concise and expressive language, especially compared to Java.

Alright, now let's get on with the guide! 📝

Here's an example of some comments:

2/15
Now we're going to look at variables and variable types.

Variables are easy to declare in Kotlin. Here's an example.

3/15
There are 9 basic types for variables (discounting arrays).

Integers:
- Byte
- Short
- Integer
- Long

Decimals:
- Float
- Double

Other:
- Boolean
- String
- Char

Read the details about these types here: https://kotlinlang.org/docs/reference/basic-types.html

4/15
There's also null safety built-in to Kotlin. Read more about it here: https://kotlinlang.org/docs/reference/null-safety.html

Here's some examples:

5/15
Now let's talk about arrays and lists.

You'll find that the syntax for both arrays and lists is simple and expressive.

6/15
There are a few different types of Arrays in Kotlin.

Here's the generic Array type in Kotlin that can hold any value:

7/15
And then there's special array types to prevent boxing/unboxing of primitives:
- ByteArray
- ShortArray
- IntArray
- FloatArray
- DoubleArray

Example:

8/15
Lists are similar to arrays in the way they are handled.

Here's an example:

9/15
Next up are control structures, like if statements, loops, and a special one - when.

First let's look at some if statements. These are similar to the ones in JavaScript, with a few differences:

10/15
Loops are interesting in Kotlin. They are more similar to the loops in Python than JavaScript.

Let's look at for loops first:

11/15
Now let's look at while loops and do-while loops, which aren't very different from Java or JavaScript.

12/15
Finally, there's the when statement, which serves the same purpose as a switch statement.

13/15
Now we're gonna look at functions.

Like JavaScript, functions are first class citizens in Kotlin, which is a luxury that Java developers unfortunately don't enjoy.

Let's look at some examples.

14/15
Okay, that's all for today. I hit my tweet limit for threads 😅.

Tomorrow we'll discuss OOP in Kotlin and the paradigm shift from prototype-based OOP and class-based OOP.

Happy coding! (in Kotlin hopefully!)

15/15
You can follow @darrenfinch_.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.