SlideShare a Scribd company logo
1 of 55
Kotlin Playground
Introduction to Kotlin
Generic Definition of Kotlin
● Kotlin is a general purpose, free, open source, statically typed
“pragmatic” programming language initially designed for the
JVM (Java Virtual Machine) and Android, and combines
object-oriented and functional programming features.
● It is focused on interoperability, safety, clarity, and tooling
support.
What is Kotlin
Kotlin and Java
● At first glance, Kotlin looks like a more concise and
streamlined version of Java.
● The most important reason for introducing Kotlin to Android
advancement was to decrease the number of lines of code
and make development more convenient.
● Everything that can be done utilizing Java can be done
utilizing Kotlin for Android development.
Why Kotlin ?
Basic Syntax
What is val and var?
What is val and var?
In general, it is recommended to use ‘val’ whenever possible,
as it helps to enforce immutability and leads to cleaner, more
maintainable code. However, there may be cases where
mutability is necessary, in which case var can be used.
Getter and Setters
Getter and Setters
The when clause in Kotlin is a type of expression that works
similarly to a switch statement in other programming languages.
It evaluates a given expression and matches it with the branches
(cases) provided in the when clause.
The When Clause
In Android development, the when clause can be used to handle
different cases in a switch-like statement for example, to choose
different actions to perform based on the state of an object, the
user's inputs, or the device's screen orientation. Additionally, the
when clause can also be used in combination with the view model
to perform specific actions for a view based on changes in the
view's state.
The When Clause
After completing basic
syntax
What are lambda functions?
Lambdas expression are function literals means these
functions are not declared but passed immediately as an
expression.
val sum1 = { a: Int, b: Int -> a + b }
or
val sum2:(Int,Int)-> Int = { a , b -> a + b}
Lambda function
Kotlin Collections
What is a collection?
● A collection is a group of related items.
● It is simply an object that groups multiple elements
into a single unit.
● Kotlin supports different kinds of collections
including arrays, lists, mutable lists etc.
GT
Mythpa
13.1M
Arrays
What are Arrays?
Arrays are used to store multiple values in a single
variable, instead of creating separate variables for each
value.
To create an array, use the arrayOf() function, and place
the values in a comma-separated list inside it:
val cars = arrayOf("Volvo", "BMW", "Ford", "Mazda")
You can store any type of data type in array
Methods in Array
1. size
Gives the size of the array.
array.size
2. get()
Gives the element at the specified position.
array.get(element)
3. set()
Changes the element at the specified position.
array.set()
4. indices
returns an IntRange object with valid indices for this list.
array.indices
5. forEach
forEach is used perform the given action on each item of
the array. Inside the code block of forEach, the item
could be referenced as it.
the array.forEach {
//statement(s)
}
Lists
What are Lists?
A list is a collection of items with a
specific order. It is declared using
listOf() syntax. It’s size is fixed. List is
same as array except that in list
elements cannot be modified.
val numbers = listOf(1, 2, 3, 4, 5, 6)
Methods in List
1. forEach()
foreach is used perform the given action on each item of
the list. Inside the code block of forEach, the item could
be referenced as it.
the List.forEach {
//statement(s)
}
2. size
gives the size of the list.
list.size
3. contains()
returns true if element is found in the list, else false.
list.contains(element)
4. first()
used to get the first element of the List.
list.first()
3. last()
used to get the last element of the List.
list.last()
5. get()
returns the element at the specified index in this list.
list.get(index)
6. indices
returns an IntRange object with valid indices for this list.
list.indices
7. indexOf()
finds and returns the index of first occurrence of the
element in the list.
list.indexOf(element)
Mutable lists
What are mutable lists?
MutableList class is used to create
mutable lists in which the
elements can be added or
removed.
fun <T> mutableListOf( vararg
elements: T): MutableList <T>
Methods in list:
1. add()
It adds elements to the list.
val numbers = mutableListOf(1, 2, 3, 4, 5, 6)
numbers.add(7)
2. size
gives the size of the list.
numbers.size
3. contains()
returns true if element is found in the list, else false.
numbers.contains(element)
4. first()
used to get the first element of the List.
numbers.first()
3. last()
used to get the last element of the List.
numbers.last()
5. get()
returns the element at the specified index in this list.
numbers.get(index)
6. indices
returns an IntRange object with valid indices for this list.
numbers.indices
7. indexOf()
finds and returns the index of first occurrence of the
element in the list.
numbers.indexOf(element)
8. elementAt()
Returns the element at the specified index.
numbers.elementAt(index)
9. remove()
Removes the specified element from the list.
numbers.remove(element)
10. removeAt()
Removes the element from the list at specified
position.
numbers.removeAt(element)
OOPs in Kotlin
Examples
Mobile object
Mobile_Phone
Properties:
Company
RAM
Storage
Methods:
call()
text()
Design of class
Access Modifiers
Object declaration
● No constructors are allowed (init blocks are allowed)
● Follows singleton pattern
● Can inherit a class/interface
● Only one instance of the object is created
Properties of an object
Then why use it ?
Consider the example below
Inheritance
What is Inheritance?
● Mechanism in which one
object acquires all the
properties and behaviors of
a parent object.
● Inheritance represents the
IS-A relationship between
objects.
Overriding
Mobile
name
size
makecall()
display()
poweroff()
One Plus
name
size
display()
What is Overriding?
● Overriding is a feature that allows a
subclass or child class to provide a
specific implementation of a
method that is already provided by
one of its superclasses or parent
classes.
Abstraction
Data classes in Kotlin are special
classes specifically designed to
make data storage easy and
convenient. They provide a concise
way of declaring classes without the
need for writing any getters, setters,
equals, hashCode, or toString
methods.
Data classes
What are they ?
Sealed class
Java and Kotlin both are object-oriented programming
languages. But both are used for different purposes.
Kotlin is used to develop android applications while Java
is mainly used for developing enterprise applications.
Kotlin is used when we want to develop an android
application or want to do server-side programming. We
should go with Java if we want to develop an enterprise
application.
Java and Kotlin
Comparison between Java and Kotlin
Kotlin Playground.pptx
Kotlin Playground.pptx
Kotlin Playground.pptx
Kotlin Playground.pptx

