SlideShare a Scribd company logo
Kotlin Basic & Android
Programming
Handled By
Dr.T.Abirami
Associate Professor
Department of IT
Kongu Engineering College Perundurai
Why Learn Kotlin?
• Kotlin is 100 percent interoperable with Java.
Hence your Java/Android code works with Kotlin.
• Kotlin allows you to cut off the lines of code by
approximately 40% (compared to Java).
• Learning Kotlin is easy. It is particularly easy if
you already know Java.
• Kotlin is tool-friendly. You can use any Java IDE or
command line to run Kotlin.
Present and Future of Kotlin
Present
• Many companies like Netflix, Uber, Trello, Pinterest, Corda, etc
are using Kotlin (along with other programming languages) to
create applications.
• Google's Android team announced Kotlin as an official language
for Android app development.
• You can replace Java code with Kotlin seamlessly. It is 100%
interoperable with Java and Android.
Future
• Cross-platform game development
• Cross-platform mobile application development
• Server-side and microservices
• Data analysis and machine learning
• Embedded system: Arduino/Raspberry Pi to professional
controllers directly
Kotlin
• Kotlin is a programming language introduced
by JetBrains
• The main() function in Kotlin is the entry point
to a Kotlin program.
• It supports both procedural programming and
object oriented programming.
Program entry point
fun main()
{
println("Hello world!")
}
------------------------------
fun main(args: Array<String>) {
println("Hello World!")
print("Welcome to JavaTpoint")
}
fun main(args: Array<String>){
println(10)
println("Welcome to JavaTpoint")
print(20)
print("Hello")
}
10 Welcome to JavaTpoint
20Hello
Kotlin Output
Variable Declaration
Kotlin variable is declared using keyword var and val.
• var (Mutable variable): We can change the value of
variable declared using var keyword later in the
program.
• val (Immutable variable): We cannot change the
value of variable which is declared using val keyword.
• var language ="Java"
• val salary = 30000
explicitly specify the type of variable while declaring it.
• var language: String ="Java"
• val salary: Int = 30000
Example
• var salary = 30000
• salary = 40000 //execute
Here, the value of variable salary can be changed (from
30000 to 40000) because variable salary is declared
using var keyword.
• val language = "Java"
• language = "Kotlin" //Error
Here, we cannot re-assign the variable language from
"Java" to "Kotlin" because the variable is declared
using val keyword.
• val a: Int = 1 // immediate assignment
• val b = 2 // `Int` type is inferred
• val c: Int // Type required when no initializer is
provided
• c = 3 // deferred assignment
var x = 5 // `Int` type is inferred
x += 1
val PI = 3.14
var x = 0
fun incrementX() {
x += 1
}
fun main(args: Array<String>)
{
val first: Int = 10
val second: Int = 20
val sum = first + second
println("The sum is: $sum")
}
Kotlin Input
• standard library function readLine()- is used for reads line
of string input from standard input stream.
fun main(args: Array<String>) {
println("Enter your name")
val name = readLine()
println("Enter your age")
var age: Int =Integer.valueOf(readLine())
println("Your name is $name and your age is $age")
}
Example Getting Integer Input
import java.util.Scanner
fun main(args: Array<String>) {
val read = Scanner(System.`in`)
println("Enter your age")
var age = read.nextInt()
println("Your input age is "+age)
}
User-defined Function
fun main(args: Array<String>)
{
sum()
print("code after sum")
}
fun sum()
{
var num1 =8
var num2 = 9
println("sum = "+(num1+num2))
}
fun functionName()
{
//body of the code
}
• function having two Int parameters
with Int return type:
fun sum(a: Int, b: Int): Int
{
return a + b
}
Unit return type can be omitted:
fun printSum(a: Int, b: Int): Unit {
println("sum of $a and $b is ${a + b}")
}
Conditional expressions
fun maxOf(a: Int, b: Int): Int {
if (a > b) {
return a
} else {
return b
}
}
for loop
Syntax:
for (item in collection)
print(item)
----------------------------------------------------------------
for (i in 1..3)
{
println(i)
}
-----------------------------------------------------------------
Example:
val items = listOf("apple", "banana", "kiwifruit")
for (item in items) {
println(item)
}
Kotlin OOPs
• Class and Objects
• Constructors
• Inheritance
• Abstract Class
Class in Kotlin
class ClassName
{
// property
// member function
}
class Example
{ // data member private
var number: Int = 5 //
member function
fun calculateSquare(): Int
{
return number*number
}
}
Objects in Kotlin
Syntax:
var obj1 = ClassName()
Example e = Example()
//Access data member
e.number
//Access member function e.calculateSquare()
class Example
{
// data member
private var number: Int = 5
// member function
fun calculateSquare(): Int
{
return number*number
}
}
fun main(args: Array<String>)
{
// create obj object of Example class
val obj = Example()
println("${obj.calculateSquare()}")
}
Constructors in Kotlin
class myClass(valname: String,varid: Int)
{
// class body
}
Constructors in Kotlin
class Person(val firstName: String, var age: Int)
{
}
fun main(args: Array<String>)
{
val person1 = Person(“Kongu", 35)
println("First Name = ${person1.firstName}")
println("Age = ${person1.age}")
}
Inheritance
open class ParentClass(primary_construct)
{ // common code
}
class ChildClass(primary_construct): ParentClass(primary_construct_initializ)
{
// ChildClass specific behaviours
}
import java.util.Arrays
open class ABC
{
fun think ()
{
print("Hey!! i am thiking ")
}
}
class BCD: ABC()
{
// inheritence happend using default constructor
}
fun main(args: Array<String>)
{
var a = BCD()
a.think()
}
Inheritance
Kotlin Android
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val button = findViewById<Button>(R.id.button)
val tv = findViewById<TextView>(R.id.textView)
val ed =findViewById<EditText>(R.id.editTextTextPersonName)
button.setOnClickListener {
Toast.makeText(this,"Hi",Toast.LENGTH_LONG).show()
tv.setText("Hello").toString()
val inputValue: String = ed.text.toString()
tv.setText(inputValue).toString()
}
}
}
Reference
• https://www.javatpoint.com/kotlin-tutorial
• https://www.programiz.com/kotlin-
programming

