Learn about the online playground in Kotlin. The playground is a place to try out code snippets, see examples of Kotlin programming techniques, and master the language via the exercises in the Koans.
- [Narrator] The easiest way to get a taste of Kotlin is to use the online playground located at try.kotlinlang.org. I'm going to sign in using my Google Plus credentials. You can also use credentials from Facebook, Twitter, GitHub and JetBrains. Signing in isn't required, but doing so let's you save your work online. In the playground you can write small Kotlin programs. You can also convert Java into Kotlin.
The playground has an extensive collection of code snippets, which illustrated the Kotlin way to do a variety of coding tasks, everything from hello world to function composition. To learn Kotlin, try the Koans. The Koans are a series of 42 programming challenges. The playground provides a partial program and you complete it. Each Koan includes unit test to validate your solution. Complete them all and become a Kotlin guru. There are also code samples from a Kotlin book and a link to the site Advent of Code.
If you'd like to write your own code, scroll down on the left panel until you see my programs. Click the folder with the plus sign, then give your project a name. Let's call it greet. Click the Add button and the playground will create a main function for your code. Let's add the traditional hello world greeting. Notice that print line is included in Kotlin. We don't have to import anything to use it.
To run your app, click the green play triangle on the top right hand side of the page. The output will appear at the bottom of the page. Let's tweak our app to accept a name as an argument. Make sure that the arguments dropdown near the top center of the page is expanded, type your name, now let's tweak our code to accept it. First we'll create a variable called name.
We will check to see if there were any arguments sent to the program and if so, we'll take the first of them, args sub zero, otherwise we'll default and just use the name Kotlin. Next we'll change the string. We'll replace Kotlin World with $name and we'll click the green arrow again. We can see that it's taken the name. Delete the name from the argument and it defaults to displaying hello Kotlin.
While the playground is fun at some point you're going to want to write something more substantial. JetBrains' own IntelliJ IDE is an excellent way to write Kotlin because of its built in support.
- Kotlin as a better Java
- Setting up a Kotlin programming environment
- Val vs. var
- Understanding basic Kotlin programming concepts
- Object-oriented programming
- Using Java from Kotlin
- Using Kotlin from Java
- Annotations, reflection, and DSL construction
- Functional programming in Kotlin