SlideShare une entreprise Scribd logo
1  sur  15
This work is licensed under the Apache 2.0 License
Android Study Jams
#Session 2
DSC - MSEC
This work is licensed under the Apache 2.0 License
fun main() {
println("Hello world!")
}
What does this code do?
This work is licensed under the Apache 2.0 License
fun main() {
println("Hello world!")
}
What does this code do?
>>> Hello world!
This work is licensed under the Apache 2.0 License
fun main() {
println("Hello world!")
}
What do you notice about Kotlin?
This work is licensed under the Apache 2.0 License
fun add(a: Int, b: Int): Int {
return a + b
}
fun display(): Unit {
println("Welcome")
}
Parameters and Return Type
This work is licensed under the Apache 2.0 License
mutable variable var counter: Int = 5
val name: String = "Rebecca"immutable variable
This work is licensed under the Apache 2.0 License
var length = 5
val message = "Welcome"
What’s interesting about these
variable declarations?
This work is licensed under the Apache 2.0 License
if (score < 20) {
println("Low")
} else if (score < 70) {
println("Medium")
} else {
println("High")
}
when (x) {
0 -> endGame()
1 -> moveNext()
2 -> skipTurn()
}
This work is licensed under the Apache 2.0 License
side
// This is the Square class
// definition
class Square(val side: Int)
// This is a Square instance
val s = Square(10)
println(s.side)
Classes
This work is licensed under the Apache 2.0 License
val numList = listOf(1, 2, 3)
val numSet = setOf(4, 5, 6)
val numMap = mapOf("a" to 10, "b" to 20, "b" to 30)
Collections
This work is licensed under the Apache 2.0 License
Layouts
This work is licensed under the Apache 2.0 License
TextView ImageView Button
Hello Android!
Views
This work is licensed under the Apache 2.0 License
FrameLayout
TextView
TextView
TextView
Button
LinearLayout
TextVie
w
Button
ConstraintLayout
TextVie
w
ViewGroups
This work is licensed under the Apache 2.0 License
● Activity
● Resources (layout files, images, strings, themes, etc...)
● AndroidManifest.xml
● Gradle files
Anatomy of a Basic App Project
This work is licensed under the Apache 2.0 License
Hello World!
Declare layouts in XML
<TextView
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

Contenu connexe

Tendances

ncurses in your hobostove
ncurses in your hobostovencurses in your hobostove
ncurses in your hobostove
SmartLogic
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
Rakesh Madugula
 
PythonPythagoreanTheorem
PythonPythagoreanTheoremPythonPythagoreanTheorem
PythonPythagoreanTheorem
Matt R
 

Tendances (20)

Throttle and Debounce Patterns in Web Apps
Throttle and Debounce Patterns in Web AppsThrottle and Debounce Patterns in Web Apps
Throttle and Debounce Patterns in Web Apps
 
Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017Introduction to Coroutines @ KotlinConf 2017
Introduction to Coroutines @ KotlinConf 2017
 
Kotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is comingKotlin Coroutines. Flow is coming
Kotlin Coroutines. Flow is coming
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
ncurses in your hobostove
ncurses in your hobostovencurses in your hobostove
ncurses in your hobostove
 
LvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncioLvivPy4 - Threading vs asyncio
LvivPy4 - Threading vs asyncio
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Fresh Async with Kotlin @ QConSF 2017
Fresh Async with Kotlin @ QConSF 2017Fresh Async with Kotlin @ QConSF 2017
Fresh Async with Kotlin @ QConSF 2017
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Assignment#1
Assignment#1Assignment#1
Assignment#1
 
The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.5.2 book - Part 46 of 181The Ring programming language version 1.5.2 book - Part 46 of 181
The Ring programming language version 1.5.2 book - Part 46 of 181
 
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
 
NoiseGen at Arlington Ruby 2012
NoiseGen at Arlington Ruby 2012NoiseGen at Arlington Ruby 2012
NoiseGen at Arlington Ruby 2012
 
New features and enhancement
New features and enhancementNew features and enhancement
New features and enhancement
 
