Kotlin, Start? Start! (pluu) Android Developer GDG Korea Android Organizer

Size: px
Start display at page:

Download "Kotlin, Start? Start! (pluu) Android Developer GDG Korea Android Organizer"

Transcription

1 Kotlin, Start? Start! (pluu) Android Developer GDG Korea Android Organizer

2 Agenda Kotlin Overview Kotlin??

3

4

5

6

7

8

9

10 Basic fun main(args: Array<String>): Unit { println("hello, world!")

11 Basic Function Keyword fun main(args: Array<String>): Unit { println("hello, world!")

12 Basic Function Name fun main(args: Array<String>): Unit { println("hello, world!")

13 Basic Parameter Name fun main(args: Array<String>): Unit { println("hello, world!")

14 Basic Parameter Type fun main(args: Array<String>): Unit { println("hello, world!")

15 Basic Return Type fun main(args: Array<String>): Unit { println("hello, world!")

16 Basic Function Definition fun main(args: Array<String>): Unit { println("hello, world!")

17 Basic Unit return type can be omitted fun main(args: Array<String>): Unit { println("hello, world!")

18 Basic fun main(args: Array<String>) { println("hello, world!")

19 Null Safe val text: String = null // Error, non-null Type

20 Null Safe val text: String? = null

21 Null Safe Nullable Keyword val text: String? = null

22 Null Safe val text: String? = null text = 100.toString() // Error, Immutable Data

23 Null Safe Immutable Keyword val text: String? = null text = 100.toString()

24 Null Safe Mutable Keyword var text: String? = null text = 100.toString()

25 Null Safe if (data!= null && data.value!= null) { data.value.tostring()

26 Null Safe data?.value?.tostring()

27 Control Flow if / when / try

28 Control Flow statement No Return Value expression Return Value

29 Expression ( if / when / try ) Java int val a = 10; String val value: value; String Kotlin if (a > 10) { value = = "Over 10"; else { value = = "Under 10";

30 Expression ( if / when / try ) Java int a = 10; String value; if (a > 10) { value = "Over 10"; else { value = "Under 10"; Kotlin val a = 10 val value: String if (a > 10) { value = "Over 10" else { value = "Under 10"

31 Expression ( if / when / try ) Java int a = 10; String value; if (a > 10) { value = "Over 10"; else { value = "Under 10"; Kotlin val a = 10 val value = if (a > 10) { "Over 10" else { "Under 10"

32 Expression ( if / when / try ) Java int a = 10; String value; if (a > 10) { value = "Over 10"; else { value = "Under 10"; Kotlin val a = 10 val value = if (a > 10) "Over 10" else "Under 10"

33 Expression ( if / when / try ) Kotlin val a = 10 val value = if (a > 10) "Over 10" else "Under 10"

34 Expression ( if / when / try ) Java String value; if (a == 1) { value = "one"; else if (a == 2) { value = "two"; else if (a == 3) { value = "three"; else { value = "another"; Kotlin val value: String if (a === 1) { value = "one" else if (a === 2) { value = "two" else if (a === 3) { value = "three" else { value = "another"

35 Expression ( if / when / try ) Java String value; if (a == 1) { value = "one"; else if (a == 2) { value = "two"; else if (a == 3) { value = "three"; else { value = "another"; Kotlin val value: String when { a === 1 -> value = "one" a === 2 -> value = "two" a === 3 -> value = "three" else -> value = "another"

36 Expression ( if / when / try ) Java String value; if (a == 1) { value = "one"; else if (a == 2) { value = "two"; else if (a == 3) { value = "three"; else { value = "another"; Kotlin val value = when(a) { 1 -> "one" 2 -> "two" 3 -> "three" else -> "another"

37 Expression ( if / when / try ) Kotlin when (x) { parseint(s) -> print("s encodes x") in > print("x is in the range") in validnumbers -> print("x is valid")!in > print("x is outside the range") else -> print("none of the above")

38 Expression ( if / when / try ) Kotlin when (x) { Expression parseint(s) -> print("s encodes x") in > print("x is in the range") in validnumbers -> print("x is valid")!in > print("x is outside the range") else -> print("none of the above")

39 Expression ( if / when / try ) Kotlin when (x) { Range parseint(s) -> print("s encodes x") in > print("x is in the range") in validnumbers -> print("x is valid")!in > print("x is outside the range") else -> print("none of the above")

40 Expression ( if / when / try ) Kotlin when (x) { parseint(s) -> print("s encodes x") in > print("x is in the range") Not In Range in validnumbers -> print("x is valid")!in > print("x is outside the range") else -> print("none of the above")

41 Expression ( if / when / try ) Kotlin when (x) { parseint(s) -> print("s encodes x") in > print("x is in the range") in validnumbers -> print("x is valid") Optional, statement / expression!in > print("x is outside the range") else -> print("none of the above")

42 Default Parameter Java public String foo(string name, int number, boolean touppercase) { return (touppercase? name.touppercase() : name) + number; public String foo(string name, int number) { return foo(name, number, false); public String foo(string name, boolean touppercase) { return foo(name, 42, touppercase); public String foo(string name) { return foo(name, 42);

43 Default Parameter Java public String foo(string name, int number, boolean touppercase) { return (touppercase? name.touppercase() : name) + number; Default : false public String foo(string name, int number) { return foo(name, number, false); public String foo(string name, boolean touppercase) { return foo(name, 42, touppercase); Default : 42 public String foo(string name) { return foo(name, 42);

44 Default Parameter fun foo(name: String, number: Int = 42, touppercase: Boolean = false) = (if (touppercase) name.touppercase() else name) + number

45 Default Parameter fun foo(name: String, number: Int = 42, touppercase: Boolean = false) = (if (touppercase) name.touppercase() else name) + number

46 Example setter / getter hashcode equals tostring class Item { private String type1; private int type2; private float type3; private float type4;

47 public String gettype1() { return type1; Example class Item { private String type1; private int type2; private float type3; private float type4; public Item(String type1, int type2, float type3, float type4) { this.type1 = type1; this.type2 = type2; this.type3 = type3; this.type4 = type4;

48 class Item { private String type1; private int type2; private float type3; private float type4; public Item(String type1, int type2, float type3, float type4) { this.type1 = type1; this.type2 = type2; this.type3 = type3; this.type4 = type4; public String gettype1() { return type1; public void settype1(string type1) { this.type1 = type1; public int gettype2() { return type2; public void settype2(int type2) { this.type2 = type2; public float gettype3() { return type3; public void settype3(float type3) { this.type3 = type3; public float gettype4() { return type4; public void settype4(float type4) { this.type4 = public boolean equals(object o) { if (this == o) return true; if (o == null getclass()!= o.getclass()) return false; Item item = (Item) o; if (type2!= item.type2) return false; if (Float.compare(item.type3, type3)!= 0) return false; if (Float.compare(item.type4, type4)!= 0) return false; return type1!= null? type1.equals(item.type1) : item.type1 == public int hashcode() { int result = type1!= null? type1.hashcode() : 0; result = 31 * result + type2; result = 31 * result + (type3!= +0.0f? Float.floatToIntBits(type3) : 0); result = 31 * result + (type4!= +0.0f? Float.floatToIntBits(type4) : 0); return public String tostring() { return "Item{" + "type1='" + type1 + '\'' + ", type2=" + type2 + ", type3=" + type3 + ", type4=" + type4 + ''; Field? setter / getter hashcode equals tostring

49 Data Class data class Item( var type1: String?, var type2: Int, var type3: Float, var type4: Float)

50 Data Class data Keyword data class Item( var type1: String?, var type2: Int, var type3: Float, var type4: Float)

51 Data Class equals() / hashcode() tostring() componentn() functions copy() // Destructuring Declarations val jane = User("Jane", 35) val (name, age) = jane println("$name, $age years of age") // prints "Jane, 35 years of age"

52 Singleton Class Java public class A { private static final A instance = new A(); private A() { public static A getinstance() { return instance; public void b() { System.out.println("Singleton"); Custom Method

53 Object Class object A { fun b() { println("singleton") // Use A.b()

54 Object Class object A { fun b() { Object declarations println("singleton")

55 Type Inference val s: String = "Value"

56 Type Inference val s = "Value" val c = 'V' val i = 10 val l = 10L val f = 10F val d = 10.0 val b = true val sb = StringBuilder() // String // Char // Int // Long // Float // Double // Boolean // StringBuilder

57 Smart Casts if (obj is String) { print(obj.length)

58 Smart Casts if (obj is String) { print(obj.length) Type Check

59 Smart Casts if (obj is String) { print(obj.length) Smart Casts

60 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) is IntArray -> print(x.sum())

61 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) Type Check is IntArray -> print(x.sum())

62 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) Smart Casts is IntArray -> print(x.sum())

63 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) is IntArray -> print(x.sum()) Type Check

64 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) is IntArray -> print(x.sum()) Smart Casts

65 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) is IntArray -> print(x.sum()) Type Check

66 Smart Casts when (x) { is Int -> print(x + 1) is String -> print(x.length + 1) is IntArray -> print(x.sum()) Smart Casts

67 Extension Function inline fun Fragment.toast(message: CharSequence): Unit = activity.toast(message) fun Context.toast(message: CharSequence) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show() // Use in Activity/Fragment toast("hello World") commons/src/dialogs/toasts.kt

68 Extension Function fun Context.toast(message: CharSequence) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show()

69 Extension Function fun Context.toast(message: CharSequence) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show() Receiver Type

70 Extension Function fun Context.toast(message: CharSequence) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show() Function Definition

71 Extension Function fun Context.toast(message: CharSequence) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show() Function Body

72 Higher-Order Functions and Lambdas fun <T, R> List<T>.map(transform: (T) -> R): List<R> { val result = arraylistof<r>() for (item in this) result.add(transform(item)) return result

73 Higher-Order Functions and Lambdas fun <T, R> List<T>.map(transform: (T) -> R): List<R> { val result = arraylistof<r>() for (item in this) result.add(transform(item)) return result Function Type

74 Higher-Order Functions and Lambdas val list = listof(1, 2, 3) list.map({ x: Int -> x * 2 )

75 Higher-Order Functions and Lambdas val list = listof(1, 2, 3) list.map({ x: Int -> x * 2 ) list.map({ x -> x * 2 )

76 Higher-Order Functions and Lambdas val list = listof(1, 2, 3) list.map({ x: Int -> x * 2 ) list.map({ x -> x * 2 ) list.map() { x -> x * 2

77 Higher-Order Functions and Lambdas val list = listof(1, 2, 3) list.map({ x: Int -> x * 2 ) list.map({ x -> x * 2 ) list.map() { x -> x * 2 list.map { x -> x * 2

78 Higher-Order Functions and Lambdas val list = listof(1, 2, 3) list.map({ x: Int -> x * 2 ) list.map({ x -> x * 2 ) list.map() { x -> x * 2 list.map { x -> x * 2 list.map { it * 2

79

80 1. Kotlin? / / / Functional Programming Hybrid Language Best Practices

81 2.

82

83 3. Function Programming FP (ex, Predicate, High-Order Function)

84 3. FP.

85 3. FP. Groovy Lazy Lambda Clojure Pure Function Dispatch Reduce High-Order Function Monad Scala Currying

86 4. Overhead Kotlin Compiler ms Java

87 4. Overhead Kotlin fun test(x: Any) { if (x is String) { println(x.length) println(x.length) println(x.length) println(x.length) Decompile public static final void test(@notnull Object x) { Intrinsics.checkParameterIsNotNull(x, "x"); if (x instanceof String) { int var1 = ((String)x).length(); System.out.println(var1); var1 = ((String)x).length(); System.out.println(var1); var1 = ((String)x).length(); System.out.println(var1); var1 = ((String)x).length(); System.out.println(var1);

88 5. kapt Kotlin plugin supports annotation processors like Dagger or DBFlow. apply plugin: 'kotlin-kapt' kotlinc Kotlin Stubs javac Final Code Clean Build

89 6. Framework Library Your Code Java Java / Kotlin Java / Kotlin Kotlin Compiler Java Class Code Java to Kotlin, non-null null.

90

91 1. Java Java Java Java Java 9???? Android Java 7 Support 2013 Java 8 Support Jack / desugar Different for every version

92

93

94 2. Kotlin Android Extensions Kotlin Android Extensions View Binding, ViewHolder (1.1.4), Parcelable (1.1.4) Extension Function Lazy Anko

95 2. Kotlin Android Extensions import kotlinx.android.synthetic.main.activity_main.* class MyActivity : Activity() { override fun oncreate(savedinstancestate: Bundle?) { super.oncreate(savedinstancestate) setcontentview(r.layout.activity_main) textview.settext("hello, world!") Kotlin Android Extensions <TextView android:id="@+id/textview"... />

96 2. Kotlin Android Extensions apply plugin: 'kotlin-android-extensions' import kotlinx.android.synthetic.main.<layout>.* // kotlinx.android.synthetic.main.activity_main.*

97 3. Kotlin GitHub (2017/09/20 ) Stars : 5 Language : 30

98 3. Kotlin / / Kotlin Java 100% Java (N %) + Kotlin (M %),, 1 ( )

99 4. Simple is Best Delegation Data Class Singleton Null Safety Expression Destructuring Declarations Type Checks and Casts

100 5. Code Scope val person = Person().apply { name = "Pluu" age = 1 money = 1 phone = " " // More

101 5. Code Scope val person = Person().apply { name = "Pluu" age = 1 money = 1 phone = " " // More apply Calls the specified function [block] with `this` value as its receiver and returns `this` value.

102 5. Code Scope val person = Person().apply {

103 6. IntelliJ Show Kotlin Bytecode Decompile Decompile Java

104 Preferred / Used Kotlin

105

106

107 Any.kt

108

109

110

111 2017 Kotlin ( 3~4 ) GDG Kotlin Kotlin (Kotlin Reference, Twitter, Medium, Qiita) Kotlin ( )

112 , best practice

113 Action Item! Kotlin X, Kotlin Convert Java File to Kotlin File Show Kotlin Bytecode

114 Kotlin Reference ( Get Started with Kotlin It is here to stay ( Kotlin: A New Hope in a Java 6 Wasteland ( droidcon-michael-pardo-kotlin/) Kotlin (

115 Q&A GDG Slack #android #kotlin (Slack :

Kotlin for Android developers

Kotlin for Android developers ROME - APRIL 13/14 2018 Kotlin for Android developers Victor Kropp, JetBrains @kropp Kotlin on JVM + Android JS In development: Kotlin/Native ios/macos/windows/linux Links Kotlin https://kotlinlang.org

More information

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI

Programming Kotlin. Familiarize yourself with all of Kotlin s features with this in-depth guide. Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Familiarize yourself with all of Kotlin s features with this in-depth guide Stephen Samuel Stefan Bocutiu BIRMINGHAM - MUMBAI Programming Kotlin Copyright 2017 Packt Publishing First

More information

GETTING STARTED WITH Kotlin INTRODUCTION WHERE TO START CODING BASIC SYNTAX

GETTING STARTED WITH Kotlin INTRODUCTION WHERE TO START CODING BASIC SYNTAX 257 CONTENTS INTRODUCTION GETTING STARTED WITH Kotlin WHERE TO START CODING BASIC SYNTAX CONTROL FLOW: CONDITIONS CONTROL FLOW: LOOPS BASIC TYPES CLASSES FUNCTION TYPES AND LAMBDAS HIGHER-ORDER FUNCTIONS

More information

Data binding. in a Kotlin world. Lisa

Data binding. in a Kotlin world. Lisa Data binding in a Kotlin world Lisa Wray Data binding in a Kotlin world Lisa Wray Data binding in a Kotlin world Lisa Wray Less code is better code 1. Quick tour of The Best Parts of data binding 2. Kotlin

More information

The Kotlin Programming Language. Andrey Breslav

The Kotlin Programming Language. Andrey Breslav The Kotlin Programming Language Andrey Breslav What is Kotlin? Statically typed object-oriented JVM-targeted general-purpose programming language developed by JetBrains intended for industrial use Docs

More information

You can do better with Kotlin. Svetlana Isakova

You can do better with Kotlin. Svetlana Isakova You can do better with Kotlin Svetlana Isakova Kotlin Programming Language - modern - pragmatic - Android-friendly Official on Android Not only Android Pragmatic - tooling - Java interop From has good

More information

KOTLIN - A New Programming Language for the Modern Needs

KOTLIN - A New Programming Language for the Modern Needs KOTLIN - A New Programming Language for the Modern Needs [1] Mrs.J.ArockiaJeyanthi, [2] Mrs.T.Kamaleswari [1] Assistant Professor, [2] Assistant Professor, [1] Department of Computer Science, A.P.C. Mahalaxmi

More information

CS 2340 Objects and Design - Scala

CS 2340 Objects and Design - Scala CS 2340 Objects and Design - Scala Objects and Operators Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design - Scala Objects and Operators 1 / 13 Classes

More information

Kotlin for Android Developers

Kotlin for Android Developers Kotlin for Android Developers Learn Kotlin the easy way while developing an Android App Antonio Leiva This book is for sale at http://leanpub.com/kotlin-for-android-developers This version was published

More information

A Deep Dive Into Kotlin

A Deep Dive Into Kotlin A Deep Dive Into Kotlin By 1 About me (droidyue.com) @Flipboard China GDG 2 3 Kotlin An official language for Android recently Powered by Jetbrains 4 Why Kotlin Concise Safe interoperable tool-friendly

More information

Produced by. Agile Software Development. Eamonn de Leastar

Produced by. Agile Software Development. Eamonn de Leastar Agile Software Development Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie Xtend Programming

More information

Produced by. Agile Software Development. Eamonn de Leastar

Produced by. Agile Software Development. Eamonn de Leastar Agile Software Development Produced by Eamonn de Leastar (edeleastar@wit.ie) Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie Xtend Programming

More information

Kotlin for Android Developers

Kotlin for Android Developers Kotlin for Android Developers Learn Kotlin the easy way while developing an Android App Antonio Leiva This book is for sale at http://leanpub.com/kotlin-for-android-developers This version was published

More information

Understand Every Line of Your Codebase

Understand Every Line of Your Codebase Understand Every Line of Your Codebase Victoria Gonda Boris Farber Speakers Victoria Developer at Collective Idea Android and Rails Boris Partner Engineer at Google Android Partnerships Android and Java

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

The Kotlin Programming Language. Andrey Breslav Dmitry Jemerov

The Kotlin Programming Language. Andrey Breslav Dmitry Jemerov The Kotlin Programming Language Andrey Breslav Dmitry Jemerov What is Kotlin? Statically typed object-oriented JVM-targeted general-purpose programming language developed by JetBrains intended for industrial

More information

Xtend Programming Language

Xtend Programming Language Xtend Programming Language Produced by: Eamonn de Leastar (edeleastar@wit.ie) Department of Computing and Mathematics http://www.wit.ie/ Agenda Subtitle Excellent Xtend User Guide (Version 2.6) API Docs

More information

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are built on top of that. CMSC131 Inheritance Object When we talked about Object, I mentioned that all Java classes are "built" on top of that. This came up when talking about the Java standard equals operator: boolean equals(object

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

INHERITANCE. Spring 2019

INHERITANCE. Spring 2019 INHERITANCE Spring 2019 INHERITANCE BASICS Inheritance is a technique that allows one class to be derived from another A derived class inherits all of the data and methods from the original class Suppose

More information

Getting Started with Kotlin. Commerzbank Java Developer Day

Getting Started with Kotlin. Commerzbank Java Developer Day Getting Started with Kotlin Commerzbank Java Developer Day 30.11.2017 Hello! Alexander Hanschke Hello! Alexander Hanschke CTO at techdev Solutions GmbH in Berlin Hello! Alexander Hanschke CTO at techdev

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

KAI KOENIG ANKO THE ULTIMATE NINJA OF KOTLIN LIBRARIES?

KAI KOENIG ANKO THE ULTIMATE NINJA OF KOTLIN LIBRARIES? KAI KOENIG (@AGENTK) ANKO THE ULTIMATE NINJA OF KOTLIN LIBRARIES? AGENDA What are Kotlin and Anko? Anko-related idioms and language concepts Anko DSL The hidden parts of Anko Anko VS The Rest Final thoughts

More information

UI-Testing, Reactive Programming and some Kotlin.

UI-Testing, Reactive Programming and some Kotlin. UI-Testing, Reactive Programming and some Kotlin anders.froberg@liu.se Load up your guns, and bring your friends This is the end, My only Friend, the end Äntligen stod prästen i predikstolen I ll be back

More information

Java Fundamentals (II)

Java Fundamentals (II) Chair of Software Engineering Languages in Depth Series: Java Programming Prof. Dr. Bertrand Meyer Java Fundamentals (II) Marco Piccioni static imports Introduced in 5.0 Imported static members of a class

More information

n n Official Scala website n Scala API n

n   n Official Scala website n Scala API n n Quiz 8 Announcements n Rainbow grades: HW1-8, Quiz1-6, Exam1-2 n Still grading: HW9, Quiz 7 Scala n HW10 due today n HW11 out today, due Friday Fall 18 CSCI 4430, A Milanova 1 Today s Lecture Outline

More information

The class Object. Lecture CS1122 Summer 2008

The class Object.  Lecture CS1122 Summer 2008 The class Object http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html Lecture 10 -- CS1122 Summer 2008 Review Object is at the top of every hierarchy. Every class in Java has an IS-A relationship

More information

Java Classes, Inheritance, and Interfaces

Java Classes, Inheritance, and Interfaces Java Classes, Inheritance, and Interfaces Introduction Classes are a foundational element in Java. Everything in Java is contained in a class. Classes are used to create Objects which contain the functionality

More information

Mixed projects: Java + Kotlin. Svetlana Isakova

Mixed projects: Java + Kotlin. Svetlana Isakova Mixed projects: Java + Kotlin Svetlana Isakova Compilation of a mixed project *.kt kotlinc *.class *.jar *.java javac *.class Nullability Nullability Type =? Java Kotlin Nullability annotations @Nullable

More information

2 years without Java or reload Android development with Kotlin.

2 years without Java or reload Android development with Kotlin. 2 years without Java or reload Android development with Kotlin KirillRozov@EPAM Who am I? Team Lead in EPAM More than 6 years in Android development Kotlin Evangelist Co-organizer GDG Minsk, Android Academy

More information

About 1. Chapter 1: Getting started with dagger-2 2. Remarks 2. Versions 2. Examples 2. Description and Setup 2. Basic Example 3.

About 1. Chapter 1: Getting started with dagger-2 2. Remarks 2. Versions 2. Examples 2. Description and Setup 2. Basic Example 3. dagger-2 #dagger-2 Table of Contents About 1 Chapter 1: Getting started with dagger-2 2 Remarks 2 Versions 2 Examples 2 Description and Setup 2 Basic Example 3 Android example 4 Learn Dagger2 with simple

More information

Multi-catch. Future Features. Sometimes we need to handle more than one exception in a single catch block:

Multi-catch. Future Features. Sometimes we need to handle more than one exception in a single catch block: 1 Multi-catch Sometimes we need to handle more than one exception in a single catch block: try { // some code } catch (e: ExceptionA ExceptionB) { log(e); throw e; } Note that this is not proposing general

More information

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline

Bibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline Bibliography Analyse et Conception Formelle Lesson 5 Crash Course on Scala Simply Scala. Onlinetutorial: http://www.simply.com/fr http://www.simply.com/ Programming in Scala, M. Odersky, L. Spoon, B. Venners.

More information

Object-oriented programming

Object-oriented programming Object-oriented programming HelloWorld The following code print Hello World on the console object HelloWorld { def main(args: Array[String]): Unit = { println("hello World") 2 1 object The keyword object

More information

More about inheritance

More about inheritance Main concepts to be covered More about inheritance Exploring polymorphism method polymorphism static and dynamic type overriding dynamic method lookup protected access 4.1 The inheritance hierarchy Conflicting

More information

Canonical Form. No argument constructor Object Equality String representation Cloning Serialization Hashing. Software Engineering

Canonical Form. No argument constructor Object Equality String representation Cloning Serialization Hashing. Software Engineering CSC40232: SOFTWARE ENGINEERING Professor: Jane Cleland Huang Canonical Form sarec.nd.edu/courses/se2017 Department of Computer Science and Engineering Canonical Form Canonical form is a practice that conforms

More information

Kotlin In Spreadshirt JavaLand,

Kotlin In Spreadshirt JavaLand, Kotlin In Practice @philipp_hauer Spreadshirt JavaLand, 13.03.18 Spreadshirt 2 Hands Up! Kotlin Features and Usage in Practice Data Classes Immutability made easy data class DesignData( val filename: String,

More information

Modern Web Development with Kotlin

Modern Web Development with Kotlin Modern Web Development with Kotlin A concise and practical step-by-step guide Denis Kalinin This book is for sale at http://leanpub.com/modern-web-development-with-kotlin This version was published on

More information

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia

CPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple

More information

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University

Day 4. COMP1006/1406 Summer M. Jason Hinek Carleton University Day 4 COMP1006/1406 Summer 2016 M. Jason Hinek Carleton University today s agenda assignments questions about assignment 2 a quick look back constructors signatures and overloading encapsulation / information

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Week 13 - Part 1 Thomas Wies New York University Review Last lecture Object Oriented Programming Outline Today: Scala Sources: Programming in Scala, Second

More information

...something useful to do with the JVM.

...something useful to do with the JVM. Scala Finally... ...something useful to do with the JVM. Image source: http://www.tripadvisor.com/locationphotos-g187789-lazio.html Young Developed in 2003 by Martin Odersky at EPFL Martin also brought

More information

Kotlin In Spreadshirt. JUG Saxony Day, Spreadshirt

Kotlin In Spreadshirt. JUG Saxony Day, Spreadshirt Kotlin In Practice @philipp_hauer JUG Saxony Day, 29.09.17 2 Hands Up! Kotlin Features and Usage in Practice References Immutable and mutable References val id = 1 id = 2 var id2 = 1 id2 = 2 5 Data Classes

More information

Announcements/Follow-ups

Announcements/Follow-ups Announcements/Follow-ups Midterm #2 Friday Everything up to and including today Review section tomorrow Study set # 6 online answers posted later today P5 due next Tuesday A good way to study Style omit

More information

Domain-Driven Design Activity

Domain-Driven Design Activity Domain-Driven Design Activity SWEN-261 Introduction to Software Engineering Department of Software Engineering Rochester Institute of Technology Entities and Value Objects are special types of objects

More information

INTRODUCTION. SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova

INTRODUCTION. SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova SHORT INTRODUCTION TO SCALA INGEGNERIA DEL SOFTWARE Università degli Studi di Padova Dipartimento di Matematica Corso di Laurea in Informatica, A.A. 2014 2015 rcardin@math.unipd.it INTRODUCTION Object/functional

More information

Future of Java. Post-JDK 9 Candidate Features. Jan Lahoda Java compiler developer Java Product Group, Oracle September, 2017

Future of Java. Post-JDK 9 Candidate Features. Jan Lahoda Java compiler developer Java Product Group, Oracle September, 2017 Future of Java Post-JDK 9 Candidate Features Jan Lahoda Java compiler developer Java Product Group, Oracle September, 2017 Safe Harbor Statement The following is intended to outline our general product

More information

Java Object Oriented Design. CSC207 Fall 2014

Java Object Oriented Design. CSC207 Fall 2014 Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code

More information

Abstract Classes and Interfaces

Abstract Classes and Interfaces Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass

More information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Announcements. CSCI 334: Principles of Programming Languages. Lecture 16: Intro to Scala. Announcements. Squeak demo. Instructor: Dan Barowy

Announcements. CSCI 334: Principles of Programming Languages. Lecture 16: Intro to Scala. Announcements. Squeak demo. Instructor: Dan Barowy Announcements CSCI 334: Principles of Programming Languages Lecture 16: Intro to Scala HW7 sent out as promised. See course webpage. Instructor: Dan Barowy Announcements No class on Tuesday, April 17.

More information

Java Magistère BFA

Java Magistère BFA Java 101 - Magistère BFA Lesson 3: Object Oriented Programming in Java Stéphane Airiau Université Paris-Dauphine Lesson 3: Object Oriented Programming in Java (Stéphane Airiau) Java 1 Goal : Thou Shalt

More information

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring Java Outline Java Models for variables Types and type checking, type safety Interpretation vs. compilation Reasoning about code CSCI 2600 Spring 2017 2 Java Java is a successor to a number of languages,

More information

Polymorphism. return a.doublevalue() + b.doublevalue();

Polymorphism. return a.doublevalue() + b.doublevalue(); Outline Class hierarchy and inheritance Method overriding or overloading, polymorphism Abstract classes Casting and instanceof/getclass Class Object Exception class hierarchy Some Reminders Interfaces

More information

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition?

IBS Software Services Technical Interview Questions. Q1. What is the difference between declaration and definition? IBS Software Services Technical Interview Questions Q1. What is the difference between declaration and definition? The declaration tells the compiler that at some later point we plan to present the definition

More information

Building Microservices with Kotlin. Haim Yadid

Building Microservices with Kotlin. Haim Yadid Building Microservices with Kotlin Haim Yadid Disclaimer The purpose of this talk is to share our experience and with Kotlin not to teach the language syntax. I will delve into some details for for the

More information

Assignment 2 (Solution)

Assignment 2 (Solution) Assignment 2 (Solution) Exercise. Q: Why are method equals and method hashcode probably pure? Under which circumstances are they not pure? A: They are probably pure because we don t know the implementation

More information

Inheritance. Transitivity

Inheritance. Transitivity Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated

More information

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017

CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 CS-140 Fall 2017 Test 2 Version A Nov. 29, 2017 Name: 1. (10 points) For the following, Check T if the statement is true, the F if the statement is false. (a) T F : An interface defines the list of fields

More information

Refactoring to Functional. Hadi Hariri

Refactoring to Functional. Hadi Hariri Refactoring to Functional Hadi Hariri Functional Programming In computer science, functional programming is a programming paradigm, a style of building the structure and elements of computer programs,

More information

CLASS DESIGN. Objectives MODULE 4

CLASS DESIGN. Objectives MODULE 4 MODULE 4 CLASS DESIGN Objectives > After completing this lesson, you should be able to do the following: Use access levels: private, protected, default, and public. Override methods Overload constructors

More information

COMP 250. Lecture 32. polymorphism. Nov. 25, 2016

COMP 250. Lecture 32. polymorphism. Nov. 25, 2016 COMP 250 Lecture 32 polymorphism Nov. 25, 2016 1 Recall example from lecture 30 class String serialnumber Person owner void bark() {print woof } : my = new (); my.bark();?????? extends extends class void

More information

Scala. Fernando Medeiros Tomás Paim

Scala. Fernando Medeiros Tomás Paim Scala Fernando Medeiros fernfreire@gmail.com Tomás Paim tomasbmp@gmail.com Topics A Scalable Language Classes and Objects Basic Types Functions and Closures Composition and Inheritance Scala s Hierarchy

More information

Assumptions. History

Assumptions. History Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand

More information

Java Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Java Classes. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar Java Classes Introduction to the Java Programming Language Produced by Eamonn de Leastar edeleastar@wit.ie Department of Computing, Maths & Physics Waterford Institute of Technology http://www.wit.ie http://elearning.wit.ie

More information

Classes Classes 2 / 35

Classes Classes 2 / 35 Classes 1 / 35 Classes Classes 2 / 35 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays

More information

Principles of Object Oriented Programming. Lecture 4

Principles of Object Oriented Programming. Lecture 4 Principles of Object Oriented Programming Lecture 4 Object-Oriented Programming There are several concepts underlying OOP: Abstract Types (Classes) Encapsulation (or Information Hiding) Polymorphism Inheritance

More information

Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer

Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Java and C# in Depth Carlo A. Furia, Marco Piccioni, Bertrand Meyer Exercise Session Week 2 Agenda Ø Quizzes Ø More quizzes Ø And even more quizzes 2 Quiz 1. What will be printed? Ø Integers public class

More information

C12a: The Object Superclass and Selected Methods

C12a: The Object Superclass and Selected Methods CISC 3115 TY3 C12a: The Object Superclass and Selected Methods Hui Chen Department of Computer & Information Science CUNY Brooklyn College 10/4/2018 CUNY Brooklyn College 1 Outline The Object class and

More information

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University

Day 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays

More information

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended

Class definition. complete definition. public public class abstract no instance can be created final class cannot be extended JAVA Classes Class definition complete definition [public] [abstract] [final] class Name [extends Parent] [impelements ListOfInterfaces] {... // class body public public class abstract no instance can

More information

Java Persistence API (JPA) Entities

Java Persistence API (JPA) Entities Java Persistence API (JPA) Entities JPA Entities JPA Entity is simple (POJO) Java class satisfying requirements of JavaBeans specification Setters and getters must conform to strict form Every entity must

More information

Using Type Annotations to Improve Your Code

Using Type Annotations to Improve Your Code Using Type Annotations to Improve Your Code Birds-of-a-Feather Session Werner Dietl, University of Waterloo Michael Ernst, University of Washington Open for questions Survey: Did you attend the tutorial?

More information

Programming Languages and Techniques (CIS120)

Programming Languages and Techniques (CIS120) Programming Languages and Techniques (CIS120) Lecture 28 March 30, 2016 Collections and Equality Chapter 26 Announcements Dr. Steve Zdancewic is guest lecturing today He teaches CIS 120 in the Fall Midterm

More information

Inheritance (Part 5) Odds and ends

Inheritance (Part 5) Odds and ends Inheritance (Part 5) Odds and ends 1 Static Methods and Inheritance there is a significant difference between calling a static method and calling a non-static method when dealing with inheritance there

More information

JAVA MOCK TEST JAVA MOCK TEST II

JAVA MOCK TEST JAVA MOCK TEST II http://www.tutorialspoint.com JAVA MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Java Framework. You can download these sample mock tests at your

More information

Informatik II (D-ITET) Tutorial 6

Informatik II (D-ITET) Tutorial 6 Informatik II (D-ITET) Tutorial 6 TA: Marian George, E-mail: marian.george@inf.ethz.ch Distributed Systems Group, ETH Zürich Exercise Sheet 5: Solutions and Remarks Variables & Methods beginwithlowercase,

More information

JVM ByteCode Interpreter

JVM ByteCode Interpreter JVM ByteCode Interpreter written in Haskell (In under 1000 Lines of Code) By Louis Jenkins Presentation Schedule ( 15 Minutes) Discuss and Run the Virtual Machine first

More information

Super-Classes and sub-classes

Super-Classes and sub-classes Super-Classes and sub-classes Subclasses. Overriding Methods Subclass Constructors Inheritance Hierarchies Polymorphism Casting 1 Subclasses: Often you want to write a class that is a special case of an

More information

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5,

Informatik II. Tutorial 6. Mihai Bâce Mihai Bâce. April 5, Informatik II Tutorial 6 Mihai Bâce mihai.bace@inf.ethz.ch 05.04.2017 Mihai Bâce April 5, 2017 1 Overview Debriefing Exercise 5 Briefing Exercise 6 Mihai Bâce April 5, 2017 2 U05 Some Hints Variables &

More information

Generics method and class definitions which involve type parameters.

Generics method and class definitions which involve type parameters. Contents Topic 07 - Generic Programming I. Introduction Example 1 User defined Generic Method: printtwice(t x) Example 2 User defined Generic Class: Pair Example 3 using java.util.arraylist II. Type

More information

Introduction to Functional Programming and Haskell. Aden Seaman

Introduction to Functional Programming and Haskell. Aden Seaman Introduction to Functional Programming and Haskell Aden Seaman Functional Programming Functional Programming First Class Functions Expressions (No Assignment) (Ideally) No Side Effects Different Approach

More information

15CS45 : OBJECT ORIENTED CONCEPTS

15CS45 : OBJECT ORIENTED CONCEPTS 15CS45 : OBJECT ORIENTED CONCEPTS QUESTION BANK: What do you know about Java? What are the supported platforms by Java Programming Language? List any five features of Java? Why is Java Architectural Neutral?

More information

UMBC CMSC 331 Final Exam

UMBC CMSC 331 Final Exam UMBC CMSC 331 Final Exam Name: UMBC Username: You have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for answers that are needlessly wordy

More information

Scala Java Sparkle Monday, April 16, 2012

Scala Java Sparkle Monday, April 16, 2012 Scala Java Sparkle Scala Scala Java Scala "Which Programming Language would you use *now* on top of JVM, except Java?". The answer was surprisingly fast and very clear: - Scala. http://www.adam-bien.com/roller/abien/entry/java_net_javaone_which_programming

More information

Object Model. Object Oriented Programming Spring 2015

Object Model. Object Oriented Programming Spring 2015 Object Model Object Oriented Programming 236703 Spring 2015 Class Representation In Memory A class is an abstract entity, so why should it be represented in the runtime environment? Answer #1: Dynamic

More information

Functional Logic Programming Language Curry

Functional Logic Programming Language Curry Functional Logic Programming Language Curry Xiang Yin Department of Computer Science McMaster University November 9, 2010 Outline Functional Logic Programming Language 1 Functional Logic Programming Language

More information

Scala : an LLVM-targeted Scala compiler

Scala : an LLVM-targeted Scala compiler Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................

More information

COMP 401 Spring 2013 Midterm 1

COMP 401 Spring 2013 Midterm 1 COMP 401 Spring 2013 Midterm 1 I have not received nor given any unauthorized assistance in completing this exam. Signature: Name: PID: Please be sure to put your PID at the top of each page. This page

More information

CS/ENGRD 2110 FALL Lecture 6: Consequence of type, casting; function equals

CS/ENGRD 2110 FALL Lecture 6: Consequence of type, casting; function equals CS/ENGRD 2110 FALL 2018 Lecture 6: Consequence of type, casting; function equals http://courses.cs.cornell.edu/cs2110 Overview references in 2 Quick look at arrays: array Casting among classes cast, object-casting

More information

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass? 1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type

More information

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March

QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March QUEEN MARY, UNIVERSITY OF LONDON DCS128 ALGORITHMS AND DATA STRUCTURES Class Test Monday 27 th March 2006 11.05-12.35 Please fill in your Examination Number here: Student Number here: MODEL ANSWERS All

More information

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix PGJC4_JSE8_OCA.book Page ix Monday, June 20, 2016 2:31 PM Contents Figures Tables Examples Foreword Preface xix xxi xxiii xxvii xxix 1 Basics of Java Programming 1 1.1 Introduction 2 1.2 Classes 2 Declaring

More information

Informatik II Tutorial 6. Subho Shankar Basu

Informatik II Tutorial 6. Subho Shankar Basu Informatik II Tutorial 6 Subho Shankar Basu subho.basu@inf.ethz.ch 06.04.2017 Overview Debriefing Exercise 5 Briefing Exercise 6 2 U05 Some Hints Variables & Methods beginwithlowercase, areverydescriptiveand

More information

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming

Introduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics

More information

Classes Classes 2 / 36

Classes Classes 2 / 36 Classes 1 / 36 Classes Classes 2 / 36 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays

More information

Lecture 10. Overriding & Casting About

Lecture 10. Overriding & Casting About Lecture 10 Overriding & Casting About Announcements for This Lecture Readings Sections 4.2, 4.3 Prelim, March 8 th 7:30-9:30 Material up to next Tuesday Sample prelims from past years on course web page

More information

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

(800) Toll Free (804) Fax   Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days Course Description This course introduces the Java programming language and how to develop Java applications using Eclipse 3.0. Students learn the syntax of the Java programming language, object-oriented

More information

Garbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; }

Garbage collec,on Parameter passing in Java. Sept 21, 2016 Sprenkle - CSCI Assignment 2 Review. public Assign2(int par) { onevar = par; } Objec,ves Inheritance Ø Overriding methods Garbage collec,on Parameter passing in Java Sept 21, 2016 Sprenkle - CSCI209 1 Assignment 2 Review private int onevar; public Assign2(int par) { onevar = par;

More information