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

Similar to Why kotlininandroid

DAY1.pptx
DAY1.pptxDAY1.pptx
Synapseindia android apps intro to android development
Synapseindia android apps  intro to android developmentSynapseindia android apps  intro to android development
Synapseindia android apps intro to android developmentSynapseindiappsdevelopment
 
Intro to Android Programming
Intro to Android ProgrammingIntro to Android Programming
Intro to Android Programming
Peter van der Linden
 
MOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptxMOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptx
kamalkantmaurya1
 
moocs_ppt.pptx
moocs_ppt.pptxmoocs_ppt.pptx
moocs_ppt.pptx
kamalkantmaurya1
 
MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)
Peter Presnell
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Tony Frame
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Eugene Kurko
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
UA Mobile
 
Android presentation
Android presentationAndroid presentation
Android presentationImam Raza
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
sullis
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
秀吉(Hsiu-Chi) 蔡(Tsai)
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
Revanth Mca
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
Brian Lyttle
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
James Montemagno
 

Similar to Why kotlininandroid (20)

DAY1.pptx
DAY1.pptxDAY1.pptx
DAY1.pptx
 
Stmik bandung
Stmik bandungStmik bandung
Stmik bandung
 
Synapseindia android apps intro to android development
Synapseindia android apps  intro to android developmentSynapseindia android apps  intro to android development
Synapseindia android apps intro to android development
 
Intro to Android Programming
Intro to Android ProgrammingIntro to Android Programming
Intro to Android Programming
 
MOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptxMOOC_PRESENTATION_KOTLIN[1].pptx
MOOC_PRESENTATION_KOTLIN[1].pptx
 
moocs_ppt.pptx
moocs_ppt.pptxmoocs_ppt.pptx
moocs_ppt.pptx
 
MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)MWLUG 2014: Modern Domino (workshop)
MWLUG 2014: Modern Domino (workshop)
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Activity
ActivityActivity
Activity
 
Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01Googleappengineintro 110410190620-phpapp01
Googleappengineintro 110410190620-phpapp01
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Android presentation
Android presentationAndroid presentation
Android presentation
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
Csharp dot net
Csharp dot netCsharp dot net
Csharp dot net
 
Introduction to Google App Engine with Python
Introduction to Google App Engine with PythonIntroduction to Google App Engine with Python
Introduction to Google App Engine with Python
 
Visual Studio 2017 Launch Event
Visual Studio 2017 Launch EventVisual Studio 2017 Launch Event
Visual Studio 2017 Launch Event
 

Recently uploaded

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
NaapbooksPrivateLimi
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
XfilesPro
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
Jelle | Nordend
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 

Recently uploaded (20)

Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Visitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.appVisitor Management System in India- Vizman.app
Visitor Management System in India- Vizman.app
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 

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

  1. List<String> names = List(<*>) Names.setvalue(1) oncli
  2. ? !! Let
  3. Int num=1 Val num :Int=1
  4. User(u,p) User(u,p,z) User(u,p) Kotlin User(u?=null,p?=null,Z?=null) User(u,p)
  5. 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.
  6. 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
  7. Future Ready