timingExercise
timingExercisetimingExercise
timingExercise
 
Textile
TextileTextile
Textile
 
Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02Rust concurrency tutorial 2015 12-02
Rust concurrency tutorial 2015 12-02
 
Puerto serialarduino
Puerto serialarduinoPuerto serialarduino
Puerto serialarduino
 
PythonPythagoreanTheorem
PythonPythagoreanTheoremPythonPythagoreanTheorem
PythonPythagoreanTheorem
 
FSE 2008
FSE 2008FSE 2008
FSE 2008
 

Similaire à DSC - Android Study Jams - Session 2

Similaire à DSC - Android Study Jams - Session 2 (20)

Compose Camp
Compose Camp Compose Camp
Compose Camp
 
day1.docx
day1.docxday1.docx
day1.docx
 
Prior programming experience track
Prior programming experience trackPrior programming experience track
Prior programming experience track
 
Kotlin Fundamentals.pptx
Kotlin Fundamentals.pptxKotlin Fundamentals.pptx
Kotlin Fundamentals.pptx
 
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
Compose Camp - Jetpack Compose for Android Developers Introduction Session De...
 
Compose Camp Session 2
Compose Camp Session 2Compose Camp Session 2
Compose Camp Session 2
 
Session 1 ppt.pptx
Session 1 ppt.pptxSession 1 ppt.pptx
Session 1 ppt.pptx
 
Compose Camp #1.pptx
Compose  Camp #1.pptxCompose  Camp #1.pptx
Compose Camp #1.pptx
 
Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2Android Study Jam Prior Prog S-2
Android Study Jam Prior Prog S-2
 
Introduction to KOTLIN.pptx
Introduction to KOTLIN.pptxIntroduction to KOTLIN.pptx
Introduction to KOTLIN.pptx
 
Google Solution Challenge Android Awesomeness.pptx
Google Solution Challenge Android Awesomeness.pptxGoogle Solution Challenge Android Awesomeness.pptx
Google Solution Challenge Android Awesomeness.pptx
 
-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx-Kotlin_Camp_Unit2.pptx
-Kotlin_Camp_Unit2.pptx
 
-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx-Kotlin Camp Unit2.pptx
-Kotlin Camp Unit2.pptx
 
GDSC_day_1.pptx
GDSC_day_1.pptxGDSC_day_1.pptx
GDSC_day_1.pptx
 
Compose Camp Session 1.pdf
Compose Camp Session 1.pdfCompose Camp Session 1.pdf
Compose Camp Session 1.pdf
 
Compose Camp - Jetpack Compose for Android Developers _ Introduction Session ...
Compose Camp - Jetpack Compose for Android Developers _ Introduction Session ...Compose Camp - Jetpack Compose for Android Developers _ Introduction Session ...
Compose Camp - Jetpack Compose for Android Developers _ Introduction Session ...
 
Day3New GDSC.pptx
Day3New GDSC.pptxDay3New GDSC.pptx
Day3New GDSC.pptx
 
Jetpack Compose Recap Session.pdf
Jetpack Compose Recap Session.pdfJetpack Compose Recap Session.pdf
Jetpack Compose Recap Session.pdf
 
Scaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with ScalaScaladroids: Developing Android Apps with Scala
Scaladroids: Developing Android Apps with Scala
 
Scientific Computing with Python Webinar: Traits
Scientific Computing with Python Webinar: TraitsScientific Computing with Python Webinar: Traits
Scientific Computing with Python Webinar: Traits
 

Dernier

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 

Dernier (20)

VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Unit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdfUnit 2- Effective stress & Permeability.pdf
Unit 2- Effective stress & Permeability.pdf
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects2016EF22_0 solar project report rooftop projects
2016EF22_0 solar project report rooftop projects
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
Hazard Identification (HAZID) vs. Hazard and Operability (HAZOP): A Comparati...
 

