KotlinPrelim-Module1Final
KotlinPrelim-Module1Final
Prelim: Module 1
OVERVIEW
OBJECTIVES
ACTIVITY
Instruction: Go to Google Chrome or any web browser that you have, search for “Kotlin Playground”. Upon entering
your search keyword click the first Kotlin Playground website that you see until you arrive on the specified interface.
Once you get in Kotlin Playground, create a simple code that will print your name, age, and address. They should be
printed on different lines. Make a variable declaration on each values and call them inside the println function by
the use of string template or interpolation. Hint: use the dollar($) sign for calling the values.
Sample output:
Upon submission, take a screenshot of your code and the output and send it to my facebook online class account
via “PM”.
Page 1|4
LESSON PROPER
Kotlin Introduction
Basic Syntax
Package Definition and Imports
Kotlin code is usually defined in packages. Package specification should be at the top of the source file.
It is not required to match directories and packages: source files can be placed arbitrarily in the file system.
In Kotlin versions earlier than 1.3, the main function must have a parameter of type Array<String>
println prints its arguments and adds a line break, so that the next thing you print appears on the next line.
Comments
Just like most modern languages, Kotlin supports single-line (or end-of-line) and multi-line (block)
comments.
Page 2|4
package my.demo
import kotlin.text.*
// . . .
fun main() {
println(“Hello World!”)
}
Page 3|4
Variables
Read-only local variables are defined using the keyword val. They can be assigned a value only once.
val PI = 3.14
var x = 0
fun incrementX() {
x += 1
}
String Templates
var a = 1
// simple name in template:
val s1 = “a is $a”
a=2
// arbitrary expression in template:
val s2 = “${s1.replace(“is”, “was”)}, but now is $a”
print(“Hello “)
print(“world! “)
println(“Hello world!”)
REFERENCES
println(42)
Page 4|4