SlideShare a Scribd company logo
Version: Jan 10, 2019
2
KOTLIN
100 % interoperable with java
Developed By Jet Brains.
3
HISTORY
2010 – Work Started
2011 – Announced
2016 – 1.0 Released
2017 – 1.1 Released
 In Google I/O 2017 they announced that First-class support for Kotlin.
 Android Studio 3.0 is released and Kotlin is by default supported. No other
setup required.
 Kotlin is a growing community and it is also acknowledged by Google.
4
 Null references are controlled by the system.(NPE)
 No raw types.
 Kotlin does not have checked Exceptions.
 Requires more code to do simple tasks.
 Not that friendly with android.
 Inability to add methods in platform APIs, have to use Utils for that.
 For Android ,it’s nullability everywhere
5
WHY KOTLIN?
Kotlin & Java
can exist
together in one
project. You
can keep on
utilizing
existing
libraries in
Java
Concise Safe It's functional
Kotlin & Java
can exist
together in one
project. You
can keep on
utilizing
existing
libraries in
Java
Definitely
reduce the
measure of
standard code
you have to
compose
Avoid entire
classes of
errors such as
null pointer
exceptions
Kotlin utilizes
numerous
ideas from
functional
programming,
for example,
lambda
expressions
100% interoperable with Java
Source: google.com
6
KEY BENEFITS OF ADOPTING KOTLIN
Open
Source
Kotlin Offers
Shortness
Mature
Language
With a Great
IDE Support
Provides an Easier
Way to Develop
AndroidApps
Swift Language
forAndroidApp
Development
Reliable Due
to its
Evolutionary
Process
Much Safer
Than Java
Easy to
Learn
Runs on
JVM
Combines
OO and
Functional
Programin
g
Saves30 - 40%
lines of code
Source: google.com
7
Declaring a variable
 var - Mutable variable
 val – Immutable or final viable
Example:
val name:String=“Pocket Office”// immutable or final
var name:String=“Pocket Office” // mutable
Ex. name=“NCR”
val name=“Pocket Office” // Types are auto-inferred
val num:Int=10// immediate assignment
var personList:List<String>()=ArrayList()
Statically Type
In java : final String name=“Pocket Office”;
In Kotlin: val name=“Pocket Office”
 Double
 Float
 Long
 Int
 Short
 Boolean
 Char
 String
 Array
