If you are an Android developer, an experienced Java developer looking to take your mobile applications to the next level, so this session is for you. Starting from Android N which is the next version of Google's blockbuster operating system for mobile devices.
Developers can experiment with the new features and capabilities of the operating system powered by Java SE 8 and Kotlin, I will also touch the new Desugar compiler designed for Java SE 8 support and programming with Java SE 8 syntax; lambda expression, method reference, default methods, Streams... etc.
Github project @ https://github.com/mohamed-taman/Android_with_JavaSE8_Kotlin
10. WHAT'S NEW IN JDK 8
• Lambda Expressions (Covered already)
• Method references
• Default and static interface methods
• Streams & Collections
• For more:
Mohamed Taman @_tamanm
Supported by Android development
https://developer.android.com/studio/preview/features/java8-support.html#supported_features
11. QUICK LIVE DEMO
Mohamed Taman @_tamanm
http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html
13. USE JAVA 8 LANGUAGE FEATURES
• Android Studio 2.4 Preview 4 and later supports all Java SE 7 language features.
• And a subset of Java SE 8 language features.
Mohamed Taman @_tamanm
Note: When developing apps for Android, using Java 8
language features, is optional.
14. DESUGAR TOOLCHAIN
Is the default toolchain for
new Android Studio 2.4+
Mohamed Taman @_tamanm
.java .class
.class
(desugared)
.dex
javac dexdesugar
Third party
library
Java 8 language feature support using desugar bytecode transformations.
16. UPDATE GRADLE PLUGIN
• Update the Android plugin to 2.4.0 (or higher), you can use latest Gradle v3.5.
• Add the following to your module’s build.gradle file
Mohamed Taman @_tamanm
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
17. API VERSION, VM IMAGE, & TOOLS
• Update API to API level 24 or higher.
• minSdkVersion (24) is Noga Android N or higher should be installed.
• Intel x86 atom System image of Noga SDK.
• Latest build and platform tools v24.0.0+.
• Google Repository v24 or later.
• Intel x86 emulator accelerator (HAXM installer) latest version.
Mohamed Taman @_tamanm
18. WHY KOTLIN?
Mohamed Taman @_tamanm
Statically typed programming language
for modern multiplatform applications
19. KOTLIN IS…
• Concise; Drastically reduce the amount of boilerplate code.
• Safe; Avoid entire classes of errors such as null pointer exceptions.
• Interoperable; Leverage existing libraries for the JVM, Android, and the browser.
• Tool – friendly; Choose any Java IDE or build from the command line.
• For more:
Mohamed Taman @_tamanm
Now official on Android
https://kotlinlang.org
Lambda Expressions
------------------------------
A new language feature, has been introduced in this release. They enable you to treat functionality as a method argument, or code as data.
Lambda expressions let you express instances of single-method interfaces (referred to as functional interfaces) more compactly.
Method references
---------------------------
Provide easy-to-read lambda expressions for methods that already have a name.
Default and static methods:
--------------------------------------
Enable new functionality to be added to the interfaces of libraries and ensure binary compatibility with code written for older versions of those interfaces.
Collections and Streams:
--------------------------------------
Classes in the new java.util.stream package provide a Stream API to support functional-style operations on streams of elements.
The Stream API is integrated into the Collections API, which enables bulk operations on collections, such as sequential or parallel map-reduce transformations.
Note: When developing apps for Android, using Java 8 language features is optional.
You can keep your project's source and target compatibility values set to Java 7, but you still need to compile using JDK 8.
Android Studio now provides built-in support for using certain Java 8 language features and third-party libraries that use them.
The default toolchain called desugar implements the new language features by performing bytecode transformations on the output of the javac compiler.