DSC - Android Study Jams - Session 2

  • 1. This work is licensed under the Apache 2.0 License Android Study Jams #Session 2 DSC - MSEC
  • 2. This work is licensed under the Apache 2.0 License fun main() { println("Hello world!") } What does this code do?
  • 3. This work is licensed under the Apache 2.0 License fun main() { println("Hello world!") } What does this code do? >>> Hello world!
  • 4. This work is licensed under the Apache 2.0 License fun main() { println("Hello world!") } What do you notice about Kotlin?
  • 5. This work is licensed under the Apache 2.0 License fun add(a: Int, b: Int): Int { return a + b } fun display(): Unit { println("Welcome") } Parameters and Return Type
  • 6. This work is licensed under the Apache 2.0 License mutable variable var counter: Int = 5 val name: String = "Rebecca"immutable variable
  • 7. This work is licensed under the Apache 2.0 License var length = 5 val message = "Welcome" What’s interesting about these variable declarations?
  • 8. This work is licensed under the Apache 2.0 License if (score < 20) { println("Low") } else if (score < 70) { println("Medium") } else { println("High") } when (x) { 0 -> endGame() 1 -> moveNext() 2 -> skipTurn() }
  • 9. This work is licensed under the Apache 2.0 License side // This is the Square class // definition class Square(val side: Int) // This is a Square instance val s = Square(10) println(s.side) Classes
  • 10. This work is licensed under the Apache 2.0 License val numList = listOf(1, 2, 3) val numSet = setOf(4, 5, 6) val numMap = mapOf("a" to 10, "b" to 20, "b" to 30) Collections
  • 11. This work is licensed under the Apache 2.0 License Layouts
  • 12. This work is licensed under the Apache 2.0 License TextView ImageView Button Hello Android! Views
  • 13. This work is licensed under the Apache 2.0 License FrameLayout TextView TextView TextView Button LinearLayout TextVie w Button ConstraintLayout TextVie w ViewGroups
  • 14. This work is licensed under the Apache 2.0 License ● Activity ● Resources (layout files, images, strings, themes, etc...) ● AndroidManifest.xml ● Gradle files Anatomy of a Basic App Project
  • 15. This work is licensed under the Apache 2.0 License Hello World! Declare layouts in XML <TextView android:text="Hello World!" android:layout_width="wrap_content" android:layout_height="wrap_content" />

