KOTLIN VARIABLE
kevin.santiago83
Created on March 6, 2022
More creations to inspire you
THE MESOZOIC ERA
Presentation
ALL THE THINGS
Presentation
ASTL
Presentation
VISUAL COMMUNICATION AND STORYTELLING
Presentation
ENGLISH IRREGULAR VERBS
Presentation
GROWTH MINDSET
Presentation
BLENDED LEARNING
Presentation
Transcript
Kotlin : BASIC TYPES AND VARIABLES
Chapter 2
1. Introduction
3. Things to know about variable's value
2. How to declare variable and type
4. Store multiple values in an array
5. Things to know about Strings
INDEX
6. Conclusion
1. iNTRODUCTION
YOUR CODE NEEDs VARIABLEs !!
What is a variable
Small cups
Give it a name
Tell if the variable can be reused or not
Choose a type
Assign a value
hOW TO CREATE A VARIABLE
2. How to declare VARIABLE AND type
What happends when you declare a variable
Be careful about the type.
Let the compiler choose
What happens when you declare a variable
val --> can't be changed
Hexadecimal and binary
Kotlin's basic types
Integers
Floating points
Boolean
Characters and String
Binary : prefix 0b
Hexadecimal : prefix 0x
Float : 32 bits
exemple : var x = 123.5
Double : 64 bits
char : only one character, with single quotes
string : multiples characters, with doubles quotes
boolean : true or false
What happens when you declare a variable
3. THINGS TO KNOW ABOUT VARIABLE'S VALUE
Make sure that their types are compatible
Assigning a value to an other variable
Example :
Can't create a variable from a type to another
Assigning a value to an other variable
Example :
Use functions
Example :
Functions : useful when new object is larger
Be careful when new object is smaller
Example :
var var1 : Long = 1234567890123
var var2 = var1.toInt() // Value is 1912276171
var x = 123.456
var y : Int = x.toInt() // Value is 123
4. Store multiple values in array
How to create an array ?
arrayOf()
size
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
How can we update an array ?
Example :
Be careful with the type of the array
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
How can we explicitly define the array's type ?
Example :
Val and Var ?
4. Things to know about Strings
String templates
Allows you to construct complex Strings with very little code !
Conclusion