Basic Data Types
8
Saving time with Kotlin
#1. Static Layout Import
One of the most common boilerplate codes in Android is using the findViewById() function to obtain references to your views in
Activities or Fragments.
For example,
consider the following activity XML layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="co.ikust.kotlintest.MainActivity">
<TextView android:id="@+id/helloWorldTextView“ android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
Import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
helloWorldTextView.text = "Hello World!"
} }
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv=findViewById(R.id.helloWorldTextView);
tv.setText(“Hello World!”);
}
}
9
#2 Writing POJO Classes with Kotlin
public class User {
private String firstName;
private String lastName;
Sting fullname
Stign address
public String
getFirstName() {
return firstName;
}
public void
setFirstName(String
firstName) {
this.firstName =
firstName;
}
public String
getLastName() {
return lastName;
}
public void
setLastName(String
class User {
var firstName: String? = null
Var aadress:String?
var lastName: String? = null
}
Custom accessors can be written, for example:
class User {
var firstName: String? = null
var lastName: String? = null
val fullName: String? get() firstName + " " + lastName }
This saves lots of lines of code
10
#3 Class Inheritance and Constructors
Kotlin classes have a primary constructor and one or more secondary constructors.
An example of defining a primary constructor:
class User constructor (firstName: String, lastName: String){ }
class User(val firstName: String, val lastName: String) {
constructor(firstName: String) : this(firstName, "")
{ //... }
}
Secondary constructor
Inheritance
In Kotlin, all classes extend from Any, which is similar to Object in Java. By default, classes are
closed, like final classes in Java. So, in order to extend a class, it has to be declared as open or
abstract:
open class User(val firstName, val lastName) class Administrator(val firstName, val lastName)
: User(firstName, lastName)
11
#4 Lambda Expressions
fun add(x: Int, y: Int = 1) : Int
{
return x + y;
}
int add(int x)
{
return add(x, 1);
}
int add(int x, int y)
{
return x + y;
} Using Lambda Expressions
view.setOnClickListener(
{ view -> toast("Click")
})
view.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "Clicked on view",
Toast.LENGTH_SHORT).show();
}
};
12
#5 Null Safety
No more Null Pointer Exceptions
Kotlin’s type system is aimed to eliminate this forever.
//Null Safety
var a: String = "abc"
a = null // compilation error
var b: String? = "abc"
b = null // ok
// what about this ?
val l = a.length // Promise no NPE crash
val l = b.length // error: b can be null
13
#6 Extensions and Smart Cast
public static boolean isTuesday(Date
date) {
return date.getDay() == 2;
}
boolean tuesdayBool =
DateUtils.isTuesday(date);
fun Date.isTuesday(): Boolean {
return getDay() ==2
}
val dateToCheck = Date()
println(date.isTuesday())
Extensions
Smart Cast
if (obj instanceOf MyType) {
((MyType)obj).getXValue();
} else {
// Oh no do more
}
if (obj is MyType) {
obj.getXValue()
} else {
// Oh no do more
}
14
… and More
• Visibility Modifiers
• Companion Objects
• Nested, Sealed Classes
• Generics
• Coroutines
• Operator overloading
• Exceptions
• Annotations
• Reflection
• and more
… and Even More
• Infix extension methods
• Interfaces
• Interface Delegation
• Property Delegation
• Destructuring
• Safe Singletons
• Init blocks
• Enums
• Multiline Strings
• Tail recursion
source http://kotlinlang.org/
15
NUMBER OF ANDROID APPS IN KOTLIN
2018 2019
Stats from Jetbrains.com
(Projection)
16
For more information…
• https://developer.android.com/kotlin/
• https://www.jetbrains.com/opensource/kotlin/
• https://discuss.kotlinlang.org/
• https://kotlinlang.org/docs/reference/android-overview.html
Source https://developer.android.com/kotlin/
FURTHER SUPPORT AND INTEGRATIONS
FOR KOTLIN
• start.spring.io
• Kotlin Compiler Plugin
• Kotlin Support in Spring 5.0
• Kotlin Gradle DSL
• @TestInstance(
Lifecycle.PER_CLASS)
• Kotlin Android Extensions
18
THANK YOU
Phani Gullapalli.

More Related Content

PPTX
F# And Silverlight
PDF
JUnit 5 - The Next Generation
PDF
PDF
Lab 5-Android
PPTX
Dependency Injection and Autofac
PDF
High productivity development with Eclipse and Java 8
PDF
Test code that will not slow you down
PPT
Rifartek Robot Training Course - How to use ClientRobot
F# And Silverlight
JUnit 5 - The Next Generation
Lab 5-Android
Dependency Injection and Autofac
High productivity development with Eclipse and Java 8
Test code that will not slow you down
Rifartek Robot Training Course - How to use ClientRobot

Similar to Why kotlininandroid (20)

PDF
Be More Productive with Kotlin
PDF
A quick and fast intro to Kotlin
PPTX
Kotlin: lo Swift di Android (2015)
PPTX
Kotlin - lo Swift di Android
PPTX
Introduction to Kotlin Language and its application to Android platform
PPTX
Exploring Kotlin language basics for Android App development
PDF
Lightning talk: Kotlin
PDF
Summer of Tech 2017 - Kotlin/Android bootcamp
PDF
Little Helpers for Android Development with Kotlin
PDF
Kotlin, smarter development for the jvm
PDF
Kotlin for Android - Vali Iorgu - mRready
PDF
Develop your next app with kotlin @ AndroidMakersFr 2017
PDF
What’s new in Kotlin?
PDF
Kotlin: A pragmatic language by JetBrains
PDF
Having Fun with Kotlin Android - DILo Surabaya
PDF
Kotlin what_you_need_to_know-converted event 4 with nigerians
PDF
Android 101 - Building a simple app with Kotlin in 90 minutes
PDF
ADG Poznań - Kotlin for Android developers
PPTX
PPTX
Kotlin – the future of android
Be More Productive with Kotlin
A quick and fast intro to Kotlin
Kotlin: lo Swift di Android (2015)
Kotlin - lo Swift di Android
Introduction to Kotlin Language and its application to Android platform
Exploring Kotlin language basics for Android App development
Lightning talk: Kotlin
Summer of Tech 2017 - Kotlin/Android bootcamp
Little Helpers for Android Development with Kotlin
Kotlin, smarter development for the jvm
Kotlin for Android - Vali Iorgu - mRready
Develop your next app with kotlin @ AndroidMakersFr 2017
What’s new in Kotlin?
Kotlin: A pragmatic language by JetBrains
Having Fun with Kotlin Android - DILo Surabaya
Kotlin what_you_need_to_know-converted event 4 with nigerians
Android 101 - Building a simple app with Kotlin in 90 minutes
ADG Poznań - Kotlin for Android developers
Kotlin – the future of android
Ad