More Related Content

What's hot

What are monads?
What are monads?What are monads?
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic Programmer
Raúl Raja Martínez
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
piyush Kumar Sharma
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
gourav kottawar
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
Dustin Chase
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++
kinan keshkeh
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOF
Dror Bereznitsky
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
Functions in C++ (OOP)
Functions in C++ (OOP)Functions in C++ (OOP)
Functions in C++ (OOP)
Faizan Janjua
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
Mohammed Sikander
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
Hadziq Fabroyir
 
Streams for (Co)Free!
Streams for (Co)Free!Streams for (Co)Free!
Streams for (Co)Free!
John De Goes
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
Rokonuzzaman Rony
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
Tareq Hasan
 
Overloading
OverloadingOverloading
Overloading
poonamchopra7975
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
Dmitri Nesteruk
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
Neeru Mittal
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 

What's hot (19)

What are monads?
What are monads?What are monads?
What are monads?
 
Functional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic ProgrammerFunctional Programming Patterns for the Pragmatic Programmer
Functional Programming Patterns for the Pragmatic Programmer
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
expression in cpp
expression in cppexpression in cpp
expression in cpp
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++2 BytesC++ course_2014_c1_basicsc++
2 BytesC++ course_2014_c1_basicsc++
 
Fantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOFFantom on the JVM Devoxx09 BOF
Fantom on the JVM Devoxx09 BOF
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Functions in C++ (OOP)
Functions in C++ (OOP)Functions in C++ (OOP)
Functions in C++ (OOP)
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
Streams for (Co)Free!
Streams for (Co)Free!Streams for (Co)Free!
Streams for (Co)Free!
 
Operator Overloading & Type Conversions
Operator Overloading & Type ConversionsOperator Overloading & Type Conversions
Operator Overloading & Type Conversions
 
08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt08 c++ Operator Overloading.ppt
08 c++ Operator Overloading.ppt
 
Overloading
OverloadingOverloading
Overloading
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 

Similar to Kotlin Basic & Android Programming

Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
Adit Lal
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
Jigar Gosar
 
Compose Code Camp (1).pptx
Compose Code Camp (1).pptxCompose Code Camp (1).pptx
Compose Code Camp (1).pptx
MadheswarKonidela
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
XPeppers
 
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
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
Sunghyouk Bae
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptx
adityakale2110
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
Mohamed Nabil, MSc.
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
simenehanmut
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
Oswald Campesato
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
Ian Robertson
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
Adam Getchell
 
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
 
UNIT IV (1).ppt
UNIT IV (1).pptUNIT IV (1).ppt
UNIT IV (1).ppt
VGaneshKarthikeyan
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
Thooyavan Venkatachalam
 
C++
C++C++
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹
Kros Huang
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
KosmikTech1
 