More Related Content

Similar to Kotlin Playground.pptx

Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
Renzo Borgatti
 
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2
Umar Ali
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
rohithprabhas1
 
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docxAssg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
festockton
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigeriansKotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin what_you_need_to_know-converted event 4 with nigerians
junaidhasan17
 

Similar to Kotlin Playground.pptx (20)

Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014Clojure beasts-euroclj-2014
Clojure beasts-euroclj-2014
 
Collections
CollectionsCollections
Collections
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
ArrayList.docx
ArrayList.docxArrayList.docx
ArrayList.docx
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
C questions
C questionsC questions
C questions
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2Dotnet programming concepts difference faqs- 2
Dotnet programming concepts difference faqs- 2
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 
9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin9054799 dzone-refcard267-kotlin
9054799 dzone-refcard267-kotlin
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
 
scala.ppt
scala.pptscala.ppt
scala.ppt
 
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docxAssg 14 C++ Standard Template Library (STL)(Extra Credit .docx
Assg 14 C++ Standard Template Library (STL)(Extra Credit .docx
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Kotlin what_you_need_to_know-converted event 4 with nigerians
Kotlin  what_you_need_to_know-converted event 4 with nigeriansKotlin  what_you_need_to_know-converted event 4 with nigerians
Kotlin what_you_need_to_know-converted event 4 with nigerians
 
Mastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_argumentsMastering Python lesson 4_functions_parameters_arguments
Mastering Python lesson 4_functions_parameters_arguments
 
Master in javascript
Master in javascriptMaster in javascript
Master in javascript
 

More from GDSCVJTI (7)

Firebase Introduction.pptx
Firebase Introduction.pptxFirebase Introduction.pptx
Firebase Introduction.pptx
 
GDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptxGDSC Flutter Forward Workshop.pptx
GDSC Flutter Forward Workshop.pptx
 
Kickstart ML.pptx
Kickstart ML.pptxKickstart ML.pptx
Kickstart ML.pptx
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
GDSC FY Orientation.pptx
GDSC FY Orientation.pptxGDSC FY Orientation.pptx
GDSC FY Orientation.pptx
 
Introduction to Google Cloud & GCCP Campaign
Introduction to Google Cloud & GCCP CampaignIntroduction to Google Cloud & GCCP Campaign
Introduction to Google Cloud & GCCP Campaign
 
Introduction to Web Development.pptx
Introduction to Web Development.pptxIntroduction to Web Development.pptx
Introduction to Web Development.pptx
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 

Kotlin Playground.pptx

  • 2. Generic Definition of Kotlin ● Kotlin is a general purpose, free, open source, statically typed “pragmatic” programming language initially designed for the JVM (Java Virtual Machine) and Android, and combines object-oriented and functional programming features. ● It is focused on interoperability, safety, clarity, and tooling support. What is Kotlin
  • 3. Kotlin and Java ● At first glance, Kotlin looks like a more concise and streamlined version of Java. ● The most important reason for introducing Kotlin to Android advancement was to decrease the number of lines of code and make development more convenient. ● Everything that can be done utilizing Java can be done utilizing Kotlin for Android development. Why Kotlin ?
  • 4.
  • 6. What is val and var?
  • 7. What is val and var? In general, it is recommended to use ‘val’ whenever possible, as it helps to enforce immutability and leads to cleaner, more maintainable code. However, there may be cases where mutability is necessary, in which case var can be used.
  • 10. The when clause in Kotlin is a type of expression that works similarly to a switch statement in other programming languages. It evaluates a given expression and matches it with the branches (cases) provided in the when clause. The When Clause
  • 11. In Android development, the when clause can be used to handle different cases in a switch-like statement for example, to choose different actions to perform based on the state of an object, the user's inputs, or the device's screen orientation. Additionally, the when clause can also be used in combination with the view model to perform specific actions for a view based on changes in the view's state. The When Clause
  • 13.
  • 14. What are lambda functions? Lambdas expression are function literals means these functions are not declared but passed immediately as an expression. val sum1 = { a: Int, b: Int -> a + b } or val sum2:(Int,Int)-> Int = { a , b -> a + b} Lambda function
  • 15. Kotlin Collections What is a collection? ● A collection is a group of related items. ● It is simply an object that groups multiple elements into a single unit. ● Kotlin supports different kinds of collections including arrays, lists, mutable lists etc. GT Mythpa 13.1M
  • 16. Arrays What are Arrays? Arrays are used to store multiple values in a single variable, instead of creating separate variables for each value. To create an array, use the arrayOf() function, and place the values in a comma-separated list inside it: val cars = arrayOf("Volvo", "BMW", "Ford", "Mazda")
  • 17. You can store any type of data type in array
  • 18. Methods in Array 1. size Gives the size of the array. array.size 2. get() Gives the element at the specified position. array.get(element)
  • 19. 3. set() Changes the element at the specified position. array.set() 4. indices returns an IntRange object with valid indices for this list. array.indices
  • 20. 5. forEach forEach is used perform the given action on each item of the array. Inside the code block of forEach, the item could be referenced as it. the array.forEach { //statement(s) }
  • 21. Lists What are Lists? A list is a collection of items with a specific order. It is declared using listOf() syntax. It’s size is fixed. List is same as array except that in list elements cannot be modified. val numbers = listOf(1, 2, 3, 4, 5, 6)
  • 22. Methods in List 1. forEach() foreach is used perform the given action on each item of the list. Inside the code block of forEach, the item could be referenced as it. the List.forEach { //statement(s) }
  • 23. 2. size gives the size of the list. list.size 3. contains() returns true if element is found in the list, else false. list.contains(element)
  • 24. 4. first() used to get the first element of the List. list.first() 3. last() used to get the last element of the List. list.last()
  • 25. 5. get() returns the element at the specified index in this list. list.get(index) 6. indices returns an IntRange object with valid indices for this list. list.indices
  • 26. 7. indexOf() finds and returns the index of first occurrence of the element in the list. list.indexOf(element)
  • 27. Mutable lists What are mutable lists? MutableList class is used to create mutable lists in which the elements can be added or removed. fun <T> mutableListOf( vararg elements: T): MutableList <T>
  • 28. Methods in list: 1. add() It adds elements to the list. val numbers = mutableListOf(1, 2, 3, 4, 5, 6) numbers.add(7)
  • 29. 2. size gives the size of the list. numbers.size 3. contains() returns true if element is found in the list, else false. numbers.contains(element)
  • 30. 4. first() used to get the first element of the List. numbers.first() 3. last() used to get the last element of the List. numbers.last()
  • 31. 5. get() returns the element at the specified index in this list. numbers.get(index) 6. indices returns an IntRange object with valid indices for this list. numbers.indices
  • 32. 7. indexOf() finds and returns the index of first occurrence of the element in the list. numbers.indexOf(element) 8. elementAt() Returns the element at the specified index. numbers.elementAt(index)
  • 33. 9. remove() Removes the specified element from the list. numbers.remove(element) 10. removeAt() Removes the element from the list at specified position. numbers.removeAt(element)
  • 39. ● No constructors are allowed (init blocks are allowed) ● Follows singleton pattern ● Can inherit a class/interface ● Only one instance of the object is created Properties of an object
  • 40. Then why use it ? Consider the example below
  • 41. Inheritance What is Inheritance? ● Mechanism in which one object acquires all the properties and behaviors of a parent object. ● Inheritance represents the IS-A relationship between objects.
  • 42.
  • 43. Overriding Mobile name size makecall() display() poweroff() One Plus name size display() What is Overriding? ● Overriding is a feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes.
  • 44.
  • 46. Data classes in Kotlin are special classes specifically designed to make data storage easy and convenient. They provide a concise way of declaring classes without the need for writing any getters, setters, equals, hashCode, or toString methods. Data classes What are they ?
  • 47.
  • 49.
  • 50.
  • 51. Java and Kotlin both are object-oriented programming languages. But both are used for different purposes. Kotlin is used to develop android applications while Java is mainly used for developing enterprise applications. Kotlin is used when we want to develop an android application or want to do server-side programming. We should go with Java if we want to develop an enterprise application. Java and Kotlin Comparison between Java and Kotlin