lab1
lab1
(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