Unit iv
Unit ivUnit iv
Unit iv
snehaarao19
 

Similar to Kotlin Basic & Android Programming (20)

Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Kotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrainsKotlin: A pragmatic language by JetBrains
Kotlin: A pragmatic language by JetBrains
 
Compose Code Camp (1).pptx
Compose Code Camp (1).pptxCompose Code Camp (1).pptx
Compose Code Camp (1).pptx
 
A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Kotlin coroutines and spring framework
Kotlin coroutines and spring frameworkKotlin coroutines and spring framework
Kotlin coroutines and spring framework
 
Android Application Development (1).pptx
Android Application Development (1).pptxAndroid Application Development (1).pptx
Android Application Development (1).pptx
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
Advanced Web Technology ass.pdf
Advanced Web Technology ass.pdfAdvanced Web Technology ass.pdf
Advanced Web Technology ass.pdf
 
Introduction to Kotlin
Introduction to KotlinIntroduction to Kotlin
Introduction to Kotlin
 
KotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptxKotlinForJavaDevelopers-UJUG.pptx
KotlinForJavaDevelopers-UJUG.pptx
 
An Overview Of Python With Functional Programming
An Overview Of Python With Functional ProgrammingAn Overview Of Python With Functional Programming
An Overview Of Python With Functional Programming
 
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
 
UNIT IV (1).ppt
UNIT IV (1).pptUNIT IV (1).ppt
UNIT IV (1).ppt
 
C++ Overview PPT
C++ Overview PPTC++ Overview PPT
C++ Overview PPT
 
C++
C++C++
C++
 
Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹Kotlin Receiver Types 介紹
Kotlin Receiver Types 介紹
 
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdfpython-online&offline-training-in-kphb-hyderabad (1) (1).pdf
python-online&offline-training-in-kphb-hyderabad (1) (1).pdf
 
Unit iv
Unit ivUnit iv
Unit iv
 

More from Kongu Engineering College, Perundurai, Erode

Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
Kongu Engineering College, Perundurai, Erode
 
A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...
Kongu Engineering College, Perundurai, Erode
 
SOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptxSOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptx
Kongu Engineering College, Perundurai, Erode
 
Application Layer.pptx
Application Layer.pptxApplication Layer.pptx
Connect to NoSQL Database using Node JS.pptx
Connect to NoSQL Database using Node JS.pptxConnect to NoSQL Database using Node JS.pptx
Connect to NoSQL Database using Node JS.pptx
Kongu Engineering College, Perundurai, Erode
 
Node_basics.pptx
Node_basics.pptxNode_basics.pptx
Navigation Bar.pptx
Navigation Bar.pptxNavigation Bar.pptx
Bootstarp installation.pptx
Bootstarp installation.pptxBootstarp installation.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
nested_Object as Parameter  & Recursion_Later_commamd.pptxnested_Object as Parameter  & Recursion_Later_commamd.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
Kongu Engineering College, Perundurai, Erode
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Introduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdfIntroduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdf
Kongu Engineering College, Perundurai, Erode
 
Dropdown Menu or Combo List.pdf
Dropdown Menu or Combo List.pdfDropdown Menu or Combo List.pdf
Dropdown Menu or Combo List.pdf
Kongu Engineering College, Perundurai, Erode
 
div tag.pdf
div tag.pdfdiv tag.pdf
Dimensions of elements.pdf
Dimensions of elements.pdfDimensions of elements.pdf
CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
Kongu Engineering College, Perundurai, Erode
 
Random number generation_upload.pdf
Random number generation_upload.pdfRandom number generation_upload.pdf
Random number generation_upload.pdf
Kongu Engineering College, Perundurai, Erode
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
Kongu Engineering College, Perundurai, Erode
 
Computer Networks: Quality of service
Computer Networks: Quality of serviceComputer Networks: Quality of service
Computer Networks: Quality of service
Kongu Engineering College, Perundurai, Erode
 
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Kongu Engineering College, Perundurai, Erode
 
Transport layer services
Transport layer servicesTransport layer services

More from Kongu Engineering College, Perundurai, Erode (20)

Introduction to Spring & Spring BootFramework
Introduction to Spring  & Spring BootFrameworkIntroduction to Spring  & Spring BootFramework
Introduction to Spring & Spring BootFramework
 
A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...A REST API (also called a RESTful API or RESTful web API) is an application p...
A REST API (also called a RESTful API or RESTful web API) is an application p...
 
SOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptxSOA and Monolith Architecture - Micro Services.pptx
SOA and Monolith Architecture - Micro Services.pptx
 
