Release date: from 22 september 2016 to january 2016!!!
JSR 294: Modularization of the JDK under Project Jigsaw
JSR 354: Money and Currency API
JEP 222: jshell: The Java Shell (a Java REPL)
Android will support it in few month!
1 year release cycle!
Properties!
Serializable deprecated and removed
Java 10 approx in the first decade of 2017
Java 9 - ~ 22 sep 2016
Java 8 in Android - ???
Java 10 - ???
Java 1.0 - 1996
Java 1.1 - 1997
Java 2 - 1998
Java 3 - 2000
Java 4 - 2002
Java 5 - 2004
Java 5 - 2004
Java 6 - 2006
Java 7 - 2011
Java 8 - 2014
Java 9 - 2016
Java Virtual Machine Support for Non-Java Languages: Java SE 7 introduces a new JVM instruction that simplifies the implementation of dynamically typed programming languages on the JVM.
Ceylon, Fantom, Scala, Groovy, Kotlin, xTend, Clojure, Gosu?
Gosu, Fantom, Ceylon, xTend
Clojure
Ceylon, Fantom, Scala, Groovy, Kotlin, xTend, Clojure, Gosu?
package space
fun main(args: Array<String>) {
println("Hello, world!")
}
var x = 5
x += 1
val a: Int = 1
val b = 1
val c: Int
c = 1
val text = """
for (c in "foo")
print(c)
"""
fun sum(a: Int, b: Int): Int {
return a + b
}
fun sum(var a: Int, b: Int): Int {
a+=1
return a + b
}
fun sum(a: Int, b: Int = 42): Int {
return a + b
}
sum(1) // 43
fun main(args: Array<String>) {
if (args.size() == 0) return
print("First argument: ${args[0]}")
}
fun getStringLength(obj: Any): Int? {
if (obj !is String)
return null
// `obj` is automatically cast to `String` in this branch
return obj.length
}
fun cases(obj: Any) {
when (obj) {
1 -> print("One")
"Hello" -> print("Greeting")
is Long -> print("Long")
!is String -> print("Not a string")
else -> print("Unknown")
}
}
data class Customer(val name: String, val email: String)
val customer = Customer("Space", "space@space.com")
println(customer)
// Customer(name=Space, email=space@space.com)
fun String.replaceEvilWithAwesome() { ... }
println("Kotlin is evil".replaceEvilWithAwesome())
// Kotlin is awesome
val lazyVal: String by lazy {
println("computed!")
"Hello"
}
fun main(args: Array<String>) {
println(lazyVal)
println(lazyVal)
}
// computed!
// Hello
// Hello
String dumb = null;
dumb.length();
val a : Int = 1;
var b : Int? = null;
var a: String = "abc"
a = null // compilation error
var b: String? = "abc"
b = null // ok
var b: String? = "abc"
val l = b.length() // error: variable 'b' can be null
val l = if (b != null) b.length() else -1
val l = b?.length() ?: -1
b?.length()
bob?.department?.head?.name
val l = b!!.length()
class HelloApplication(config: ApplicationConfig) : Application(config) {
init {
routing {
get("/") {
response.status(HttpStatusCode.OK)
response.contentType(ContentType.Text.Html)
response.write {
appendHTML().html {
head {
title { +"Hello World." }
}
body {
h1 {
+"Hello, World!"
}
}
}
}
ApplicationRequestStatus.Handled
}
get("/bye") {
response.sendText("Goodbye World!")
}
}
}
}
html {
body {
div {
a("http://kotlinlang.org") {
target = ATarget.blank
+"Main site"
}
}
}
}
class TaxCalculatorSpecs: Spek() { init {
given("Tax rate calculator with default locale settings") {
val taxRateCalculator = TaxRateCalculator()
on("calculating the rate for an income of 200 and an average change of 10 per semester") {
val value = taxRateCalculator.calculateRate(200, 10)
it("should result in a value of 300") {
assertEquals(300, value)
}
}
}
}}
object Users : Table() {
val id = varchar("id", ColumnType.PRIMARY_KEY, length = 10)
val name = varchar("name", length = 50)
val cityId = integer("city_id", ColumnType.NULLABLE, references = Cities.id)
val all = id + name + cityId
val values = id + name + cityId // The columns required for insert statement
}
object Cities : Table() {
val id = integer("id", ColumnType.PRIMARY_KEY, autoIncrement = true)
val name = varchar("name", 50)
val all = id + name
val values = name
}
var db = Database("jdbc:h2:mem:test", driver = "org.h2.Driver")
db.withSession {
create (Cities, Users)
val minskId = insert (Cities.values("Minsk")) get Cities.id
insert (Users.values("ruslan", "Ruslan", minskId))
}
CREATE TABLE Cities (
id INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(50) NOT NULL)
CREATE TABLE Users (
id VARCHAR(10) PRIMARY KEY NOT NULL,
name VARCHAR(50) NOT NULL,
city_id INT NULL)
INSERT INTO Cities (name) VALUES ('Minsk')
INSERT INTO Users (id, name, city_id)
VALUES ('andrey', 'Andrey', 1)