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

lab1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

lab1

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

MOBILE PROGRAMMING Prepared by:

Eng. Marwa ELDeeb


I
WHAT IS KOTLIN?
Kotlin is a modern, trending programming language that was released
in 2016 by JetBrains.
It has become very popular since it is compatible with Java (one of
the most popular programming languages out there), which means
that Java code (and libraries) can be used in Kotlin programs.
FEATURE OF KOTLIN
Concise code: Kotlin makes sure that each line of code carries some
meaning with it.
Null Safe: Kotlin make sure that our program does not throw
NullPointerException at runtime
Interoperable: Kotlin is fully interoperable with Java. It means you
can use Java libraries, call Java methods, extend Java classes,
implement Java interfaces etc in your Kotlin codebase.
JavaScript Translation: You can translate your Kotlin code to JavaScript
code. So, we can write our code in Kotlin, translate it to JavaScript and
run it on browsers.
KOTLIN USED FOR..
Mobile applications (specially Android apps)
Web development
Server side applications
Data science
And much, much more!
WHY KOTLIN??
Kotlin is fully compatible with Java
Kotlin works on different platforms (Windows, Mac, Linux, Raspberry
Pi, etc.)
Kotlin is easy to learn, especially if you already know Java
Kotlin is free to use
KOTLIN IS (INTERPRETED OR
COMPILED) LANGUAGE?
Kotlin is both a compiled language and an interpreted language

(when targeting the JVM, Kotlin is compiled to JVM *.class files, which
is a bytecode format that can later be either interpreted by a JVM, or
compiled to the machine code by the JVM during the program run (JIT))
START WITH KOTLIN
To declare function we must use keyword fun.
The main() function is used to execute code.
Any code inside the main() function's curly brackets{} will be
executed.
The println() function is used to output/print text and insert a new
line at the end of the output.
The print() function is similar to println() but The difference
between them is: print() does not insert a new line at the end of
the output.
START WITH KOTLIN
START WITH KOTLIN
COMMENT IN KOTLIN
Use // for short comments (Single-line comments).
Use /* and ends with */ for long comments (Multi-line comments).
KOTLIN VARIABLE
Variables are containers for storing data values
To create a variable, use var or val, and assign a value to it with the
equal sign (=).
The difference between var and val is that variables declared with the
var keyword can be changed/modified, while val variables cannot.
 You can also use the + character to add a variable to another
variable.
 For numeric values, the + character works as a mathematical
operator
KOTLIN VARIABLES NAME
Names can contain letters, digits, underscores, and dollar signs
 Names should start with a letter
 Names can also begin with $ and _ (but we will not use it in this
tutorial) • Names are case sensitive ("myVar" and "myvar" are
different variables)
 Names should start with a lowercase letter and it cannot contain
whitespace
 Reserved words (like Kotlin keywords, such as var or String) cannot
be used as names
KOTLIN VARIABLES
KOTLIN DATA TYPES
Data types in kotlin are divided into different groups:
• Numbers
• Characters
Note:you cannot use ASCII values to display certain characters. The
value 66 would output a "B" in Java, but will generate an error in Kot
Example
val myLetter: Char = 66
println(myLetter) // Error
• Booleans
• Strings
• Arrays
KOTLIN DATA TYPES
CONVERSION
To convert data type to another type, you must use one of the following
functions:
toByte(), toShort(), toInt(), toLong(), toFloat(), toDouble(), toChar() or
toString().
KOTLIN INPUT
The readLine() function is used to read a line of string in Kotlin (take input).
INTEGRATED DEVELOPMENT
ENVIRONMENT SOFTWARE/JAVA
For Kotlin, the most popular IDE is IntelliJ IDEA and Android
Studio. IntelliJ IDEA is built by the same company which
developed Kotlin, JetBrains.
We will use IntelliJ IDEA in our course
THANKS Eng.Marwa
ELDeeb

You might also like