Application Layer.pptx
Application Layer.pptxApplication Layer.pptx
Application Layer.pptx
 
Connect to NoSQL Database using Node JS.pptx
Connect to NoSQL Database using Node JS.pptxConnect to NoSQL Database using Node JS.pptx
Connect to NoSQL Database using Node JS.pptx
 
Node_basics.pptx
Node_basics.pptxNode_basics.pptx
Node_basics.pptx
 
Navigation Bar.pptx
Navigation Bar.pptxNavigation Bar.pptx
Navigation Bar.pptx
 
Bootstarp installation.pptx
Bootstarp installation.pptxBootstarp installation.pptx
Bootstarp installation.pptx
 
nested_Object as Parameter & Recursion_Later_commamd.pptx
nested_Object as Parameter  & Recursion_Later_commamd.pptxnested_Object as Parameter  & Recursion_Later_commamd.pptx
nested_Object as Parameter & Recursion_Later_commamd.pptx
 
Chapter 3.pdf
Chapter 3.pdfChapter 3.pdf
Chapter 3.pdf
 
Introduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdfIntroduction to Social Media and Social Networks.pdf
Introduction to Social Media and Social Networks.pdf
 
Dropdown Menu or Combo List.pdf
Dropdown Menu or Combo List.pdfDropdown Menu or Combo List.pdf
Dropdown Menu or Combo List.pdf
 
div tag.pdf
div tag.pdfdiv tag.pdf
div tag.pdf
 
Dimensions of elements.pdf
Dimensions of elements.pdfDimensions of elements.pdf
Dimensions of elements.pdf
 
CSS Positioning Elements.pdf
CSS Positioning Elements.pdfCSS Positioning Elements.pdf
CSS Positioning Elements.pdf
 
Random number generation_upload.pdf
Random number generation_upload.pdfRandom number generation_upload.pdf
Random number generation_upload.pdf
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 
Computer Networks: Quality of service
Computer Networks: Quality of serviceComputer Networks: Quality of service
Computer Networks: Quality of service
 
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
Transport layer protocols : Simple Protocol , Stop and Wait Protocol , Go-Bac...
 
Transport layer services
Transport layer servicesTransport layer services
Transport layer services
 

Recently uploaded

ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
amsjournal
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
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
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
RamonNovais6
 
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
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
Madan Karki
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))
shivani5543
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
gowrishankartb2005
 

Recently uploaded (20)

ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
UNLOCKING HEALTHCARE 4.0: NAVIGATING CRITICAL SUCCESS FACTORS FOR EFFECTIVE I...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
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
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURSCompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
CompEx~Manual~1210 (2).pdf COMPEX GAS AND VAPOURS
 
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
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
john krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptxjohn krisinger-the science and history of the alcoholic beverage.pptx
john krisinger-the science and history of the alcoholic beverage.pptx
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))gray level transformation unit 3(image processing))
gray level transformation unit 3(image processing))
 
Material for memory and display system h
Material for memory and display system hMaterial for memory and display system h
Material for memory and display system h
 