Notes de l'éditeur

  1. What does everyone think this code does? [Continue to get audience participation until someone says “It prints Hello World!”.]
  2. Right! It prints Hello world!
  3. But what are some things you notice about Kotlin? [Continue to get audience participation until they mention these things.] Functions are declared with the ‘fun’ keyword Kotlin programs need a main() function Kotlin uses curly braces to enclose a function body Semicolons are not needed in Kotlin println function is used to print a line of output to console If after a few people speaking they’re not mentioning all of those listed above, you should jump in and say:] Specifically, every Kotlin program requires a main() function. A function is declared by using the fun keyword in Kotlin, followed by the name of the method, input parameters in parentheses, and then the function body in curly braces. This function prints “Hello world!” to the console. Notice that there’s no semicolons needed. The main() function in Kotlin can take in args as input, which is an array of strings. But the input args are optional and can be omitted as shown above, further simplifying this short program!
  4. Here’s other examples of functions in Kotlin Declare them with the fun keyword as you saw before. What’s new here is seeing how function parameters are defined. Following each parameter name, insert a colon followed by a space and then the data type of the parameter. After the parameters, insert a colon followed by a space and then the return type of the function (which is Int in this case). Within the function body, specify the return value of a function with the return keyword in Kotlin. If there is no return value, you can specify Unit as the return type. Or for more concise code, you can just omit the return type from the function declaration, as you saw with the main() function earlier. For more info https://kotlinlang.org/docs/reference/functions.html
  5. Next, let’s discuss variables. You can declare variables with the var keyword (for mutable variables) or with the val keyword (for immutable variables). Use var if you want change the value it’s assigned to, like a counter variable that would be updated. Use val if you only need to assign the variable once. In this case, we don’t expect the name to change. It is recommended to use val over var when possible. Note that regardless of whether the keyword var or val was used, the objects themselves may still be mutable or not. For example, you can declare a mutable list with val myList = mutableListOf(). While the reference to the list doesn’t change, you can still add or remove items from myList. For more info https://kotlinlang.org/docs/reference/basic-syntax.html https://play.kotlinlang.org/byExample/01_introduction/03_Variables
  6. These are also valid ways to declare variables in Kotlin. What do you notice about this code? [Get some audience participation] No data type is specified. We didn’t need to specify that length is an integer or that message is a String. Kotlin supports type inference, which means you can omit the type in your code when the compiler can infer it. In this case, the Kotlin compiler can infer that length is an integer and message is a String. Type inference is a powerful feature in Kotlin and allows your code to be more concise!
  7. Control flow statements in Kotlin may look similar to what you’ve seen in other languages, with some differences. You can write if-else statements as shown here. If the condition within the parentheses is true, then that branch will be executed. If none of the conditions are met, then we fall into the else block. You can also use the when keyword for conditionals, similar to a switch statement in Java. In this example, when x is equal to 0, call the endGame() function. When it’s equal to 1, call moveNext(). And so on. When statements can make your code more compact, instead of creating multiple if/else branches checking the value of a variable. In Kotlin, you can also write for loops and while loops, which aren’t shown here but you can check the documentation for examples. For more info https://kotlinlang.org/docs/reference/control-flow.html https://kotlinlang.org/docs/reference/basic-syntax.html#using-conditional-expressions https://play.kotlinlang.org/byExample/02_control_flow/01_When
  8. Kotlin supports both functional and object-oriented programming styles. For OOP, you can create classes and object instances as shown here. Within a single line of code, we can define a class called Square, and it has one property: the length of its side. Then, we instantiate a Square object instance with a length of 10 and store it in a variable called s. Looking at this code, what does this line s.side print? [Answer should be 10] For more info: https://kotlinlang.org/docs/reference/classes.html
  9. The Kotlin Standard Library also offers a lot of functionality to help you manage and manipulate collections of items easily. You can create lists, sets, and maps for example. This is just a brief overview of some of the basics of Kotlin and you’ll dive into more details in the hands-on part of this session. For more info: https://kotlinlang.org/docs/reference/collections-overview.html
  10. Then you’ll build an interactive Dice Roller app and learn about layouts. A layout defines the structure for the user interface in your app, and layouts in Android are made up of a hierarchy of Views and ViewGroups.
  11. Here are some types of views that are provided by Android: TextView for displaying text, ImageView for displaying images, and Button to perform some action when tapped.
  12. To position one or more views on screen, use a ViewGroup. Here are some examples of ViewGroups in Android. Use FrameLayout when you have one view that you want to position on the screen. Use LinearLayout to display a row of views or a column of views, as shown in the diagram. Use ConstraintLayout for more complex layouts. You may hear the ViewGroup referred to as the parent, and the views inside it as its children.
  13. You’ll also be exploring other aspects of a basic Android app project which include a main activity, resources for your app, an Android Manifest file, and Gradle files. An Activity is how the user interacts with your app and it takes care of creating a window to display your UI in. Resources are the additional files and static content that your code uses, such as layout files, images, audio files, UI strings, themes, and more. Every project also includes an AndroidManifest.xml file. It describes essential information about your app such as the app’s package name, components of the app, and permissions it needs access to. Android uses Gradle to automate and manage the build process for your app. You can configure the build by modifying the Gradle files in your app to specify project dependencies, properties of your app, build variants, and more. This is a quick overview of the anatomy of a basic app project. You’ll have more time to dive in and explore these files firsthand in the course. For more info https://developer.android.com/guide/components/activities/intro-activities https://developer.android.com/guide/topics/resources/providing-resources https://developer.android.com/guide/topics/manifest/manifest-intro https://developer.android.com/studio/build
  14. Declare layouts in Android using XML. For example, this is what a TextView element looks like in XML. The value of the android:text attribute is the text to display, which is Hello World! The layout_width and layout_height attributes are wrap_content, meaning the TextView will be as wide and as tall as the content inside it. Defining the UI layout in XML is one aspect of your app.