Recently uploaded (20)

PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Reimagine Home Health with the Power of Agentic AI​
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Essential Infomation Tech presentation.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Nekopoi APK 2025 free lastest update
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
AI in Product Development-omnex systems
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
VVF-Customer-Presentation2025-Ver1.9.pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Reimagine Home Health with the Power of Agentic AI​
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Essential Infomation Tech presentation.pptx
How Creative Agencies Leverage Project Management Software.pdf
Digital Strategies for Manufacturing Companies
wealthsignaloriginal-com-DS-text-... (1).pdf
Understanding Forklifts - TECH EHS Solution
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Nekopoi APK 2025 free lastest update
Design an Analysis of Algorithms I-SECS-1021-03
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
AI in Product Development-omnex systems
How to Migrate SBCGlobal Email to Yahoo Easily
Ad

Why kotlininandroid

  • 2. 2 KOTLIN 100 % interoperable with java Developed By Jet Brains.
  • 3. 3 HISTORY 2010 – Work Started 2011 – Announced 2016 – 1.0 Released 2017 – 1.1 Released  In Google I/O 2017 they announced that First-class support for Kotlin.  Android Studio 3.0 is released and Kotlin is by default supported. No other setup required.  Kotlin is a growing community and it is also acknowledged by Google.
  • 4. 4  Null references are controlled by the system.(NPE)  No raw types.  Kotlin does not have checked Exceptions.  Requires more code to do simple tasks.  Not that friendly with android.  Inability to add methods in platform APIs, have to use Utils for that.  For Android ,it’s nullability everywhere
  • 5. 5 WHY KOTLIN? Kotlin & Java can exist together in one project. You can keep on utilizing existing libraries in Java Concise Safe It's functional Kotlin & Java can exist together in one project. You can keep on utilizing existing libraries in Java Definitely reduce the measure of standard code you have to compose Avoid entire classes of errors such as null pointer exceptions Kotlin utilizes numerous ideas from functional programming, for example, lambda expressions 100% interoperable with Java Source: google.com
  • 6. 6 KEY BENEFITS OF ADOPTING KOTLIN Open Source Kotlin Offers Shortness Mature Language With a Great IDE Support Provides an Easier Way to Develop AndroidApps Swift Language forAndroidApp Development Reliable Due to its Evolutionary Process Much Safer Than Java Easy to Learn Runs on JVM Combines OO and Functional Programin g Saves30 - 40% lines of code Source: google.com
  • 7. 7 Declaring a variable  var - Mutable variable  val – Immutable or final viable Example: val name:String=“Pocket Office”// immutable or final var name:String=“Pocket Office” // mutable Ex. name=“NCR” val name=“Pocket Office” // Types are auto-inferred val num:Int=10// immediate assignment var personList:List<String>()=ArrayList() Statically Type In java : final String name=“Pocket Office”; In Kotlin: val name=“Pocket Office”  Double  Float  Long  Int  Short  Boolean  Char  String  Array Basic Data Types
  • 8. 8 Saving time with Kotlin #1. Static Layout Import One of the most common boilerplate codes in Android is using the findViewById() function to obtain references to your views in Activities or Fragments. For example, consider the following activity XML layout: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="co.ikust.kotlintest.MainActivity"> <TextView android:id="@+id/helloWorldTextView“ android:layout_width="wrap_content" android:layout_height="wrap_content"/> </RelativeLayout> Import kotlinx.android.synthetic.main.activity_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) helloWorldTextView.text = "Hello World!" } } public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv=findViewById(R.id.helloWorldTextView); tv.setText(“Hello World!”); } }
  • 9. 9 #2 Writing POJO Classes with Kotlin public class User { private String firstName; private String lastName; Sting fullname Stign address public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String class User { var firstName: String? = null Var aadress:String? var lastName: String? = null } Custom accessors can be written, for example: class User { var firstName: String? = null var lastName: String? = null val fullName: String? get() firstName + " " + lastName } This saves lots of lines of code
  • 10. 10 #3 Class Inheritance and Constructors Kotlin classes have a primary constructor and one or more secondary constructors. An example of defining a primary constructor: class User constructor (firstName: String, lastName: String){ } class User(val firstName: String, val lastName: String) { constructor(firstName: String) : this(firstName, "") { //... } } Secondary constructor Inheritance In Kotlin, all classes extend from Any, which is similar to Object in Java. By default, classes are closed, like final classes in Java. So, in order to extend a class, it has to be declared as open or abstract: open class User(val firstName, val lastName) class Administrator(val firstName, val lastName) : User(firstName, lastName)
  • 11. 11 #4 Lambda Expressions fun add(x: Int, y: Int = 1) : Int { return x + y; } int add(int x) { return add(x, 1); } int add(int x, int y) { return x + y; } Using Lambda Expressions view.setOnClickListener( { view -> toast("Click") }) view.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(v.getContext(), "Clicked on view", Toast.LENGTH_SHORT).show(); } };
  • 12. 12 #5 Null Safety No more Null Pointer Exceptions Kotlin’s type system is aimed to eliminate this forever. //Null Safety var a: String = "abc" a = null // compilation error var b: String? = "abc" b = null // ok // what about this ? val l = a.length // Promise no NPE crash val l = b.length // error: b can be null
  • 13. 13 #6 Extensions and Smart Cast public static boolean isTuesday(Date date) { return date.getDay() == 2; } boolean tuesdayBool = DateUtils.isTuesday(date); fun Date.isTuesday(): Boolean { return getDay() ==2 } val dateToCheck = Date() println(date.isTuesday()) Extensions Smart Cast if (obj instanceOf MyType) { ((MyType)obj).getXValue(); } else { // Oh no do more } if (obj is MyType) { obj.getXValue() } else { // Oh no do more }
  • 14. 14 … and More • Visibility Modifiers • Companion Objects • Nested, Sealed Classes • Generics • Coroutines • Operator overloading • Exceptions • Annotations • Reflection • and more … and Even More • Infix extension methods • Interfaces • Interface Delegation • Property Delegation • Destructuring • Safe Singletons • Init blocks • Enums • Multiline Strings • Tail recursion source http://kotlinlang.org/
  • 15. 15 NUMBER OF ANDROID APPS IN KOTLIN 2018 2019 Stats from Jetbrains.com (Projection)
  • 16. 16 For more information… • https://developer.android.com/kotlin/ • https://www.jetbrains.com/opensource/kotlin/ • https://discuss.kotlinlang.org/ • https://kotlinlang.org/docs/reference/android-overview.html Source https://developer.android.com/kotlin/
  • 17. FURTHER SUPPORT AND INTEGRATIONS FOR KOTLIN • start.spring.io • Kotlin Compiler Plugin • Kotlin Support in Spring 5.0 • Kotlin Gradle DSL • @TestInstance( Lifecycle.PER_CLASS) • Kotlin Android Extensions

Editor's Notes

  • #5: List<String> names = List(<*>) Names.setvalue(1) oncli
  • #6: ? !! Let
  • #8: Int num=1 Val num :Int=1
  • #10: User(u,p) User(u,p,z) User(u,p) Kotlin User(u?=null,p?=null,Z?=null) User(u,p)
  • #12: Lambda expressions, introduced with Java 8, are one its favorite features. However, things are not so bright on Android, as it still only supports Java 7, and looks like Java 8 won’t be supported anytime soon. So, workarounds, such as Retrolambda, bring lambda expressions to Android. With Kotlin, no additional libraries or workarounds are required. The return value of the function can be omitted, and in that case, the function will return Int. It’s worth repeating that everything in Kotlin is an object, extended from Any, and there are no primitive types Extenstion function aswell to extend the functionality.
  • #13: Nullability • In Java, the NullPointerException is one of the biggest headache’s • Kotlin , ‘null’ is part of the type system • We can explicitly declare a property , with nullable value • For each function, we can declare whether it returns a nullable value
  • #16: Future Ready