How does Android's Java version relate to a Java SE version?
Asked Answered
M

2

73

I am constantly wondering how the Java version used for Android development relates to a Java SE version. For example, I was reading today about "Type Inference and Generic Methods" which is a feature added in Java SE 7. I wonder to myself, "Can I use this in Android code?"

Of course I could type the code into an Android project and see if it compiles, but I'd be happier to have some kind of mapping in my head.

I've tried Googling for this info, checking the Android docs, etc, but can't find an answer.

Edit: I'm more interested in language features, e.g. how does the Android Java syntax version relate to Java SE syntax.

Mauromaurois answered 23/9, 2011 at 22:14 Comment(3)
Similar and relevant (but dated): https://mcmap.net/q/36768/-jre-on-android/324625Receiptor
Are you an Oracle lawyer? If so I have right to remain silent :)Korry
Here a good answer #4867834Ekaterinodar
S
42

Android's version doesn't directly relate to Java SE, although it uses a subset of Apache Harmony's SE 6 libraries and tools. It will be up to the Android team to decide if & when to support/require the SE 7 version of Harmony.

Edit It looks like as of KitKat Android supports Java SE 7 language features. See the comments below.

Seat answered 23/9, 2011 at 22:30 Comment(4)
So would it be safe to say that Android syntax is roughly equivalent to Java SE 6? (I understand the libraries are quite different)Mauromaurois
Yes, it would be safe to say that. If they switch to Java SE 7 compatibility (i.e. binary literals, strings in switch statements, etc.) then I'm sure that will be well-publicized.Seat
FYI Apache decided to retire the Harmony project back in Nov. So looks like we might not ever see SE7 or above?Crutch
@Turbo It works with KitKat.(buildToolsVersion 19) Take a look here: linkIntellect
D
1

There is no direct mapping:

  • Some parts of the API (such as JAXB, which has been around since at least Java 6) have never been available on Android.
  • When features of a new Java version are introduced, this can happen gradually over multiple versions.
  • Some newer Java features are made available for older, already-released versions as backports.

In the past it has taken Google some 2–3 years to start adopting a new Java version. Java 7 features started appearing around API 19 (KitKat). Java 8 features started at API 26 (Nougat), but a mechanism called desugaring is available to make certain Java 8 features available on earlier Android versions, regardless of their API level.

So, generally speaking, if you want to know whether a particular Java API feature is available on Android, look it up on the Android developer reference and check the minimum API version.

Dustin answered 29/1, 2023 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.