SlideShare a Scribd company logo
Introduction to Kotlin
Compiler to Run Kotlin Programs
Hello World!
fun main() { // main function
//code starts here
println("Hello World!")
}
Data Types
● Int
● Char
● String
● Float
● Double
● Long
● Short
● Byte
● Boolean
Variables
● Mutable
Starts with ‘var’ and can be reassigned.
For ex:) var age = 20
● Immutable(Read only)
Starts with ‘val’ and cannot be reassigned.
For ex:) var name = “Jack”
Functions
Syntax:
fun func_name(){
//your code
}
fun sayHello() {
println("Hello")
}
fun main() { // main function
//code starts here
sayHello()
}
Examples
fun sayHello() {
println("Hello")
}
fun sayHelloWithName(name:String) {
println("Hello $name")
}
fun addTwoNumbers(x:Int, y:Int) {
print("The sum of the two numbers is ${x + y}")
}
Conditionals in Kotlin
(stuff you would use a lot while making apps)
Operators
if , else if, else
Basic Structure :
if( condition1 ){
// This stuff runs when Condition 1 holds
} else if( condition2 ){
// This runs when Condition 2 holds
} else if( condition3 ){
// This runs when Condition 3 holds
} else{
// If none of the condition holds, this runs
}
if , else if, else
Let’s Try One Example….
if , else if, else as Expression
Example dekhte hai direct…
when statement
//// Similar to switch in C++
//// Used instead of long if else ladder
fun main() {
val x = 2;
when(x) {
1 -> println("One")
2 -> println("Two")
3 -> println("Three")
else -> println("Number not recognized")
}
}
ranges
//// Collection of values from a START point to an END point
//// Similar to ranges in python
A range of number from 1 to 10 : 1..10
val x = 1..10;
A range of number from 10 to 1 : 10 downTo 1
val x = 10 downTo 1
for loop
//// Not like for loops in languages like C++ or Java
//// Used to iterate through a collection
Basic Structure :
for( item in collection ) {
// You could do something with item
}
Let’s look at few Examples…
-> with Ranges
-> with List
-> break, continue with labels
Quiz Time!!!
//// What will be the output of this?
a)
fun main() {
val x = 1..5
val y = 1..10
for( i in x ){
print("$i : ")
for( j in y ){
print("$j ")
if( i == 3 && j == 7 ) break
}
println()
}
}
b)
while Loop
//// Similar to the while loop in C++
//// Used for condition based looping
Basic Structure :
Let’s look at an Example…
while( condition ){
// Execute something
}
do while Loop
//// Runs the body of the loop at least ones even if the
condition doesn’t satisfies
Basic Structure :
Let’s look at an Example…
do{
// Body of the loop
}while ( condition )
repeat
//// Quite not found in any other languages
Basic Structure :
repeat(3) {
println("Hello")
}
Classes & Objects
Classes
Class is template of object
A class is a user defined blueprint or prototype
from which objects are created.
It represents the set of properties or methods that
are common to all objects of one type
Objects
Name : Eshan
Age : 20
Gender: Male
Occupation : Android Developer
Name : Priya
Age : 25
Gender : Female
Occupation : Doctor
Classes
Class : Car
Class is template of object
To Create a class ,
We use class Keyword
Properties of Car
Objects : Instance of Class
Object 1 of Class Car
Jaguar I-PACE Black
0 cc
Object 2 of Class Car
Tata Nano Yellow
624 cc
Create an Object
Constructor
objectName.DataMember
Output
Constructor
There is faster way of doing this
By using a CONSTRUCTOR
A constructor is like a special function, and it is defined by using two parantheses ()
after the class name. You can specify the properties inside of the parantheses (like
passing parameters into a regular function).
Constructor
Without Constructor
By Using Constructor
Properties
Note:
Remember to specify the type of the property/variable
Creating Object by using Constructor
Class Functions
Output
Object
https://pl.kotl.in/_ebphwnyK
Pillars of OOPs
Inheritance
In Kotlin, it is possible to inherit class
properties and functions from one class to
another
SubClass
Child
SuperClass
Parent
Inheritance
Parent
Use the open keyword in front of the superclass/parent, to make this the class other
classes should inherit properties and functions from.
Child
To inherit from a class, specify the name of the subclass, followed by a colon :, and then
the name of the superclass.
In Similar fashion we can inherit functions and other properties from parent to child
https://pl.kotl.in/_ebphwnyK
Polymorphism
Poly means many and morph means forms
i.e. the same method behaves differently based on the object
we have different forms of the
method that exhibits different
behavior based on the object.
Here we can see polymorphism of
area() Function
https://pl.kotl.in/_ebphwnyK
Abstraction
Abstraction is used to hide background details or any unnecessary
implementation about the data so that users only see the required
information.
It is one of the most important and essential features of object-oriented
programming.
Encapsulation
It is a protective shield that prevents the data from
being accessed by the code outside this shield.
Here we can’t access private properties of
class from outside the class
Abstraction
Encapsulation
Main function don’t know how these
setters getters work
Introduction to kotlin and OOP in Kotlin

