This work is licensed under the Apache 2.0 License
COMPOSE
CAMP
by
Why Kotlin
This work is licensed under the Apache 2.0 License
Kotlin is a modern programming language that helps
developers be more productive. For example, Kotlin allows you
to be more concise and write fewer lines of code for the same
functionality compared to other programming languages. Apps
that are built with Kotlin are also less likely to crash, resulting
in a more stable and robust app for users. Essentially, with
Kotlin, you can write better Android apps in a shorter amount
of time
This work is licensed under the Apache 2.0 License
Kotlin Playground
This work is licensed under the Apache 2.0 License
A Kotlin program is required to have a main function, which is the
specific place in your code where the Kotlin compiler starts. The
main function is the entry point, or starting point, of the program.
This work is licensed under the Apache 2.0 License
Define a function
• The function needs a name, so you can
call it later.
• The function can also require
some inputs, or information that needs
to be provided when the function is
called. The function uses these inputs to
accomplish its purpose. Requiring
inputs are optional, and some functions
require no inputs.
• The function also has a body which
contains the instructions to perform the
task.
This work is licensed under the Apache 2.0 License
• The function definition starts with the
word fun.
• Then the name of the function is main.
• There are no inputs to the function, so
the parentheses are empty.
• There is one line of code in the function
body, println("Hello, world!"), which is
located between the opening and closing
curly braces of the function.
This work is licensed under the Apache 2.0 License
Variables and Data Types
• A variable, which is a container
for a single piece of data.
This work is licensed under the Apache 2.0 License
Data Types:
This work is licensed under the Apache 2.0 License
Variable declaration:
For Example:
val count: Int = 2
This work is licensed under the Apache 2.0 License
Update Variables
fun main() {
val cartTotal = 0
cartTotal = 20
println("Total:
$cartTotal")
}
fun main() {
var cartTotal = 0
cartTotal = 20
println("Total:
$cartTotal")
}
This work is licensed under the Apache 2.0 License
Coding Convention
• Variable names should be in camel case and start
with a lowercase letter.
• In a variable declaration, there should be a spacafter
a colon when you specify the data type.
• There should be a space before and after an operator
like the assignment (=), addition (+), subtraction (-),
multiplication (*), division (/) operators and more.
This work is licensed under the Apache 2.0 License
Comments
Single Line: // This is a comment.
/*
Multi Line: * This is a very long comment
that can
* take up multiple lines.
*/
This work is licensed under the Apache 2.0 License
Stargazing at State
Conditionals in Kotlin
This work is licensed under the Apache 2.0 License
If-else statement
This work is licensed under the Apache 2.0 License
when statement
This work is licensed under the Apache 2.0 License
if/else and when as expressions
Migration Meadow
This work is licensed under
the Apache 2.0 License
Nullability in Kotlin
This work is licensed under the Apache 2.0 License
What is Null?
Chadwick Boseman
This work is licensed under the Apache 2.0 License
Syntax of nullable Datatype
• Nullable types are variables that can hold null.
• Non-null types are variables that can't hold null.
This work is licensed under the Apache 2.0 License
?. Safe-call operator
The ?. safe-call operator allows safer access to nullable variables
because the Kotlin compiler stops any attempt of member access
to null references and returns null for the member accessed.
This work is licensed under the Apache 2.0 License
!! not-null assertion operator
you use the !! not-null assertion, it means that you assert that the
value of the variable isn’t null, regardless of whether it is or isn’t.
Installation Of
Android Studio

Compose Camp#2 - Kotlin Basics.pptx

  • 1.
    This work islicensed under the Apache 2.0 License COMPOSE CAMP by
  • 2.
  • 3.
    This work islicensed under the Apache 2.0 License Kotlin is a modern programming language that helps developers be more productive. For example, Kotlin allows you to be more concise and write fewer lines of code for the same functionality compared to other programming languages. Apps that are built with Kotlin are also less likely to crash, resulting in a more stable and robust app for users. Essentially, with Kotlin, you can write better Android apps in a shorter amount of time
  • 4.
    This work islicensed under the Apache 2.0 License Kotlin Playground
  • 5.
    This work islicensed under the Apache 2.0 License A Kotlin program is required to have a main function, which is the specific place in your code where the Kotlin compiler starts. The main function is the entry point, or starting point, of the program.
  • 6.
    This work islicensed under the Apache 2.0 License Define a function • The function needs a name, so you can call it later. • The function can also require some inputs, or information that needs to be provided when the function is called. The function uses these inputs to accomplish its purpose. Requiring inputs are optional, and some functions require no inputs. • The function also has a body which contains the instructions to perform the task.
  • 7.
    This work islicensed under the Apache 2.0 License • The function definition starts with the word fun. • Then the name of the function is main. • There are no inputs to the function, so the parentheses are empty. • There is one line of code in the function body, println("Hello, world!"), which is located between the opening and closing curly braces of the function.
  • 8.
    This work islicensed under the Apache 2.0 License Variables and Data Types • A variable, which is a container for a single piece of data.
  • 9.
    This work islicensed under the Apache 2.0 License Data Types:
  • 10.
    This work islicensed under the Apache 2.0 License Variable declaration: For Example: val count: Int = 2
  • 11.
    This work islicensed under the Apache 2.0 License Update Variables fun main() { val cartTotal = 0 cartTotal = 20 println("Total: $cartTotal") } fun main() { var cartTotal = 0 cartTotal = 20 println("Total: $cartTotal") }
  • 12.
    This work islicensed under the Apache 2.0 License Coding Convention • Variable names should be in camel case and start with a lowercase letter. • In a variable declaration, there should be a spacafter a colon when you specify the data type. • There should be a space before and after an operator like the assignment (=), addition (+), subtraction (-), multiplication (*), division (/) operators and more.
  • 13.
    This work islicensed under the Apache 2.0 License Comments Single Line: // This is a comment. /* Multi Line: * This is a very long comment that can * take up multiple lines. */
  • 14.
    This work islicensed under the Apache 2.0 License Stargazing at State Conditionals in Kotlin
  • 15.
    This work islicensed under the Apache 2.0 License If-else statement
  • 16.
    This work islicensed under the Apache 2.0 License when statement
  • 17.
    This work islicensed under the Apache 2.0 License if/else and when as expressions
  • 18.
    Migration Meadow This workis licensed under the Apache 2.0 License Nullability in Kotlin
  • 19.
    This work islicensed under the Apache 2.0 License What is Null? Chadwick Boseman
  • 20.
    This work islicensed under the Apache 2.0 License Syntax of nullable Datatype • Nullable types are variables that can hold null. • Non-null types are variables that can't hold null.
  • 21.
    This work islicensed under the Apache 2.0 License ?. Safe-call operator The ?. safe-call operator allows safer access to nullable variables because the Kotlin compiler stops any attempt of member access to null references and returns null for the member accessed.
  • 22.
    This work islicensed under the Apache 2.0 License !! not-null assertion operator you use the !! not-null assertion, it means that you assert that the value of the variable isn’t null, regardless of whether it is or isn’t.
  • 23.