The document discusses Kotlin fundamentals including defining functions, variables, and basic data types. It explains that Kotlin is used to build Android apps and functions are segments of a program that perform specific tasks. Functions begin with the fun keyword and need parentheses and curly braces. Variables can be val for immutable values or var for mutable, require a name, data type, and can have an initial value assigned.
Compose Camp is an introduction to building Android apps using Jetpack Compose. It teaches the basics of Kotlin programming language, Android Studio setup, and Jetpack Compose through hands-on projects. The learning objectives are to build first Android apps, set up development environment, learn Kotlin fundamentals like variables, data types, functions, and discover resources to continue learning Compose. The course covers these concepts through topics like Kotlin Playground, variables and data types, functions, and a quiz.
Compose Camp is an introduction to building Android apps using Jetpack Compose. The document outlines the prerequisites, learning objectives, and structure of Compose Camp. It will teach participants to set up Android Studio, learn Kotlin fundamentals, and build their first Android apps with Compose. The course is divided into units that introduce key Compose concepts and provide interactive exercises to apply the learning.
Android Development | Compose Camp Day 1 | GDSC SEC Sasaram.pdfShivamShrey1
This document provides an overview and schedule for Compose Camp, which teaches how to build Android apps using Jetpack Compose. Compose Camp introduces participants to Kotlin programming, setting up Android Studio, and learning Jetpack Compose. The schedule outlines topics to be covered each day such as creating variables and functions in Kotlin. Prerequisites include basic computer skills and an internet connection. The goal is for participants to build their first Android apps using Compose.
This document provides an overview and schedule for Compose Camp, which teaches how to build Android apps using Jetpack Compose. Compose Camp includes learning objectives like building first Android apps, setting up Android Studio, learning Kotlin programming basics, and discovering additional resources. The schedule outlines topics each day like introducing Kotlin programming language, creating and using variables and functions in Kotlin, and includes breaks. The document encourages sharing what is learned on social media and submitting tips to Android for a chance to be featured. It concludes by providing additional optional learning resources.
The document provides instructions and examples for creating a basic Android application using Kotlin and Jetpack Compose. It introduces Android Studio and the tools for building Compose apps. It demonstrates how to define composable functions to display text and images. It shows how to organize composables using Column and preview the UI using the @Preview annotation. The goal is to build a simple pet adoption app that displays the name, information and photo of a dog.
This document summarizes Session 2 of Compose Camp which provided an introduction to Kotlin and Jetpack Compose. It began with an overview of basic Kotlin data types like String, Int, Double, and Boolean. It then covered defining variables with val and var keywords and initializing their values. The document showed examples of control flows like if/else statements, for loops, while loops, and functions. It demonstrated working with collections like lists, arrays, and maps. Finally, it previewed upcoming sessions and shared additional resources for learning Compose.
The document is a collection of snippets about learning Kotlin and building Android apps. It includes explanations of Kotlin concepts like functions, variables, data types, conditionals, loops, and collections methods. It also discusses Compose Camp which is an introduction to building Android apps with Jetpack Compose. The snippets provide code examples and explanations to help teach Kotlin programming basics.
The document is a presentation on basics of Android development using Kotlin and Jetpack Compose. It includes an introduction to Kotlin programming concepts like variables, functions, data types etc. It then covers topics like building a basic Android app using Android Studio and Jetpack Compose. The schedule includes an introduction to Kotlin, setting up Android Studio and building a first Android app.
Compose Camp is an introduction to building Android apps using Jetpack Compose. It teaches the basics of Kotlin programming language, Android Studio setup, and Jetpack Compose through hands-on projects. The learning objectives are to build first Android apps, set up development environment, learn Kotlin fundamentals like variables, data types, functions, and discover resources to continue learning Compose. The course covers these concepts through topics like Kotlin Playground, variables and data types, functions, and a quiz.
Compose Camp is an introduction to building Android apps using Jetpack Compose. The document outlines the prerequisites, learning objectives, and structure of Compose Camp. It will teach participants to set up Android Studio, learn Kotlin fundamentals, and build their first Android apps with Compose. The course is divided into units that introduce key Compose concepts and provide interactive exercises to apply the learning.
Android Development | Compose Camp Day 1 | GDSC SEC Sasaram.pdfShivamShrey1
This document provides an overview and schedule for Compose Camp, which teaches how to build Android apps using Jetpack Compose. Compose Camp introduces participants to Kotlin programming, setting up Android Studio, and learning Jetpack Compose. The schedule outlines topics to be covered each day such as creating variables and functions in Kotlin. Prerequisites include basic computer skills and an internet connection. The goal is for participants to build their first Android apps using Compose.
This document provides an overview and schedule for Compose Camp, which teaches how to build Android apps using Jetpack Compose. Compose Camp includes learning objectives like building first Android apps, setting up Android Studio, learning Kotlin programming basics, and discovering additional resources. The schedule outlines topics each day like introducing Kotlin programming language, creating and using variables and functions in Kotlin, and includes breaks. The document encourages sharing what is learned on social media and submitting tips to Android for a chance to be featured. It concludes by providing additional optional learning resources.
The document provides instructions and examples for creating a basic Android application using Kotlin and Jetpack Compose. It introduces Android Studio and the tools for building Compose apps. It demonstrates how to define composable functions to display text and images. It shows how to organize composables using Column and preview the UI using the @Preview annotation. The goal is to build a simple pet adoption app that displays the name, information and photo of a dog.
This document summarizes Session 2 of Compose Camp which provided an introduction to Kotlin and Jetpack Compose. It began with an overview of basic Kotlin data types like String, Int, Double, and Boolean. It then covered defining variables with val and var keywords and initializing their values. The document showed examples of control flows like if/else statements, for loops, while loops, and functions. It demonstrated working with collections like lists, arrays, and maps. Finally, it previewed upcoming sessions and shared additional resources for learning Compose.
The document is a collection of snippets about learning Kotlin and building Android apps. It includes explanations of Kotlin concepts like functions, variables, data types, conditionals, loops, and collections methods. It also discusses Compose Camp which is an introduction to building Android apps with Jetpack Compose. The snippets provide code examples and explanations to help teach Kotlin programming basics.
The document is a presentation on basics of Android development using Kotlin and Jetpack Compose. It includes an introduction to Kotlin programming concepts like variables, functions, data types etc. It then covers topics like building a basic Android app using Android Studio and Jetpack Compose. The schedule includes an introduction to Kotlin, setting up Android Studio and building a first Android app.
The document outlines an agenda for Compose Camp Day 1. It includes introducing Kotlin basics, installing Android Studio, and building a basic layout. It also introduces the camp leaders and what Compose Camp is. The learning objectives for the camp are to set up Android Studio, learn Kotlin, Jetpack Compose, and how to create an Android app. The document provides information on installing Android Studio and an overview of its interface including the project view, code view, design view, and split view. It also describes what an emulator is and how to create one in Android Studio.
The document outlines an agenda for Day 1 of Compose Camp. It will include introductions to Kotlin basics, installing Android Studio, and building a basic layout. Attendees will learn the fundamentals of the Kotlin programming language, how to set up Android Studio on their computers, and how to create a basic Android app using Jetpack Compose. The goal is for participants to get hands-on experience developing Android apps with Compose.
The document outlines an agenda for Day 1 of Compose Camp. It will include introductions to Kotlin basics, installing Android Studio, and building a basic layout. Attendees will learn how to set up Android Studio on their computers and create their first Android app using Jetpack Compose. By the end of the day, participants will have an understanding of Kotlin programming fundamentals like functions, variables, and data types, and how to use Android Studio and emulators to build and test Compose apps. Optional resources for continuing learning are also provided.
This document provides information about Compose Camp 2022, which is a hands-on introduction to building Android apps with Jetpack Compose. The camp will teach attendees how to set up Android Studio, learn the basics of Kotlin programming, and build their first Android apps with Compose. It includes schedules, learning objectives, pathways for different topics, and previews of sample apps that will be created. Pathways cover Kotlin basics, Android Studio, creating a greeting app, and building a pet adoption app with images and multiple composable functions. The goal is for attendees to learn enough to continue exploring Compose development on their own after the camp.
This Android development workshop is a gateway to the exciting world of mobile app development. Whether you're a complete beginner or have some programming expertise, this class will provide you with the core skills and knowledge required to create great Android apps.
The document provides an overview of key Kotlin programming concepts including functions, variables, data types, control flow, classes and objects. Some key points covered include:
- Functions are segments of a program that perform specific tasks and can take parameters and return values. The main function is the entry point of a Kotlin program.
- Variables are containers that hold values of different data types like String, Int, Boolean. Variables are defined using val for immutable values and var for mutable values.
- Control flow is handled through if/else statements and when expressions. These allow different code blocks to execute conditionally.
- Classes provide blueprints to create objects with properties and methods. Objects are instances of classes
This document outlines an introduction to Kotlin and Jetpack Compose event called Compose Camp. It provides an overview of what Compose Camp is, which is a community-organized event to teach attendees hands-on coding skills using Jetpack Compose. The document outlines the learning objectives, such as building first Android apps, setting up Android Studio, learning Kotlin and Compose. It also provides information on resources for continuing learning Compose after the event.
The document outlines an introduction to Kotlin and Jetpack Compose event called Compose Camp. It provides information on what Compose Camp is, which is a community-organized event for learning how to build Android apps using Jetpack Compose through hands-on coding. It details the learning objectives of Compose Camp, which are to build first Android apps, set up Android Studio, learn Kotlin basics and Jetpack Compose, and find additional learning resources. It also provides an overview of some Kotlin and Compose concepts that will be covered, such as functions, variables, and the @Composable annotation.
This document provides information about a Compose Camp event to teach Android app development using Jetpack Compose. The event is intended for beginners, including those with no programming experience. Attendees will learn Kotlin basics, how to build Android UIs with Compose, and modern Android development best practices. The agenda includes sessions on Kotlin programming concepts like variables, data types, functions, and conditional statements. Hands-on coding exercises will have attendees creating simple apps to practice their new skills.
The document provides an overview of Compose Camp, which is a hands-on introduction to learning how to build Android apps with Jetpack Compose. The agenda for Day 1 includes an introduction to Jetpack Compose, basics of Kotlin, an overview of Android Studio, and UI elements of Compose. The facilitator Rohit will give an introduction and discuss his journey learning Android development.
This document provides instructions for building a tip calculator app in Kotlin using the Jetpack Compose UI toolkit. It begins by introducing the concept of state in Compose and how to add a text field to capture user input. It then shows how to store the input as a state variable and recompose the UI when that state changes. Finally, it demonstrates how to calculate the tip amount based on the input and display it, as well as how to host state at the top level to share it across composable functions. The goal is to create an interactive app that calculates a tip based on the cost of service entered by the user.
This document provides instructions for building an interactive tip calculator app in Kotlin using the Jetpack Compose UI toolkit. It teaches how to use state management in Compose by creating state variables to track user input fields and calculate the tip amount. It shows how to add text fields, buttons and switches to collect user input for the service amount and tip percentage. The state is hosted at the top-level screen to share it between composables and recompute the tip when the inputs change.
The document provides information about Compose Camp events, which are community-organized events focused on learning how to build Android apps using Jetpack Compose. Attendees get hands-on coding experience with Compose in a fun camp theme. Compose Camp has a similar learning format to Android Study Jams, with a group coming together for hands-on learning of a specific Android topic like Compose. The document also provides details about benefits of using Jetpack Compose for app development, such as less code, intuitive use, accelerated development, and powerful features.
The document provides information on various Kotlin programming concepts including variables, data types, functions, conditionals, operators, and the when statement. It defines key terms like val and var for declaring variables, and fun for declaring functions. It demonstrates how to use println and print to output values. Examples are provided for arithmetic operators, relational operators, increment/decrement operators, if/else conditional statements, and when expressions.
This document provides an introduction and overview of Compose Camp, which teaches how to build Android apps using Jetpack Compose. The camp will cover building a first Android app, setting up Android Studio, learning Kotlin basics and Compose, and finding additional learning resources. The agenda for Day 1 includes an introduction to Compose and Kotlin, an Android Studio overview, learning about Compose UI elements and previews, and a Q&A session.
This document provides an introduction to Kotlin, a statically typed programming language used for Android development. It highlights some key advantages of Kotlin such as requiring less boilerplate code compared to Java. The document then covers Kotlin fundamentals including variables, data types, conditional statements, functions and classes. It provides code examples for each concept to help new developers learn Kotlin.
This document contains multiple sections about Kotlin programming concepts including:
- Kotlin allows developers to write code more concisely and build more stable apps.
- A Kotlin program requires a main function as the entry point. Functions are defined with a name, optional inputs, and a body of code.
- Variables are used to store data and can be declared with specific data types like Int or String.
- Conditionals like if/else and when statements allow code to run conditionally.
- Kotlin supports null safety with nullable types, the safe call operator (?.), and not-null assertion operator (!!).
The document provides an overview of Compose Camp, which is an introduction to building Android apps with Jetpack Compose. It outlines the learning objectives, which include building first Android apps, setting up Android Studio, learning Kotlin basics and Compose. The schedule for Unit 1 is also included, covering topics like creating variables and functions in Kotlin.
This document contains a summary of an introductory session on Kotlin programming. It defines Kotlin as an open-source language that targets the JVM, Android, JavaScript and Native platforms. It notes that Kotlin code is shorter and more readable than Java for the same problems. The document discusses variables, data types, functions, and differences between var and val keywords in Kotlin. It provides examples of printing, defining variables, adding comments, defining functions, and passing parameters to functions.
The document outlines an agenda for Compose Camp Day 1. It includes introducing Kotlin basics, installing Android Studio, and building a basic layout. It also introduces the camp leaders and what Compose Camp is. The learning objectives for the camp are to set up Android Studio, learn Kotlin, Jetpack Compose, and how to create an Android app. The document provides information on installing Android Studio and an overview of its interface including the project view, code view, design view, and split view. It also describes what an emulator is and how to create one in Android Studio.
The document outlines an agenda for Day 1 of Compose Camp. It will include introductions to Kotlin basics, installing Android Studio, and building a basic layout. Attendees will learn the fundamentals of the Kotlin programming language, how to set up Android Studio on their computers, and how to create a basic Android app using Jetpack Compose. The goal is for participants to get hands-on experience developing Android apps with Compose.
The document outlines an agenda for Day 1 of Compose Camp. It will include introductions to Kotlin basics, installing Android Studio, and building a basic layout. Attendees will learn how to set up Android Studio on their computers and create their first Android app using Jetpack Compose. By the end of the day, participants will have an understanding of Kotlin programming fundamentals like functions, variables, and data types, and how to use Android Studio and emulators to build and test Compose apps. Optional resources for continuing learning are also provided.
This document provides information about Compose Camp 2022, which is a hands-on introduction to building Android apps with Jetpack Compose. The camp will teach attendees how to set up Android Studio, learn the basics of Kotlin programming, and build their first Android apps with Compose. It includes schedules, learning objectives, pathways for different topics, and previews of sample apps that will be created. Pathways cover Kotlin basics, Android Studio, creating a greeting app, and building a pet adoption app with images and multiple composable functions. The goal is for attendees to learn enough to continue exploring Compose development on their own after the camp.
This Android development workshop is a gateway to the exciting world of mobile app development. Whether you're a complete beginner or have some programming expertise, this class will provide you with the core skills and knowledge required to create great Android apps.
The document provides an overview of key Kotlin programming concepts including functions, variables, data types, control flow, classes and objects. Some key points covered include:
- Functions are segments of a program that perform specific tasks and can take parameters and return values. The main function is the entry point of a Kotlin program.
- Variables are containers that hold values of different data types like String, Int, Boolean. Variables are defined using val for immutable values and var for mutable values.
- Control flow is handled through if/else statements and when expressions. These allow different code blocks to execute conditionally.
- Classes provide blueprints to create objects with properties and methods. Objects are instances of classes
This document outlines an introduction to Kotlin and Jetpack Compose event called Compose Camp. It provides an overview of what Compose Camp is, which is a community-organized event to teach attendees hands-on coding skills using Jetpack Compose. The document outlines the learning objectives, such as building first Android apps, setting up Android Studio, learning Kotlin and Compose. It also provides information on resources for continuing learning Compose after the event.
The document outlines an introduction to Kotlin and Jetpack Compose event called Compose Camp. It provides information on what Compose Camp is, which is a community-organized event for learning how to build Android apps using Jetpack Compose through hands-on coding. It details the learning objectives of Compose Camp, which are to build first Android apps, set up Android Studio, learn Kotlin basics and Jetpack Compose, and find additional learning resources. It also provides an overview of some Kotlin and Compose concepts that will be covered, such as functions, variables, and the @Composable annotation.
This document provides information about a Compose Camp event to teach Android app development using Jetpack Compose. The event is intended for beginners, including those with no programming experience. Attendees will learn Kotlin basics, how to build Android UIs with Compose, and modern Android development best practices. The agenda includes sessions on Kotlin programming concepts like variables, data types, functions, and conditional statements. Hands-on coding exercises will have attendees creating simple apps to practice their new skills.
The document provides an overview of Compose Camp, which is a hands-on introduction to learning how to build Android apps with Jetpack Compose. The agenda for Day 1 includes an introduction to Jetpack Compose, basics of Kotlin, an overview of Android Studio, and UI elements of Compose. The facilitator Rohit will give an introduction and discuss his journey learning Android development.
This document provides instructions for building a tip calculator app in Kotlin using the Jetpack Compose UI toolkit. It begins by introducing the concept of state in Compose and how to add a text field to capture user input. It then shows how to store the input as a state variable and recompose the UI when that state changes. Finally, it demonstrates how to calculate the tip amount based on the input and display it, as well as how to host state at the top level to share it across composable functions. The goal is to create an interactive app that calculates a tip based on the cost of service entered by the user.
This document provides instructions for building an interactive tip calculator app in Kotlin using the Jetpack Compose UI toolkit. It teaches how to use state management in Compose by creating state variables to track user input fields and calculate the tip amount. It shows how to add text fields, buttons and switches to collect user input for the service amount and tip percentage. The state is hosted at the top-level screen to share it between composables and recompute the tip when the inputs change.
The document provides information about Compose Camp events, which are community-organized events focused on learning how to build Android apps using Jetpack Compose. Attendees get hands-on coding experience with Compose in a fun camp theme. Compose Camp has a similar learning format to Android Study Jams, with a group coming together for hands-on learning of a specific Android topic like Compose. The document also provides details about benefits of using Jetpack Compose for app development, such as less code, intuitive use, accelerated development, and powerful features.
The document provides information on various Kotlin programming concepts including variables, data types, functions, conditionals, operators, and the when statement. It defines key terms like val and var for declaring variables, and fun for declaring functions. It demonstrates how to use println and print to output values. Examples are provided for arithmetic operators, relational operators, increment/decrement operators, if/else conditional statements, and when expressions.
This document provides an introduction and overview of Compose Camp, which teaches how to build Android apps using Jetpack Compose. The camp will cover building a first Android app, setting up Android Studio, learning Kotlin basics and Compose, and finding additional learning resources. The agenda for Day 1 includes an introduction to Compose and Kotlin, an Android Studio overview, learning about Compose UI elements and previews, and a Q&A session.
This document provides an introduction to Kotlin, a statically typed programming language used for Android development. It highlights some key advantages of Kotlin such as requiring less boilerplate code compared to Java. The document then covers Kotlin fundamentals including variables, data types, conditional statements, functions and classes. It provides code examples for each concept to help new developers learn Kotlin.
This document contains multiple sections about Kotlin programming concepts including:
- Kotlin allows developers to write code more concisely and build more stable apps.
- A Kotlin program requires a main function as the entry point. Functions are defined with a name, optional inputs, and a body of code.
- Variables are used to store data and can be declared with specific data types like Int or String.
- Conditionals like if/else and when statements allow code to run conditionally.
- Kotlin supports null safety with nullable types, the safe call operator (?.), and not-null assertion operator (!!).
The document provides an overview of Compose Camp, which is an introduction to building Android apps with Jetpack Compose. It outlines the learning objectives, which include building first Android apps, setting up Android Studio, learning Kotlin basics and Compose. The schedule for Unit 1 is also included, covering topics like creating variables and functions in Kotlin.
This document contains a summary of an introductory session on Kotlin programming. It defines Kotlin as an open-source language that targets the JVM, Android, JavaScript and Native platforms. It notes that Kotlin code is shorter and more readable than Java for the same problems. The document discusses variables, data types, functions, and differences between var and val keywords in Kotlin. It provides examples of printing, defining variables, adding comments, defining functions, and passing parameters to functions.
1. This work is licensed under the Apache 2.0 License
Kotlin Fundamentals
2. This work is licensed under the Apache 2.0 License
Compose apps are written in
the Kotlin programming
language.
Kotlin is the language that the
majority of professional Android
developers use to build apps.
3. This work is licensed under the Apache 2.0 License
Kotlin Playground
Write and run Kotlin code in
the browser.
https://play.kotlinlang.org/
4. This work is licensed under the Apache 2.0 License
Program
A series of instructions for a
computer to perform some
action.
fun main() {
println("Hello, world!")
}
Output:
Hello, world!
5. Functions
A function is a segment of a program that
performs a specific task.
You can have many functions in your program
6. This work is licensed under the Apache 2.0 License
main Function
The main function is the entry
point, or starting point, of the
program.
Start here
fun main() {
println("Hello, world!")
}
Output:
Hello, world!
7. This work is licensed under the Apache 2.0 License
Defining a function
Functions begin with the fun
keyword.
fun displayIntroduction() {
}
8. This work is licensed under the Apache 2.0 License
Defining a function
Functions have a name so that
they can be called.
fun displayIntroduction() {
}
9. This work is licensed under the Apache 2.0 License
Defining a function
Functions need a set of parentheses
after the function name in order to
surround the function inputs or
parameters.
fun displayIntroduction() {
}
10. This work is licensed under the Apache 2.0 License
Defining a function
The curly braces make up the
function body and contain the
instructions needed to execute
a task.
fun displayIntroduction() {
// Body
}
11. This work is licensed under the Apache 2.0 License
Putting it together
fun main() {
firstFunction() // Call a function
}
// Define a function
fun firstFunction() {
// Function Body
}
12. This work is licensed under the Apache 2.0 License
Basic data types
Kotlin Data type What kind of data it can contain Example literal values
String Text
“Add contact”
“Search”
Int Whole integer number
32
-59873
Double Decimal number
2.0
-37123.9999
Float
Decimal number (less precise than a Double).
Has an f or F at the end of the number.
5.0f
-1630.209f
Boolean
true or false. Use this data type when there
are only two possible values.
true
false
13. This work is licensed under the Apache 2.0 License
A container for a single piece of
data.
Variables
14. This work is licensed under the Apache 2.0 License
val keyword
Use when you expect the variable value will
not change.
Example: name
var keyword
Use when you expect the variable value can
change.
Example: age
Defining a variable
15. This work is licensed under the Apache 2.0 License
Defining a variable
Variables start with a var or val
keyword.
fun main() {
val name: String = "Bhavye"
var age: Int = 20
}
16. This work is licensed under the Apache 2.0 License
Defining a variable
All variables must have a name.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
17. This work is licensed under the Apache 2.0 License
Defining a variable
Data type is the type of data
that the variable holds.
fun main() {
val name: String = "Meghan"
var age: Int = 28
}
18. This work is licensed under the Apache 2.0 License
Defining a variable
The initial value is the value that
is stored in the variable.
fun main() {
val name: String = "Meghan"
var age: Int = 28
// val name = “Meghan”
// var age = 28
}
19. This work is licensed under the Apache 2.0 License
Defining a variable
If we want to define a variable
with no initial value.
fun main() {
val name: String
var age: Int
// var age => Error
}
Editor's Notes
To make it easier for you to learn, you’ll be writing your code in the Kotlin Playground which you can access via the web browser. The site looks something like this. You can write your code in this window and run it by hitting the green Run button. The result of your code (known as the output) will show up at the bottom of the window (where it says “Hello, world!”).
To illustrate a few important concepts that you’ll learn in this pathway, we will go through a short code demo to create a program in Kotlin.
In Kotlin Playground, you will learn to explore and modify simple programs in Kotlin. You can think of a program as a series of instructions for a computer or mobile device to perform some action. In this program, the action is printing “Hello, world!”.
A function is a segment of a program that performs a specific task. You can have many functions in your program or only a single one.
Creating separate functions for specific tasks has a number of benefits.
Reusable code: Rather than copying and pasting code that you need to use more than once, you can simply call a function wherever needed.
Readability: Ensuring functions do one and only one specific task helps other developers and teammates, as well as your future self to know exactly what a piece of code does.
A Kotlin program is required to have a main function, which is the entry point, or starting point, of the program.
You may be asking what a function is…
We will demonstrate how to define a function with a function called displayIntroduction() that we will use to print our name and age.
A function definition starts with the fun keyword. A keyword is a reserved word that has a special meaning in Kotlin, in this case the fun keyword tells Kotlin that you are going to make a function.
Functions need to have a descriptive name so that they can be called from other parts of the program.
Functions need a set of parentheses which you can use to optionally pass information into the function. displayIntroduction() won’t need information passed in. You will learn more about passing in inputs into functions later in the course.
Functions need curly braces that contain the instructions needed to execute a task.
Finally, we will replace the contents of the main() function with a call to the displayIntroduction() function when we run it, “Hi I’m Meghan and I am 28 years old” will print to the output.
In this lecture we went over functions and variables and how to put them together to create a function that introduces you. Soon you will go deeper into these concepts and try them out for yourself in the codelabs.
When you decide what aspects of your app can be variables, it's important to specify what type of data can be stored in those variables. In Kotlin, there are some common basic data types. This table shows a different data type in each row. For each data type, there's a description of what kind of data it can hold and example values.
A String holds text so you will use it to store your name, and an Int holds an integer number so you will use it to store your age.
In computer programming, a variable is a container for a single piece of data. You can envision it as a box that contains a value. The box has a label, which is the name of the variable. By referring to the box by its name, you have access to the value it holds.
Now, let’s jump into how you define a variable.
You can declare a variable using either val or var.
With val, the variable is read-only, which means you can only read, or access, the value of the variable. Once the value is set, you cannot edit or modify its value.
With var, the variable is mutable, which means the value can be changed or modified. The value can be mutated.
In Kotlin, it's preferred to use val over var when possible.
We will store your name as a val because that will not change.
We will store your age as a var because it changes every year.
To demonstrate how to define a variable we will define both name and age variables.
Before you use a variable, you must declare it. To declare a variable, start with the val or var keyword.
All variables must have a name that they can be referenced by.
The data type specifies the type of data that the variable holds. Note that a colon separates the name and data type.
In the variable declaration, the equal sign symbol (=) follows the data type. The equal sign symbol is called the assignment operator. The assignment operator assigns a value to the variable. The variable’s initial value is the data stored in the variable.
In the variable declaration, the equal sign symbol (=) follows the data type. The equal sign symbol is called the assignment operator. The assignment operator assigns a value to the variable. The variable’s initial value is the data stored in the variable.