More Related Content

What's hot

Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
Kurt Renzo Acosta
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
Christian Melchior
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
intelliyole
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
Saurabh Tripathi
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
Simplilearn
 
Kotlin
KotlinKotlin
Kotlin
Rory Preddy
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
EastBanc Tachnologies
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
Dariusz Lorenc
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
Atif AbbAsi
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
intelliyole
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
T.M. Ishrak Hussain
 
Functional programming
Functional programmingFunctional programming
Functional programming
ijcd
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
Alexey Soshin
 
Java vs kotlin
Java vs kotlin Java vs kotlin
Java vs kotlin
RupaliSingh82
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
Syed Awais Mazhar Bukhari
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin Overview
Ekta Raj
 
Introduction to kotlin coroutines
Introduction to kotlin coroutinesIntroduction to kotlin coroutines
Introduction to kotlin coroutines
NAVER Engineering
 
Go lang
Go langGo lang
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
NexThoughts Technologies
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a tree
Kai Koenig
 

What's hot (20)

Kotlin on android
Kotlin on androidKotlin on android
Kotlin on android
 
Coroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in PractiseCoroutines for Kotlin Multiplatform in Practise
Coroutines for Kotlin Multiplatform in Practise
 
The Kotlin Programming Language
The Kotlin Programming LanguageThe Kotlin Programming Language
The Kotlin Programming Language
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022Kotlin InDepth Tutorial for beginners 2022
Kotlin InDepth Tutorial for beginners 2022
 
Kotlin
KotlinKotlin
Kotlin
 
Introduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platformIntroduction to Kotlin Language and its application to Android platform
Introduction to Kotlin Language and its application to Android platform
 
Kotlin - Better Java
Kotlin - Better JavaKotlin - Better Java
Kotlin - Better Java
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Coroutines in Kotlin
Coroutines in KotlinCoroutines in Kotlin
Coroutines in Kotlin
 
Java vs kotlin
Java vs kotlin Java vs kotlin
Java vs kotlin
 
Introduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTXIntroduction to Kotlin - Android KTX
Introduction to Kotlin - Android KTX
 
Kotlin Overview
Kotlin OverviewKotlin Overview
Kotlin Overview
 
Introduction to kotlin coroutines
Introduction to kotlin coroutinesIntroduction to kotlin coroutines
Introduction to kotlin coroutines
 
Go lang
Go langGo lang
Go lang
 
Introduction to gradle
Introduction to gradleIntroduction to gradle
Introduction to gradle
 
Kotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a treeKotlin Coroutines and Android sitting in a tree
Kotlin Coroutines and Android sitting in a tree
 

Similar to Introduction to kotlin and OOP in Kotlin

Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
Jack Nutting
 
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Kotlin For Android - Constructors and Control Flow (part 2 of 7)Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Gesh Markov
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
Abhijeet Dubey
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
Kaushik Raghupathi
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
Hoàng Lâm Huỳnh
 
Lecture6.ppt
Lecture6.pptLecture6.ppt
Lecture6.ppt
ammu241754
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
Luca Guadagnini
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekito
Arnaud Giuliani
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
aprilyyy
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
Coder Tech
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
Aleš Najmann
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
rashmita_mishra
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
Abbas Raza
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
Artur Latoszewski
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
Mohamed Wael
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
hwilming
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
Leo Hernandez
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
Squareboat
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
aeden_brines
 
Postgresql function_basics.pdf
Postgresql function_basics.pdfPostgresql function_basics.pdf
Postgresql function_basics.pdf
svhtayrv
 