Kotlin Basic & Android Programming

  • 1. Kotlin Basic & Android Programming Handled By Dr.T.Abirami Associate Professor Department of IT Kongu Engineering College Perundurai
  • 2. Why Learn Kotlin? • Kotlin is 100 percent interoperable with Java. Hence your Java/Android code works with Kotlin. • Kotlin allows you to cut off the lines of code by approximately 40% (compared to Java). • Learning Kotlin is easy. It is particularly easy if you already know Java. • Kotlin is tool-friendly. You can use any Java IDE or command line to run Kotlin.
  • 3. Present and Future of Kotlin Present • Many companies like Netflix, Uber, Trello, Pinterest, Corda, etc are using Kotlin (along with other programming languages) to create applications. • Google's Android team announced Kotlin as an official language for Android app development. • You can replace Java code with Kotlin seamlessly. It is 100% interoperable with Java and Android. Future • Cross-platform game development • Cross-platform mobile application development • Server-side and microservices • Data analysis and machine learning • Embedded system: Arduino/Raspberry Pi to professional controllers directly
  • 4. Kotlin • Kotlin is a programming language introduced by JetBrains • The main() function in Kotlin is the entry point to a Kotlin program. • It supports both procedural programming and object oriented programming.
  • 5. Program entry point fun main() { println("Hello world!") } ------------------------------ fun main(args: Array<String>) { println("Hello World!") print("Welcome to JavaTpoint") }
  • 6. fun main(args: Array<String>){ println(10) println("Welcome to JavaTpoint") print(20) print("Hello") } 10 Welcome to JavaTpoint 20Hello Kotlin Output
  • 7. Variable Declaration Kotlin variable is declared using keyword var and val. • var (Mutable variable): We can change the value of variable declared using var keyword later in the program. • val (Immutable variable): We cannot change the value of variable which is declared using val keyword. • var language ="Java" • val salary = 30000 explicitly specify the type of variable while declaring it. • var language: String ="Java" • val salary: Int = 30000
  • 8. Example • var salary = 30000 • salary = 40000 //execute Here, the value of variable salary can be changed (from 30000 to 40000) because variable salary is declared using var keyword. • val language = "Java" • language = "Kotlin" //Error Here, we cannot re-assign the variable language from "Java" to "Kotlin" because the variable is declared using val keyword.
  • 9. • val a: Int = 1 // immediate assignment • val b = 2 // `Int` type is inferred • val c: Int // Type required when no initializer is provided • c = 3 // deferred assignment var x = 5 // `Int` type is inferred x += 1
  • 10. val PI = 3.14 var x = 0 fun incrementX() { x += 1 }
  • 11. fun main(args: Array<String>) { val first: Int = 10 val second: Int = 20 val sum = first + second println("The sum is: $sum") }
  • 12. Kotlin Input • standard library function readLine()- is used for reads line of string input from standard input stream. fun main(args: Array<String>) { println("Enter your name") val name = readLine() println("Enter your age") var age: Int =Integer.valueOf(readLine()) println("Your name is $name and your age is $age") }
  • 13. Example Getting Integer Input import java.util.Scanner fun main(args: Array<String>) { val read = Scanner(System.`in`) println("Enter your age") var age = read.nextInt() println("Your input age is "+age) }
  • 14. User-defined Function fun main(args: Array<String>) { sum() print("code after sum") } fun sum() { var num1 =8 var num2 = 9 println("sum = "+(num1+num2)) } fun functionName() { //body of the code }
  • 15. • function having two Int parameters with Int return type: fun sum(a: Int, b: Int): Int { return a + b }
  • 16. Unit return type can be omitted: fun printSum(a: Int, b: Int): Unit { println("sum of $a and $b is ${a + b}") }
  • 17. Conditional expressions fun maxOf(a: Int, b: Int): Int { if (a > b) { return a } else { return b } }
  • 18. for loop Syntax: for (item in collection) print(item) ---------------------------------------------------------------- for (i in 1..3) { println(i) } ----------------------------------------------------------------- Example: val items = listOf("apple", "banana", "kiwifruit") for (item in items) { println(item) }
  • 19. Kotlin OOPs • Class and Objects • Constructors • Inheritance • Abstract Class
  • 20. Class in Kotlin class ClassName { // property // member function } class Example { // data member private var number: Int = 5 // member function fun calculateSquare(): Int { return number*number } }
  • 21. Objects in Kotlin Syntax: var obj1 = ClassName() Example e = Example() //Access data member e.number //Access member function e.calculateSquare()
  • 22. class Example { // data member private var number: Int = 5 // member function fun calculateSquare(): Int { return number*number } } fun main(args: Array<String>) { // create obj object of Example class val obj = Example() println("${obj.calculateSquare()}") }
  • 23. Constructors in Kotlin class myClass(valname: String,varid: Int) { // class body }
  • 24. Constructors in Kotlin class Person(val firstName: String, var age: Int) { } fun main(args: Array<String>) { val person1 = Person(“Kongu", 35) println("First Name = ${person1.firstName}") println("Age = ${person1.age}") }
  • 25. Inheritance open class ParentClass(primary_construct) { // common code } class ChildClass(primary_construct): ParentClass(primary_construct_initializ) { // ChildClass specific behaviours }
  • 26. import java.util.Arrays open class ABC { fun think () { print("Hey!! i am thiking ") } } class BCD: ABC() { // inheritence happend using default constructor } fun main(args: Array<String>) { var a = BCD() a.think() } Inheritance
  • 28. import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.TextView import android.widget.Toast class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val button = findViewById<Button>(R.id.button) val tv = findViewById<TextView>(R.id.textView) val ed =findViewById<EditText>(R.id.editTextTextPersonName) button.setOnClickListener { Toast.makeText(this,"Hi",Toast.LENGTH_LONG).show() tv.setText("Hello").toString() val inputValue: String = ed.text.toString() tv.setText(inputValue).toString() } } }