SlideShare a Scribd company logo
1 of 174
Download to read offline
Null-safety
val a: String? = null
println(a?.length())
Null-safety
val a: String? = null
println(a?.length())
> null
Null-safety
int length = a != null ? a.length() : -1
Null-safety
int length = a != null ? a.length() : -1
Null check
Null-safety
int length = a != null ? a.length() : -1
Assignmentselector
Null-safety
var length = if (a != null) a.length() else -1
Null-safety
var length = if (a != null) a.length() else -1
Null check
Null-safety
var length = if (a != null) a.length() else -1
Assignmentselector
Null-safety
var length = a?.length() ?: -1
Null-safety
var length = a?.length() ?: -1
Null check
Null-safety
var length = a?.length() ?: -1
Assignmentselector
Smart casts
Smart casts
if (x is String) {
print(x.length())
}
Smart casts
if (x is String) {
print(x.length())
}
Typecheck
Smart casts
if (x is String) {
print(x.length())
}
Smart cast
Smart casts
if (x !is String) {
return
}
print(x.size())
Smart casts
if (x !is String) {
return
}
print(x.size())Type check
Smart casts
if (x !is String) {
return
}
print(x.size())
Smart casts
if (x !is String) {
return
}
print(x.size())
Smart cast
Smart casts
if (x !is String || x.size() == 0) {
return
}
Smart casts
if (x !is String || x.size() == 0) {
return
}
Typecheck
Smart casts
if (x !is String || x.size() == 0) {
return
}
Smart casts
if (x !is String || x.size() == 0) {
return
}
Smart cast
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Typecheck
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart cast
Smart casts
if (x is String && x.size() > 0) {
print(x.size())
}
Smart cast
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart casts
Typecheck
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart casts
Smart cast
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Typecheck
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart cast
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Type check
Smart casts
when (x) {
is Int -> print(x + 1)
is String -> print(x.size() + 1)
is Array<Int> -> print(x.sum())
}
Smart cast
String templates
String templates
val apples = 4
println("I have " + apples + " apples.")
> I have 4 apples.
String templates
val apples = 4
println("I have $apples apples.")
> I have 4 apples.
> I have 4 apples.
String templates
val apples = 4
val bananas = 3
println("I have $apples apples and " + (apples + bananas) + " fruits.")
> I have 4 apples.
> I have 4 apples.
> I have 4 apples and 7 fruits.
String templates
val apples = 4
val bananas = 3
println("I have $apples apples and ${apples+bananas} fruits.")
> I have 4 apples.
> I have 4 apples and 7 fruits.
> I have 4 apples and 7 fruits.
Range expressions
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
if (IntRange(1, 10).contains(i)) {
println(i)
}
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
if (1.rangeTo(10).contains(i)) {
println(i)
}
Range expressions
if (1 <= i && i <= 10) {
println(i)
}
if (i in 1..10 ) {
println(i)
} Range operator
Range expressions
for (i in 1..4) {
print(i)
}
> 1234
Range expressions
for (i in 1..4 step 2) {
print(i)
}
> 1234
> 13
Range expressions
for (i in 4 downTo 1 step 2) {
print(i)
}
> 1234
> 13
> 42
Range expressions
for (i in 1.0..2.0) {
print("$i ")
}
> 13
> 42
> 1.0 2.0
Range expressions
for (i in 1.0..2.0 step 0.3) {
print("$i ")
}
> 42
> 1.0 2.0
> 1.0 1.3 1.6 1.9
Lab 1
Foo Corporation needs a program to calculate how much to pay their hourly employees. The US Department
of Labor requires that employees get paid time and a half for any hours over 40 that they work in a single
week. For example, if an employee works 45 hours, they get 5 hours of overtime, at 1.5 times their base pay.
The State of Massachusetts requires that hourly employees be paid at least $8.00 an hour. Foo Corp requires
that an employee not work more than 60 hours in a week.
• Rules
• An employee gets paid (hours worked) × (base pay), for each hour up to 40 hours.
• For every hour over 40, they get overtime = (base pay) × 1.5.
• The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error.
• If the number of hours is greater than 60, print an error message.
Write a method that takes the base pay and hours worked as parameters, and prints the total pay
or an error. Write a main method that calls this method for each of these employees:
Base Pay Hours Worked
Employee 1 $7.50 35
Employee 2 $8.20 47
Employee 3 $10.00 73
Lab 2
A group of ITI friends decide to run a Marathon. Their names and times (in minutes) are below:
Name Time (minutes)
Ahmed 341
Mohamed 273
Ismail 278
Hend 329
Aly 445
Hossam 402
Ola 388
Alaa 275
Basma 243
Mina 334
Nada 412
Saad 393
• Find the fastest runner. Print the name and his/her time (in minutes).
• Optional: Find the second fastest runner. Print the name and his/her time (in minutes).
Lab 3
• Create an Android a simple app with two buttons, one to count and
one to show a toast.
Lab 4
• Create an Android UI with one text field, centered at the top of the screen, and
one button. The text field will initially display the text Tap to Change Color.
• Every time you tap the button, you will generate a random color using RGB
values, change the text to that color, and display the values for the color in the
following format (assuming you are displaying a light grey with values
100/100/100): COLOR: 100r, 100g, 100b.
Lab 5
• Battery Status App
• Create an Android App that displays a colored
bar to display the battery's status.
• Display a battery drawable as follows:
0-25% - Red (battery low)
>25% <80% - Yellow (battery medium)
>80% - Green (battery good)
When expression
When expression
• When expression is similar to switch/case in Java,
but far more powerful.
When expression
when (argument) {
match1 -> fun1()
match2 -> fun2()
else -> fun3()
}
When expression
when (argument) {
m a t c h 1 - > f u n 1 ( )
m a t c h 2 - > f u n 2 ( )
e l s e - > f u n 3 ( )
}
Can be anything
When expression
( a r g u m e n t )
Match1 -> fun1()
match2 -> fun2()
e l s e - > f u n 3 ( )
}
Can be anything
When expression
var result: Int = when (argument) {
m a t c h 1 - > f u n 1 ( )
m a t c h 2 - > f u n 2 ( )
e l s e - > f u n 3 ( )
}
Can return result
When expression
var result: Int = when (argument) {
match1 -> fun1()
match2 -> fun2()
else -> fun3()
}
When expression
override fun onCreateViewHolder(g: ViewGroup, type: Int) {
when (type) {
TYPE_TITLE -> TitleViewHolder(g)
TYPE_DESCRIPTION -> DescriptionViewHolder(g))
}
return null
}
When expression
o v e r r i d e f u n o n C r e a t e V i e w H o l d e r ( g : V i e w G r o u p ,
t y p e : I n t ) {
when (type) {
T Y P E _ T I T L E - > T i t l e V i e w H o l d e r ( g )
T Y P E _ D E S C R I P T I O N - >
D e s c r i p t i o n V i e w H o l d e r ( g ) )
}
r e t u r n n u l l
}
Can be placed after a = symbol
When expression
override fun onCreateViewHolder(g: ViewGroup, type: Int) = when (type) {
T Y P E _ T I T L E - > T i t l e V i e w H o l d e r ( g )
T Y P E _ D E S C R I P T I O N - >
D e s c r i p t i o n V i e w H o l d e r ( g ) )
e l s e - > n u l l
}
When expression
override fun onCreateViewHolder(g: ViewGroup, type: Int) = when (type) {
TYPE_TITLE -> TitleViewHolder(g)
TYPE_DESCRIPTION -> DescriptionViewHolder(g)
else -> null
}
When expression
override fun getItemViewType(index: Int) = when (dataList[index]) {
is Title -> TYPE_TITLE
is Description -> TYPE_DESCRIPTION
else -> TYPE_UNDEFINED
}
When expression
override fun getItemViewType(index: Int) = when (dataList[index]) {
is Title -> TYPE_TITLE
is Description -> TYPE_DESCRIPTION
else -> TYPE_UNDEFINED
}
Type checks possible
When expression
override fun getItemViewType(index: Int) = when (dataList[index]) {
is Title -> TYPE_TITLE
is Description -> TYPE_DESCRIPTION
else -> TYPE_UNDEFINED
}
When expression
override fun onBindViewHolder(viewHolder: ViewHolder, index: Int) {
val displayable: Displayable = dataList[index]
when (displayable) {
is Title -> initTitle(viewHolder, displayable)
is Description -> initDescription(viewHolder, displayable)
}
}
When expression
o v e r r i d e f u n o n B i n d V i e w H o l d e r ( v i e w H o l d e r : V i e w H o l d e r , i n d e x : I n t ) {
v a l d i s p l a y a b l e : D i s p l a y a b l e = d a t a L i s t [ i n d e x ]
W h e n ( d i s p l a y a b l e ) {
is Title -> initTitle(viewHolder, displayable)
is Description -> initDescription(viewHolder, displayable)
}
}
Smart cast
let, apply, use, with
let, apply, use, with
• Higher-order functions - function that takes
functions as parameters, or returns a function.
let (scope function)
/**
* Calls the specified function [block] with `this` value as
* its argument and returns its result.
*/
public inline fun <T, R> T.let(block: (T) -> R): R = block(this)
let
Preferences.getUser().let {
showUserName(it.name)
showUserEmail(it.email)
}
let
Preferences.getUser().let {
showUserName(it.name)
showUserEmail(it.email)
}
Refers to user object
let
Preferences.getUser().let {
showUserName(it.name)
showUserEmail(it.email)
}
Variable visibility scope
let
Preferences.getUser()?.let {
showUserName(it.name)
showUserEmail(it.email)
}
Only execute if user is not null
let
Preferences.getUser()?.let {
showUserName(it.name)
showUserEmail(it.email)
}
use (try with resources function)
/**
* Executes the given [block] function on this resource and then
* closes it down correctly whether an exception is thrown or not.
*/
public inline fun <T : Closeable, R> T.use(block: (T) -> R): R {
var closed = false
try {
return block(this)
} catch (e: Exception) {
// ommitted
} finally {
if (!closed) { close()
}
}
}
use
fun countUsers(): Long {
val database = openDatabase()
val result = database.count("users")
database.close()
return result
}
use
fun countUsers() = openDatabase().use { it.count("users") }
Automatically close
database
fun countUsers() = openDatabase().use { it.count("users") }
Refers to database object
use
fun countUsers() = openDatabase().use { it.count("users") }
use
with
/**
* Calls the specified function [block] with the given [receiver]
* as its receiver and returns its result.
*/
public inline fun <T, R> with(receiver: T, block: T.() -> R): R = receiver.block()
with
recyclerView.setHasFixedSize(true)
recyclerView.addItemDecoration(createDecorator())
recyclerView.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.adapter = myAdapter
with
with(recyclerView) {
recyclerView.setHasFixedSize(true)
recyclerView.addItemDecoration(createDecorator())
recyclerView.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.adapter = myAdapter
}
with
with(recyclerView) {
recyclerView.setHasFixedSize(true)
recyclerView.addItemDecoration(createDecorator())
recyclerView.layoutManager = LinearLayoutManager(applicationContext)
recyclerView.adapter = myAdapter
}
Not need
with
with(recyclerView) {
setHasFixedSize(true)
addItemDecoration(createDecorator())
layoutManager = LinearLayoutManager(applicationContext)
adapter = myAdapter
}
with
with(recyclerView) {
setHasFixedSize(true)
addItemDecoration(createDecorator())
layoutManager = LinearLayoutManager(applicationContext)
adapter = myAdapter
}
apply
/**
* Calls the specified function [block] with `this` value as its receiver
* and returns `this` value.
*/
public inline fun <T> T.apply(block: T.() -> Unit): T { block(); return this }
apply
fun makeDir(path: String): File {
val result: File = File(path)
result.mkdirs()
return result
}
apply
fun makeDir(path: String) = File(path).apply { mkdirs() }
Collections
Collections
val numbers: MutableList<Int> = mutableListOf(1, 2, 3)
numbers.add(1)
val numbers2: List<Int> = listOf(1, 2, 3)
numbers2.add(1)
No such method
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [1, null, 2, null, 3, 4, 5, 6, 7, 8, 9]
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [2, 4, 6, 8]
Collections
mutableListOf(1, null, 2, null, 3, 4, 5, 6, 7, 8, 9)
.filterNotNull()
.filter { it % 2 == 0 }
.sortedDescending()
> [8, 6, 4, 2]
Collections
getOrElse()
find()
filter()
filterNot()
filterNotNull()
flatMap()
take()
takeLast()
sortBy()
sortByDescending()
groupBy()
map()
mapNotNull()
all()
any()
maxBy()
minBy()
minWith()
sumBy()
zip()
...
Functions default values
Default values for function parameters
• Function parameters can have default values, which are used when a
corresponding argument is omitted.
• This allows for a reduced number of overloads compared to other
languages.
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String?,
selectionArgs : Array<String>?,
orderBy: String?): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, "NAME")
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, "NAME")
Default value
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, "NAME")
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, orderBy = "NAME")
Named argument
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), null, null, orderBy = "NAME")
Not needed
Default values for function parameters
fun query(table: String,
columns: Array<String>,
selection: String? = null,
selectionArgs : Array<String>? = null,
orderBy: String? = null): Cursor {
...
}
// function call
query("USERS", arrayOf("ID", "NAME"), orderBy = "NAME")
Lazy property
Lazy property
• Value gets computed only upon first access.
Lazy property
val preference = getSharedPreferences("pref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Lazy property
val preference = getSharedPreferences("pref")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Crash, require context
Lazy property
val preference by lazy { getSharedPreferences("pref") }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Won’t be executed until the
property is first used
Lazy property
val preference by lazy { getSharedPreferences("pref") }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val username = preference.getString("username")
}
Extension functions
Extension functions
public fun isLollipopOrGreater(code: Int): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun isLollipopOrGreater(code: Int): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(code: Int): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {
return code >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {
return this >= Build.VERSION_CODES.LOLLIPOP
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {.
return this >= Build.VERSION_CODES.LOLLIPOP
}
if (Build.VERSION.SDK_INT.isLollipopOrGreater) {
// ...
}
Extension functions
public fun Int.isLollipopOrGreater(): Boolean {.
return this >= Build.VERSION_CODES.LOLLIPOP
}
if (16.isLollipopOrGreater) {
// ...
}
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper,
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
Function<Customer, Order> customerMapper = // ...
Function<Order, Boolean> orderFilter = // ...
Function<Order, Float> orderSorter = // ...
List<Order> vipOrders = sortBy(filter(map(customers,
customerMapper),
orderFilter),
orderSorter);
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Extension functions
val vipOrders = customers
.map { it.lastOrder }
.filter { it.total >= 500F }
.sortBy { it.total }
Primary constructors
Primary constructors
class Customer {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String) {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String) {
var firstName: String = firstName
var lastName: String = lastName
var email: String = email
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String) {
var firstName: String
var lastName: String
var email: String
init {
this.firstName = firstName
this.lastName = lastName
this.email = email
}
}
Primary constructors
class Customer(firstName: String, lastName: String, email: String)
Primary constructors
class Customer(var firstName: String, var lastName: String, var email: String)
Primary constructors
class Customer(
var firstName: String,
var lastName: String,
var email: String)
Primary constructors
class Customer(
val firstName: String,
val lastName: String,
val email: String)
Properties
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
private String firstName;
private String lastName;
private String email;
public String getFirstName() { return firstName;}
public String getLastName() { return lastName; }
public String getEmail() { return email; }
public void setFirstName(String firstName) { this.firstName = firstName }
public void setLastName(String lastName) { this.lastName = lastName }
public void setEmail(String email) { this.email = email }
}
Properties
class Customer {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
Properties
class Customer {
var firstName: String = // ...
var lastName: String = // ...
var email: String = // ...
}
val customer = Customer()
customer.firstName = "Michael"
customer.lastName = "Pardo"
customer.email = "michael@michaelpardo.com"
Data class
Data class
What it does?
Nothing, just hold data
What it provides?
● getters, setters
● equals()/hashCode()
● toString() ofthe form"User(name=John, age=42)"
● copy() function
Data class
data class User(val name: String, val age: Int)
Data class
data class User(val name: String, val age: Int)
val user = User("Dmytro", 24)
print(user)
> User(name=Dmytro, age=24)
Singletons
Singletons
public class Singleton {
private static volatile Singleton instance;
private Singleton() { }
public static Singleton getInstance() {
if (instance == null ) {
synchronized (Singleton.class) {
if (instance == null) {
instance = new Singleton();
}
}
}
return instance;
}
}
Singletons
public class Singleton {
private static volatile Singleton instance = null;
private Singleton() { }
public static synchronized Singleton getInstance() {
if (instance == null) {
instance = new Singleton();
}
return instance;
}
}
Singletons
public class Singleton {
private static final Singleton INSTANCE = new Singleton();
private Singleton() {}
public static Singleton getInstance() {
return INSTANCE;
}
}
Singletons
public class Singleton {
private static final Singleton instance;
static {
try {
instance = new Singleton();
} catch (Exception e) {
throw new RuntimeException("an error occurred!", e);
}
}
public static Singleton getInstance() {
return instance;
}
private Singleton() { }
}
Singletons
public class Singleton {
private Singleton() { }
private static class SingletonHolder {
private static final Singleton INSTANCE = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.INSTANCE;
}
}
Singletons
object Singleton
Singletons
object Logger {
val tag = "TAG"
fun d(message: String) {
Log.d(tag, message)
}
}
Companion objects
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Timber.v("Starting activity %s", LaunchActivity.TAG);
Companion objects
class LaunchActivity extends AppCompatActivity {
public static final String TAG = LaunchActivity.class.getName();
public static void start(Context context) {
context.startActivity(new Intent(context, LaunchActivity.class));
}
}
Timber.v("Starting activity %s", LaunchActivity.TAG);
LaunchActivity.start(context);
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Timber.v("Starting activity ${LaunchActivity.TAG}")
Companion objects
class LaunchActivity {
companion object {
val TAG: String = LaunchActivity::class.simpleName
fun start(context: Context) {
context.startActivity(Intent(context, LaunchActivity::class))
}
}
}
Timber.v("Starting activity ${LaunchActivity.TAG}")
LaunchActivity.start(context)
Operator overloading

More Related Content

What's hot

Structured data type
Structured data typeStructured data type
Structured data typeOmkar Majukar
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentalsMauro Palsgraaf
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks QueuesIntro C# Book
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search TechniquesShakil Ahmed
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlangasceth
 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184Mahmoud Samir Fayed
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersKimikazu Kato
 
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...Philip Schwarz
 

What's hot (14)

02 arrays
02 arrays02 arrays
02 arrays
 
Python list
Python listPython list
Python list
 
Structured data type
Structured data typeStructured data type
Structured data type
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
Advanced Search Techniques
Advanced Search TechniquesAdvanced Search Techniques
Advanced Search Techniques
 
Intro To Erlang
Intro To ErlangIntro To Erlang
Intro To Erlang
 
Numerical analysisgroup19
Numerical analysisgroup19Numerical analysisgroup19
Numerical analysisgroup19
 
The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184The Ring programming language version 1.5.3 book - Part 24 of 184
The Ring programming language version 1.5.3 book - Part 24 of 184
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Channel coding
Channel codingChannel coding
Channel coding
 
Kotlin standard
Kotlin standardKotlin standard
Kotlin standard
 

Similar to Calculate hourly employee pay including overtime

Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdfkesav24
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202Mahmoud Samir Fayed
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdfsowmya koneru
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and testsintive
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210Mahmoud Samir Fayed
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Codemotion
 

Similar to Calculate hourly employee pay including overtime (20)

Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
Flink Forward Berlin 2017: David Rodriguez - The Approximate Filter, Join, an...
 
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
Implement the following sorting algorithms  Bubble Sort  Insertion S.pdfImplement the following sorting algorithms  Bubble Sort  Insertion S.pdf
Implement the following sorting algorithms Bubble Sort Insertion S.pdf
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202The Ring programming language version 1.8 book - Part 29 of 202
The Ring programming language version 1.8 book - Part 29 of 202
 
Poly-paradigm Java
Poly-paradigm JavaPoly-paradigm Java
Poly-paradigm Java
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
Python
PythonPython
Python
 
C programs
C programsC programs
C programs
 
Monadologie
MonadologieMonadologie
Monadologie
 
PRACTICAL COMPUTING
PRACTICAL COMPUTINGPRACTICAL COMPUTING
PRACTICAL COMPUTING
 
Kotlin, Spek and tests
Kotlin, Spek and testsKotlin, Spek and tests
Kotlin, Spek and tests
 
The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210The Ring programming language version 1.9 book - Part 31 of 210
The Ring programming language version 1.9 book - Part 31 of 210
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and ScalaFolding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 

Recently uploaded

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 

Recently uploaded (20)

Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 

Calculate hourly employee pay including overtime