Similar to Introduction to kotlin and OOP in Kotlin (20)

Swift, swiftly
Swift, swiftlySwift, swiftly
Swift, swiftly
 
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Kotlin For Android - Constructors and Control Flow (part 2 of 7)Kotlin For Android - Constructors and Control Flow (part 2 of 7)
Kotlin For Android - Constructors and Control Flow (part 2 of 7)
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
C++ Interview Questions
C++ Interview QuestionsC++ Interview Questions
C++ Interview Questions
 
Introduction to Functional Programming
Introduction to Functional ProgrammingIntroduction to Functional Programming
Introduction to Functional Programming
 
Lecture6.ppt
Lecture6.pptLecture6.ppt
Lecture6.ppt
 
7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin7 Sins of Java fixed in Kotlin
7 Sins of Java fixed in Kotlin
 
Kotlin cheat sheet by ekito
Kotlin cheat sheet by ekitoKotlin cheat sheet by ekito
Kotlin cheat sheet by ekito
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScript
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
Introduction to clojure
Introduction to clojureIntroduction to clojure
Introduction to clojure
 
Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?Kotlin coroutine - the next step for RxJava developer?
Kotlin coroutine - the next step for RxJava developer?
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
Exploring Ceylon with Gavin King - JUG BB Talk - Belrin 2014
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Postgresql function_basics.pdf
Postgresql function_basics.pdfPostgresql function_basics.pdf
Postgresql function_basics.pdf
 

Recently uploaded

AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
Paris Salesforce Developer Group
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
MadhavJungKarki
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
sydezfe
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
Kamal Acharya
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
PreethaV16
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
Roger Rozario
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
um7474492
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
uqyfuc
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
harshapolam10
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
Divyanshu
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
AlvianRamadhani5
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
upoux
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
aryanpankaj78
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
vmspraneeth
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
Gino153088
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
Indrajeet sahu
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 

Recently uploaded (20)

AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
AI + Data Community Tour - Build the Next Generation of Apps with the Einstei...
 
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
1FIDIC-CONSTRUCTION-CONTRACT-2ND-ED-2017-RED-BOOK.pdf
 
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
一比一原版(uoft毕业证书)加拿大多伦多大学毕业证如何办理
 
Accident detection system project report.pdf
Accident detection system project report.pdfAccident detection system project report.pdf
Accident detection system project report.pdf
 
Object Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOADObject Oriented Analysis and Design - OOAD
Object Oriented Analysis and Design - OOAD
 
Transformers design and coooling methods
Transformers design and coooling methodsTransformers design and coooling methods
Transformers design and coooling methods
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...smart pill dispenser is designed to improve medication adherence and safety f...
smart pill dispenser is designed to improve medication adherence and safety f...
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
SCALING OF MOS CIRCUITS m .pptx
SCALING OF MOS CIRCUITS m                 .pptxSCALING OF MOS CIRCUITS m                 .pptx
SCALING OF MOS CIRCUITS m .pptx
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
Null Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAMNull Bangalore | Pentesters Approach to AWS IAM
Null Bangalore | Pentesters Approach to AWS IAM
 
5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf5G Radio Network Througput Problem Analysis HCIA.pdf
5G Radio Network Througput Problem Analysis HCIA.pdf
 
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
一比一原版(osu毕业证书)美国俄勒冈州立大学毕业证如何办理
 
Digital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptxDigital Twins Computer Networking Paper Presentation.pptx
Digital Twins Computer Networking Paper Presentation.pptx
 
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICSUNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
UNIT 4 LINEAR INTEGRATED CIRCUITS-DIGITAL ICS
 
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
4. Mosca vol I -Fisica-Tipler-5ta-Edicion-Vol-1.pdf
 
Open Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surfaceOpen Channel Flow: fluid flow with a free surface
Open Channel Flow: fluid flow with a free surface
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 

