0% found this document useful (0 votes)
5 views

KotlinPrelim-Module1Final

This document outlines a course module on Mobile Application Development using Kotlin for BSIT IV students. It includes an overview of Kotlin's features, objectives for learning the basics of the language, and an activity to create a simple program that prints personal information. Additionally, it covers basic syntax, program entry points, variable declaration, and string templates in Kotlin.

Uploaded by

gemarmelendres95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

KotlinPrelim-Module1Final

This document outlines a course module on Mobile Application Development using Kotlin for BSIT IV students. It includes an overview of Kotlin's features, objectives for learning the basics of the language, and an activity to create a simple program that prints personal information. Additionally, it covers basic syntax, program entry points, variable declaration, and string templates in Kotlin.

Uploaded by

gemarmelendres95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Course Code: MAD Semester: 2nd SEM 2021-2022

Description : Mobile Application Development Year : BSIT IV

Prelim: Module 1
OVERVIEW

Kotlin is a modern but already mature programming language to make developers


happier. It’s concise, safe, interoperable with Java and other languages, and provides many
ways to reuse code between multiple platforms for productive programming.

OBJECTIVES

1. To be able to familiarize and understand the basics of Kotlin programming.


2. Be knowledgeable about the basic syntax of Kotlin.

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.

println function format:


println(“My name is ?”)
println(“I am ? years old”)
println(“I live in ?”)
Fill in the question marks with the correct set of codes to get the desired output.

Sample output:

Upon submission, take a screenshot of your code and the output and send it to my facebook online class account
via “PM”.

Deadline of submission: March 21, 2022 - 9am.

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.

Program Entry Point


An entry point of a Kotlin application is the main function. The return type is not specified, which means that
the function returns nothing.

In Kotlin versions earlier than 1.3, the main function must have a parameter of type Array<String>

Print to the Standard Output


print prints its argument to the standard output.

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.

Block comments in Kotlin can be nested.

Page 2|4
package my.demo
import kotlin.text.*
// . . .

fun main() {
println(“Hello World!”)
}

fun main(args: Array<String>) {


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 a : Int = 1 // immediate assignment


val b = 2 // ‘Int’ type is inferred
val c : Int // Type required when no initializer is provided
c=3 // deferred assignment
Variables that can be reassigned use the var keyword.

var x = 5 // ‘Int’ type is inferred


x += 1
You can declare variables at the top level.

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)

// This is an end-of-line comment


/* This is a block comment on multiple lines. */

/* The comment starts here


/* contains a nested comment */ and ends here. */

Page 4|4

You might also like