Introduction to kotlin and OOP in Kotlin

  • 2. Compiler to Run Kotlin Programs
  • 3. Hello World! fun main() { // main function //code starts here println("Hello World!") }
  • 4. Data Types ● Int ● Char ● String ● Float ● Double ● Long ● Short ● Byte ● Boolean
  • 5. Variables ● Mutable Starts with ‘var’ and can be reassigned. For ex:) var age = 20 ● Immutable(Read only) Starts with ‘val’ and cannot be reassigned. For ex:) var name = “Jack”
  • 6. Functions Syntax: fun func_name(){ //your code } fun sayHello() { println("Hello") } fun main() { // main function //code starts here sayHello() }
  • 7. Examples fun sayHello() { println("Hello") } fun sayHelloWithName(name:String) { println("Hello $name") } fun addTwoNumbers(x:Int, y:Int) { print("The sum of the two numbers is ${x + y}") }
  • 8. Conditionals in Kotlin (stuff you would use a lot while making apps)
  • 10. if , else if, else Basic Structure : if( condition1 ){ // This stuff runs when Condition 1 holds } else if( condition2 ){ // This runs when Condition 2 holds } else if( condition3 ){ // This runs when Condition 3 holds } else{ // If none of the condition holds, this runs }
  • 11. if , else if, else Let’s Try One Example….
  • 12. if , else if, else as Expression Example dekhte hai direct…
  • 13. when statement //// Similar to switch in C++ //// Used instead of long if else ladder fun main() { val x = 2; when(x) { 1 -> println("One") 2 -> println("Two") 3 -> println("Three") else -> println("Number not recognized") } }
  • 14. ranges //// Collection of values from a START point to an END point //// Similar to ranges in python A range of number from 1 to 10 : 1..10 val x = 1..10; A range of number from 10 to 1 : 10 downTo 1 val x = 10 downTo 1
  • 15. for loop //// Not like for loops in languages like C++ or Java //// Used to iterate through a collection Basic Structure : for( item in collection ) { // You could do something with item } Let’s look at few Examples… -> with Ranges -> with List -> break, continue with labels
  • 16. Quiz Time!!! //// What will be the output of this? a) fun main() { val x = 1..5 val y = 1..10 for( i in x ){ print("$i : ") for( j in y ){ print("$j ") if( i == 3 && j == 7 ) break } println() } } b)
  • 17. while Loop //// Similar to the while loop in C++ //// Used for condition based looping Basic Structure : Let’s look at an Example… while( condition ){ // Execute something }
  • 18. do while Loop //// Runs the body of the loop at least ones even if the condition doesn’t satisfies Basic Structure : Let’s look at an Example… do{ // Body of the loop }while ( condition )
  • 19. repeat //// Quite not found in any other languages Basic Structure : repeat(3) { println("Hello") }
  • 20.
  • 21.
  • 23. Classes Class is template of object A class is a user defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type
  • 24.
  • 26. Name : Eshan Age : 20 Gender: Male Occupation : Android Developer Name : Priya Age : 25 Gender : Female Occupation : Doctor
  • 27. Classes Class : Car Class is template of object
  • 28. To Create a class , We use class Keyword Properties of Car
  • 29. Objects : Instance of Class Object 1 of Class Car Jaguar I-PACE Black 0 cc Object 2 of Class Car Tata Nano Yellow 624 cc
  • 33. There is faster way of doing this By using a CONSTRUCTOR A constructor is like a special function, and it is defined by using two parantheses () after the class name. You can specify the properties inside of the parantheses (like passing parameters into a regular function). Constructor
  • 34. Without Constructor By Using Constructor Properties Note: Remember to specify the type of the property/variable
  • 35. Creating Object by using Constructor
  • 40. Inheritance In Kotlin, it is possible to inherit class properties and functions from one class to another SubClass Child SuperClass Parent
  • 42. Parent Use the open keyword in front of the superclass/parent, to make this the class other classes should inherit properties and functions from. Child To inherit from a class, specify the name of the subclass, followed by a colon :, and then the name of the superclass. In Similar fashion we can inherit functions and other properties from parent to child
  • 44. Polymorphism Poly means many and morph means forms i.e. the same method behaves differently based on the object
  • 45. we have different forms of the method that exhibits different behavior based on the object.
  • 46. Here we can see polymorphism of area() Function https://pl.kotl.in/_ebphwnyK
  • 47. Abstraction Abstraction is used to hide background details or any unnecessary implementation about the data so that users only see the required information. It is one of the most important and essential features of object-oriented programming.
  • 48. Encapsulation It is a protective shield that prevents the data from being accessed by the code outside this shield.
  • 49. Here we can’t access private properties of class from outside the class Abstraction Encapsulation Main function don’t know how these setters getters work